Skip to content

Commit

Permalink
Refine CcFromString to handle spaces and empty addresses.
Browse files Browse the repository at this point in the history
This change ensures that email addresses with leading or trailing spaces are trimmed, and empty addresses resulting from multiple commas are ignored. This helps prevent potential errors with malformed email addresses in the "Cc" field.
  • Loading branch information
wneessen committed Oct 26, 2024
1 parent d7b3248 commit 855d7f0
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,16 @@ func (m *Msg) CcIgnoreInvalid(rcpts ...string) {
// References:
// - https://datatracker.ietf.org/doc/html/rfc5322#section-3.6.3
func (m *Msg) CcFromString(rcpts string) error {
return m.Cc(strings.Split(rcpts, ",")...)
src := strings.Split(rcpts, ",")
var dst []string
for _, address := range src {
address = strings.TrimSpace(address)
if address == "" {
continue
}
dst = append(dst, address)
}
return m.Cc(dst...)
}

// Bcc sets one or more "BCC" (blind carbon copy) addresses in the mail body for the Msg.
Expand Down

0 comments on commit 855d7f0

Please sign in to comment.