diff --git a/bot/bot.go b/bot/bot.go index d9de689..cd3423d 100644 --- a/bot/bot.go +++ b/bot/bot.go @@ -90,7 +90,7 @@ func (b *Bot) Start() error { } // Send email to matrix room -func (b *Bot) Send(ctx context.Context, from, to, subject, body string, files []*utils.File) error { +func (b *Bot) Send(ctx context.Context, from, to, subject, plaintext, html string, files []*utils.File) error { roomID, ok := b.GetMapping(ctx, utils.Mailbox(to)) if !ok { return errors.New("room not found") @@ -103,7 +103,11 @@ func (b *Bot) Send(ctx context.Context, from, to, subject, body string, files [] text.WriteString("# ") text.WriteString(subject) text.WriteString("\n\n") - text.WriteString(format.HTMLToMarkdown(body)) + if html != "" { + text.WriteString(format.HTMLToMarkdown(html)) + } else { + text.WriteString(plaintext) + } content := format.RenderMarkdown(text.String(), true, true) _, err := b.lp.Send(roomID, content) diff --git a/smtp/session.go b/smtp/session.go index 8802d55..a054469 100644 --- a/smtp/session.go +++ b/smtp/session.go @@ -66,17 +66,13 @@ func (s *session) Data(r io.Reader) error { if err != nil { return err } - text := eml.Text - if eml.HTML != "" { - text = eml.HTML - } attachments := s.parseAttachments(eml.Attachments) inlines := s.parseAttachments(eml.Inlines) files := make([]*utils.File, 0, len(attachments)+len(inlines)) files = append(files, attachments...) files = append(files, inlines...) - return s.client.Send(s.ctx, s.from, s.to, eml.GetHeader("Subject"), text, files) + return s.client.Send(s.ctx, s.from, s.to, eml.GetHeader("Subject"), eml.Text, eml.HTML, files) } func (s *session) Reset() {} diff --git a/smtp/smtp.go b/smtp/smtp.go index 98921a1..c7d44de 100644 --- a/smtp/smtp.go +++ b/smtp/smtp.go @@ -10,5 +10,5 @@ import ( // Client interface to send emails type Client interface { GetMapping(context.Context, string) (id.RoomID, bool) - Send(ctx context.Context, from, mailbox, subject, body string, files []*utils.File) error + Send(ctx context.Context, from, mailbox, subject, text, html string, files []*utils.File) error }