From 24686ef5019469a19a3b12f12bb44bb21cf3a68f Mon Sep 17 00:00:00 2001 From: Aine Date: Tue, 23 Aug 2022 17:56:38 +0300 Subject: [PATCH 1/2] lint fixes --- .gitlab-ci.yml | 2 -- bot/bot.go | 9 ++++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 871c6a0..2854ab1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,14 +4,12 @@ stages: lint: stage: test - only: ['main'] image: registry.gitlab.com/etke.cc/base script: - make lint unit: stage: test - only: ['main'] image: registry.gitlab.com/etke.cc/base script: - make test diff --git a/bot/bot.go b/bot/bot.go index 8b2daaa..d9de689 100644 --- a/bot/bot.go +++ b/bot/bot.go @@ -61,10 +61,17 @@ func (b *Bot) Error(ctx context.Context, roomID id.RoomID, message string, args // Notice sends a notice message to the matrix room func (b *Bot) Notice(ctx context.Context, roomID id.RoomID, message string, args ...interface{}) { - b.lp.Send(roomID, &event.MessageEventContent{ + _, err := b.lp.Send(roomID, &event.MessageEventContent{ MsgType: event.MsgNotice, Body: fmt.Sprintf(message, args...), }) + if err != nil { + if sentry.HasHubOnContext(ctx) { + sentry.GetHubFromContext(ctx).CaptureException(err) + } else { + sentry.CaptureException(err) + } + } } // Start performs matrix /sync From 0178c3cff353e0b08f68fc6496063fecead597ac Mon Sep 17 00:00:00 2001 From: Aine Date: Tue, 23 Aug 2022 18:11:38 +0300 Subject: [PATCH 2/2] do not convert plaintext as html --- bot/bot.go | 8 ++++++-- smtp/session.go | 6 +----- smtp/smtp.go | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) 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 }