add noinlines option
This commit is contained in:
@@ -111,6 +111,7 @@ If you want to change them - check available options in the help message (`!pm h
|
|||||||
* **!pm nohtml** - Get or set `nohtml` of the room (`true` - ignore HTML in email; `false` - parse HTML in emails)
|
* **!pm nohtml** - Get or set `nohtml` of the room (`true` - ignore HTML in email; `false` - parse HTML in emails)
|
||||||
* **!pm nothreads** - Get or set `nothreads` of the room (`true` - ignore email threads; `false` - convert email threads into matrix threads)
|
* **!pm nothreads** - Get or set `nothreads` of the room (`true` - ignore email threads; `false` - convert email threads into matrix threads)
|
||||||
* **!pm nofiles** - Get or set `nofiles` of the room (`true` - ignore email attachments; `false` - upload email attachments)
|
* **!pm nofiles** - Get or set `nofiles` of the room (`true` - ignore email attachments; `false` - upload email attachments)
|
||||||
|
* **!pm noinlines** - Get or set `noinlines` of the room (`true` - ignore inline attachments; `false` - upload inline attachments)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -167,6 +167,15 @@ func (b *Bot) initCommands() commandList {
|
|||||||
sanitizer: utils.SanitizeBoolString,
|
sanitizer: utils.SanitizeBoolString,
|
||||||
allowed: b.allowOwner,
|
allowed: b.allowOwner,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
key: config.RoomNoInlines,
|
||||||
|
description: fmt.Sprintf(
|
||||||
|
"Get or set `%s` of the room (`true` - ignore inline attachments; `false` - upload inline attachments)",
|
||||||
|
config.RoomNoFiles,
|
||||||
|
),
|
||||||
|
sanitizer: utils.SanitizeBoolString,
|
||||||
|
allowed: b.allowOwner,
|
||||||
|
},
|
||||||
{allowed: b.allowOwner, description: "mailbox antispam"}, // delimiter
|
{allowed: b.allowOwner, description: "mailbox antispam"}, // delimiter
|
||||||
{
|
{
|
||||||
key: config.RoomSpamcheckMX,
|
key: config.RoomSpamcheckMX,
|
||||||
@@ -491,7 +500,7 @@ func (b *Bot) runSend(ctx context.Context) {
|
|||||||
ID := email.MessageID(evt.ID, domain)
|
ID := email.MessageID(evt.ID, domain)
|
||||||
for _, to := range tos {
|
for _, to := range tos {
|
||||||
recipients := []string{to}
|
recipients := []string{to}
|
||||||
eml := email.New(ID, "", " "+ID, subject, from, to, to, "", body, htmlBody, nil)
|
eml := email.New(ID, "", " "+ID, subject, from, to, to, "", body, htmlBody, nil, nil)
|
||||||
data := eml.Compose(b.cfg.GetBot().DKIMPrivateKey())
|
data := eml.Compose(b.cfg.GetBot().DKIMPrivateKey())
|
||||||
if data == "" {
|
if data == "" {
|
||||||
b.SendError(ctx, evt.RoomID, "email body is empty")
|
b.SendError(ctx, evt.RoomID, "email body is empty")
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ const (
|
|||||||
RoomNoHTML = "nohtml"
|
RoomNoHTML = "nohtml"
|
||||||
RoomNoThreads = "nothreads"
|
RoomNoThreads = "nothreads"
|
||||||
RoomNoFiles = "nofiles"
|
RoomNoFiles = "nofiles"
|
||||||
|
RoomNoInlines = "noinlines"
|
||||||
RoomPassword = "password"
|
RoomPassword = "password"
|
||||||
RoomSpamcheckDKIM = "spamcheck:dkim"
|
RoomSpamcheckDKIM = "spamcheck:dkim"
|
||||||
RoomSpamcheckSMTP = "spamcheck:smtp"
|
RoomSpamcheckSMTP = "spamcheck:smtp"
|
||||||
@@ -96,6 +97,10 @@ func (s Room) NoFiles() bool {
|
|||||||
return utils.Bool(s.Get(RoomNoFiles))
|
return utils.Bool(s.Get(RoomNoFiles))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s Room) NoInlines() bool {
|
||||||
|
return utils.Bool(s.Get(RoomNoInlines))
|
||||||
|
}
|
||||||
|
|
||||||
func (s Room) SpamcheckDKIM() bool {
|
func (s Room) SpamcheckDKIM() bool {
|
||||||
return utils.Bool(s.Get(RoomSpamcheckDKIM))
|
return utils.Bool(s.Get(RoomSpamcheckDKIM))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -129,6 +129,10 @@ func (b *Bot) IncomingEmail(ctx context.Context, email *email.Email) error {
|
|||||||
b.setThreadID(roomID, email.MessageID, threadID)
|
b.setThreadID(roomID, email.MessageID, threadID)
|
||||||
b.setLastEventID(roomID, threadID, eventID)
|
b.setLastEventID(roomID, threadID, eventID)
|
||||||
|
|
||||||
|
if !cfg.NoInlines() {
|
||||||
|
b.sendFiles(ctx, roomID, email.InlineFiles, cfg.NoThreads(), threadID)
|
||||||
|
}
|
||||||
|
|
||||||
if !cfg.NoFiles() {
|
if !cfg.NoFiles() {
|
||||||
b.sendFiles(ctx, roomID, email.Files, cfg.NoThreads(), threadID)
|
b.sendFiles(ctx, roomID, email.Files, cfg.NoThreads(), threadID)
|
||||||
}
|
}
|
||||||
@@ -179,7 +183,7 @@ func (b *Bot) SendEmailReply(ctx context.Context) {
|
|||||||
meta.MessageID = email.MessageID(evt.ID, meta.FromDomain)
|
meta.MessageID = email.MessageID(evt.ID, meta.FromDomain)
|
||||||
meta.References = meta.References + " " + meta.MessageID
|
meta.References = meta.References + " " + meta.MessageID
|
||||||
b.log.Info("sending email reply: %+v", meta)
|
b.log.Info("sending email reply: %+v", meta)
|
||||||
eml := email.New(meta.MessageID, meta.InReplyTo, meta.References, meta.Subject, meta.From, meta.To, meta.RcptTo, meta.CC, body, htmlBody, nil)
|
eml := email.New(meta.MessageID, meta.InReplyTo, meta.References, meta.Subject, meta.From, meta.To, meta.RcptTo, meta.CC, body, htmlBody, nil, nil)
|
||||||
data := eml.Compose(b.cfg.GetBot().DKIMPrivateKey())
|
data := eml.Compose(b.cfg.GetBot().DKIMPrivateKey())
|
||||||
if data == "" {
|
if data == "" {
|
||||||
b.SendError(ctx, evt.RoomID, "email body is empty")
|
b.SendError(ctx, evt.RoomID, "email body is empty")
|
||||||
|
|||||||
@@ -17,35 +17,37 @@ import (
|
|||||||
|
|
||||||
// Email object
|
// Email object
|
||||||
type Email struct {
|
type Email struct {
|
||||||
Date string
|
Date string
|
||||||
MessageID string
|
MessageID string
|
||||||
InReplyTo string
|
InReplyTo string
|
||||||
References string
|
References string
|
||||||
From string
|
From string
|
||||||
To string
|
To string
|
||||||
RcptTo string
|
RcptTo string
|
||||||
CC []string
|
CC []string
|
||||||
Subject string
|
Subject string
|
||||||
Text string
|
Text string
|
||||||
HTML string
|
HTML string
|
||||||
Files []*utils.File
|
Files []*utils.File
|
||||||
|
InlineFiles []*utils.File
|
||||||
}
|
}
|
||||||
|
|
||||||
// New constructs Email object
|
// New constructs Email object
|
||||||
func New(messageID, inReplyTo, references, subject, from, to, rcptto, cc, text, html string, files []*utils.File) *Email {
|
func New(messageID, inReplyTo, references, subject, from, to, rcptto, cc, text, html string, files, inline []*utils.File) *Email {
|
||||||
email := &Email{
|
email := &Email{
|
||||||
Date: dateNow(),
|
Date: dateNow(),
|
||||||
MessageID: messageID,
|
MessageID: messageID,
|
||||||
InReplyTo: inReplyTo,
|
InReplyTo: inReplyTo,
|
||||||
References: references,
|
References: references,
|
||||||
From: Address(from),
|
From: Address(from),
|
||||||
To: Address(to),
|
To: Address(to),
|
||||||
CC: AddressList(cc),
|
CC: AddressList(cc),
|
||||||
RcptTo: Address(rcptto),
|
RcptTo: Address(rcptto),
|
||||||
Subject: subject,
|
Subject: subject,
|
||||||
Text: text,
|
Text: text,
|
||||||
HTML: html,
|
HTML: html,
|
||||||
Files: files,
|
Files: files,
|
||||||
|
InlineFiles: inline,
|
||||||
}
|
}
|
||||||
|
|
||||||
if html != "" {
|
if html != "" {
|
||||||
@@ -72,19 +74,26 @@ func FromEnvelope(rcptto string, envelope *enmime.Envelope) *Email {
|
|||||||
files = append(files, file)
|
files = append(files, file)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inlines := make([]*utils.File, 0, len(envelope.Inlines))
|
||||||
|
for _, inline := range envelope.Inlines {
|
||||||
|
file := utils.NewFile(inline.FileName, inline.Content)
|
||||||
|
inlines = append(inlines, file)
|
||||||
|
}
|
||||||
|
|
||||||
email := &Email{
|
email := &Email{
|
||||||
Date: date,
|
Date: date,
|
||||||
MessageID: envelope.GetHeader("Message-Id"),
|
MessageID: envelope.GetHeader("Message-Id"),
|
||||||
InReplyTo: envelope.GetHeader("In-Reply-To"),
|
InReplyTo: envelope.GetHeader("In-Reply-To"),
|
||||||
References: envelope.GetHeader("References"),
|
References: envelope.GetHeader("References"),
|
||||||
From: Address(envelope.GetHeader("From")),
|
From: Address(envelope.GetHeader("From")),
|
||||||
To: Address(envelope.GetHeader("To")),
|
To: Address(envelope.GetHeader("To")),
|
||||||
RcptTo: Address(rcptto),
|
RcptTo: Address(rcptto),
|
||||||
CC: AddressList(envelope.GetHeader("Cc")),
|
CC: AddressList(envelope.GetHeader("Cc")),
|
||||||
Subject: envelope.GetHeader("Subject"),
|
Subject: envelope.GetHeader("Subject"),
|
||||||
Text: envelope.Text,
|
Text: envelope.Text,
|
||||||
HTML: html,
|
HTML: html,
|
||||||
Files: files,
|
Files: files,
|
||||||
|
InlineFiles: inlines,
|
||||||
}
|
}
|
||||||
|
|
||||||
return email
|
return email
|
||||||
|
|||||||
Reference in New Issue
Block a user