do not add empty mime parts, fixes #51
This commit is contained in:
@@ -430,6 +430,10 @@ func (b *Bot) runSend(ctx context.Context) {
|
|||||||
for _, to := range tos {
|
for _, to := range tos {
|
||||||
email := utils.NewEmail(ID, "", " "+ID, subject, from, to, body, htmlBody, nil)
|
email := utils.NewEmail(ID, "", " "+ID, subject, from, to, body, htmlBody, nil)
|
||||||
data := email.Compose(b.getBotSettings().DKIMPrivateKey())
|
data := email.Compose(b.getBotSettings().DKIMPrivateKey())
|
||||||
|
if data == "" {
|
||||||
|
b.SendError(ctx, evt.RoomID, "email body is empty")
|
||||||
|
return
|
||||||
|
}
|
||||||
queued, err := b.Sendmail(evt.ID, from, to, data)
|
queued, err := b.Sendmail(evt.ID, from, to, data)
|
||||||
if queued {
|
if queued {
|
||||||
b.log.Error("cannot send email: %v", err)
|
b.log.Error("cannot send email: %v", err)
|
||||||
|
|||||||
@@ -180,6 +180,10 @@ func (b *Bot) SendEmailReply(ctx context.Context) {
|
|||||||
b.log.Debug("send email reply: %+v", meta)
|
b.log.Debug("send email reply: %+v", meta)
|
||||||
email := utils.NewEmail(meta.MessageID, meta.InReplyTo, meta.References, meta.Subject, meta.From, meta.To, body, htmlBody, nil)
|
email := utils.NewEmail(meta.MessageID, meta.InReplyTo, meta.References, meta.Subject, meta.From, meta.To, body, htmlBody, nil)
|
||||||
data := email.Compose(b.getBotSettings().DKIMPrivateKey())
|
data := email.Compose(b.getBotSettings().DKIMPrivateKey())
|
||||||
|
if data == "" {
|
||||||
|
b.SendError(ctx, evt.RoomID, "email body is empty")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
queued, err := b.Sendmail(evt.ID, meta.From, meta.To, data)
|
queued, err := b.Sendmail(evt.ID, meta.From, meta.To, data)
|
||||||
if queued {
|
if queued {
|
||||||
|
|||||||
@@ -143,13 +143,23 @@ func (e *Email) Content(threadID id.EventID, options *ContentOptions) *event.Con
|
|||||||
|
|
||||||
// Compose converts the email object to a string (to be used for delivery via SMTP) and possibly DKIM-signs it
|
// Compose converts the email object to a string (to be used for delivery via SMTP) and possibly DKIM-signs it
|
||||||
func (e *Email) Compose(privkey string) string {
|
func (e *Email) Compose(privkey string) string {
|
||||||
|
textSize := len(e.Text)
|
||||||
|
htmlSize := len(e.HTML)
|
||||||
|
if textSize == 0 && htmlSize == 0 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
mail := enmime.Builder().
|
mail := enmime.Builder().
|
||||||
From("", e.From).
|
From("", e.From).
|
||||||
To("", e.To).
|
To("", e.To).
|
||||||
Header("Message-Id", e.MessageID).
|
Header("Message-Id", e.MessageID).
|
||||||
Subject(e.Subject).
|
Subject(e.Subject)
|
||||||
Text([]byte(e.Text)).
|
if textSize > 0 {
|
||||||
HTML([]byte(e.HTML))
|
mail = mail.Text([]byte(e.Text))
|
||||||
|
}
|
||||||
|
if htmlSize > 0 {
|
||||||
|
mail = mail.HTML([]byte(e.HTML))
|
||||||
|
}
|
||||||
if e.InReplyTo != "" {
|
if e.InReplyTo != "" {
|
||||||
mail = mail.Header("In-Reply-To", e.InReplyTo)
|
mail = mail.Header("In-Reply-To", e.InReplyTo)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user