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