Skip to content

Commit

Permalink
parse cc and bcc from custom headers to add them on email envelope (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
usverger authored May 18, 2024
1 parent 6886878 commit 3babd90
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions internal/messenger/email/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"math/rand"
"net/smtp"
"net/textproto"
"strings"

"github.com/knadh/listmonk/models"
"github.com/knadh/smtppool"
Expand All @@ -14,6 +15,8 @@ import (
const (
emName = "email"
hdrReturnPath = "Return-Path"
hdrBcc = "Bcc"
hdrCc = "Cc"
)

// Server represents an SMTP server's credentials.
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 3babd90

Please sign in to comment.