Compare commits

...

2 commits

Author SHA1 Message Date
8b1208949f
Fix multipart header parsing in eml.go
The commit modifies the parseMultiPartHeader function to handle optional fields accurately. The delimiter was changed from "; " to ";" and whitespace is being trimmed from the start of optional fields to ensure correct splitting and mapping.
2024-06-25 10:59:04 +02:00
faab5323fd
Fix erroneous header name in error message
The error message previously referenced a constant 'HeaderTo' which might not always be the header being parsed. The commit replaces this with 'addrHeader', significantly improving the accuracy of error messages.
2024-06-25 09:47:12 +02:00

5
eml.go
View file

@ -142,7 +142,7 @@ func parseEMLHeaders(mailHeader *netmail.Header, msg *Msg) error {
addrStrings = append(addrStrings, addr.String()) addrStrings = append(addrStrings, addr.String())
} }
if err = addrFunc(addrStrings...); err != nil { if err = addrFunc(addrStrings...); err != nil {
return fmt.Errorf(`failed to parse %q header: %w`, HeaderTo, err) return fmt.Errorf(`failed to parse %q header: %w`, addrHeader, err)
} }
} }
} }
@ -372,7 +372,8 @@ func parseMultiPartHeader(multiPartHeader string) (header string, optional map[s
headerSplit := strings.SplitN(multiPartHeader, ";", 2) headerSplit := strings.SplitN(multiPartHeader, ";", 2)
header = headerSplit[0] header = headerSplit[0]
if len(headerSplit) == 2 { if len(headerSplit) == 2 {
optSplit := strings.SplitN(headerSplit[1], "=", 2) optString := strings.TrimLeft(headerSplit[1], " ")
optSplit := strings.SplitN(optString, "=", 2)
if len(optSplit) == 2 { if len(optSplit) == 2 {
optional[optSplit[0]] = optSplit[1] optional[optSplit[0]] = optSplit[1]
} }