mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-14 18:02:55 +01:00
Refine CcFromString
to handle spaces and empty addresses.
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.
This commit is contained in:
parent
d7b32480fd
commit
855d7f0867
1 changed files with 10 additions and 1 deletions
11
msg.go
11
msg.go
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue