Skip to content

Commit

Permalink
Fix ToFromString to handle and trim empty addresses
Browse files Browse the repository at this point in the history
Previously, the ToFromString function split email addresses by commas but did not handle empty addresses or trim whitespace. Now, it trims each address and ignores any empty entries to ensure only valid addresses are processed. This prevents potential errors stemming from malformed input.
  • Loading branch information
wneessen committed Oct 25, 2024
1 parent 03da20f commit c99b6c3
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 @@ -753,7 +753,16 @@ func (m *Msg) ToIgnoreInvalid(rcpts ...string) {
// References:
// - https://datatracker.ietf.org/doc/html/rfc5322#section-3.6.3
func (m *Msg) ToFromString(rcpts string) error {
return m.To(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.To(dst...)
}

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

0 comments on commit c99b6c3

Please sign in to comment.