Merge branch 'main' into hide-sender-address-support
This commit is contained in:
@@ -4,14 +4,12 @@ stages:
|
|||||||
|
|
||||||
lint:
|
lint:
|
||||||
stage: test
|
stage: test
|
||||||
only: ['main']
|
|
||||||
image: registry.gitlab.com/etke.cc/base
|
image: registry.gitlab.com/etke.cc/base
|
||||||
script:
|
script:
|
||||||
- make lint
|
- make lint
|
||||||
|
|
||||||
unit:
|
unit:
|
||||||
stage: test
|
stage: test
|
||||||
only: ['main']
|
|
||||||
image: registry.gitlab.com/etke.cc/base
|
image: registry.gitlab.com/etke.cc/base
|
||||||
script:
|
script:
|
||||||
- make test
|
- make test
|
||||||
|
|||||||
17
bot/bot.go
17
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
|
// Notice sends a notice message to the matrix room
|
||||||
func (b *Bot) Notice(ctx context.Context, roomID id.RoomID, message string, args ...interface{}) {
|
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,
|
MsgType: event.MsgNotice,
|
||||||
Body: fmt.Sprintf(message, args...),
|
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
|
// Start performs matrix /sync
|
||||||
@@ -83,7 +90,7 @@ func (b *Bot) Start() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Send email to matrix room
|
// 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))
|
roomID, ok := b.GetMapping(ctx, utils.Mailbox(to))
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("room not found")
|
return errors.New("room not found")
|
||||||
@@ -103,7 +110,11 @@ func (b *Bot) Send(ctx context.Context, from, to, subject, body string, files []
|
|||||||
text.WriteString("# ")
|
text.WriteString("# ")
|
||||||
text.WriteString(subject)
|
text.WriteString(subject)
|
||||||
text.WriteString("\n\n")
|
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)
|
content := format.RenderMarkdown(text.String(), true, true)
|
||||||
_, err = b.lp.Send(roomID, content)
|
_, err = b.lp.Send(roomID, content)
|
||||||
|
|||||||
@@ -66,17 +66,13 @@ func (s *session) Data(r io.Reader) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
text := eml.Text
|
|
||||||
if eml.HTML != "" {
|
|
||||||
text = eml.HTML
|
|
||||||
}
|
|
||||||
|
|
||||||
attachments := s.parseAttachments(eml.Attachments)
|
attachments := s.parseAttachments(eml.Attachments)
|
||||||
inlines := s.parseAttachments(eml.Inlines)
|
inlines := s.parseAttachments(eml.Inlines)
|
||||||
files := make([]*utils.File, 0, len(attachments)+len(inlines))
|
files := make([]*utils.File, 0, len(attachments)+len(inlines))
|
||||||
files = append(files, attachments...)
|
files = append(files, attachments...)
|
||||||
files = append(files, inlines...)
|
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() {}
|
func (s *session) Reset() {}
|
||||||
|
|||||||
@@ -10,5 +10,5 @@ import (
|
|||||||
// Client interface to send emails
|
// Client interface to send emails
|
||||||
type Client interface {
|
type Client interface {
|
||||||
GetMapping(context.Context, string) (id.RoomID, bool)
|
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
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user