parse cc and bcc from custom headers to add them on email envelope (#1865)

This commit is contained in:
Sergey Minkov 2024-05-18 08:19:24 -04:00 committed by GitHub
parent 6886878ec5
commit 3babd9020e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -6,6 +6,7 @@ import (
"math/rand"
"net/smtp"
"net/textproto"
"strings"
"github.com/knadh/listmonk/models"
"github.com/knadh/smtppool"
@ -14,6 +15,8 @@ import (
const (
emName = "email"
hdrReturnPath = "Return-Path"
hdrBcc = "Bcc"
hdrCc = "Cc"
)
// Server represents an SMTP server's credentials.
@ -146,6 +149,22 @@ func (e *Emailer) Push(m models.Message) error {
em.Headers.Del(hdrReturnPath)
}
// If the `Bcc` header is set, it should be set on the Envelope
if bcc := em.Headers.Get(hdrBcc); bcc != "" {
for _, part := range strings.Split(bcc, ",") {
em.Bcc = append(em.Bcc, strings.TrimSpace(part))
}
em.Headers.Del(hdrBcc)
}
// If the `Cc` header is set, it should be set on the Envelope
if cc := em.Headers.Get(hdrCc); cc != "" {
for _, part := range strings.Split(cc, ",") {
em.Cc = append(em.Cc, strings.TrimSpace(part))
}
em.Headers.Del(hdrCc)
}
switch m.ContentType {
case "plain":
em.Text = []byte(m.Body)