do not add empty mime parts, fixes #51

This commit is contained in:
Aine
2022-11-17 23:11:11 +02:00
parent 99a89ef87a
commit 66bd1a4fab
3 changed files with 21 additions and 3 deletions

View File

@@ -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
func (e *Email) Compose(privkey string) string {
textSize := len(e.Text)
htmlSize := len(e.HTML)
if textSize == 0 && htmlSize == 0 {
return ""
}
mail := enmime.Builder().
From("", e.From).
To("", e.To).
Header("Message-Id", e.MessageID).
Subject(e.Subject).
Text([]byte(e.Text)).
HTML([]byte(e.HTML))
Subject(e.Subject)
if textSize > 0 {
mail = mail.Text([]byte(e.Text))
}
if htmlSize > 0 {
mail = mail.HTML([]byte(e.HTML))
}
if e.InReplyTo != "" {
mail = mail.Header("In-Reply-To", e.InReplyTo)
}