From 855d7f08670af0de375396ae568390fdbc825cfd Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Sat, 26 Oct 2024 18:21:50 +0200 Subject: [PATCH] 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. --- msg.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/msg.go b/msg.go index bd771b0..587894f 100644 --- a/msg.go +++ b/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.