Refactor error handling in eml parser

Removed redundant error checking in address parsing as netmail.ParseAddressList already performs necessary checks. Added a default error return for unsupported content disposition types to improve robustness.
This commit is contained in:
Winni Neessen 2024-10-24 16:42:00 +02:00
parent 9f1e1976fe
commit 769783f037
Signed by: wneessen
GPG key ID: 385AC9889632126E

8
eml.go
View file

@ -218,9 +218,9 @@ func parseEMLHeaders(mailHeader *netmail.Header, msg *Msg) error {
for _, addr := range parsedAddrs { for _, addr := range parsedAddrs {
addrStrings = append(addrStrings, addr.String()) addrStrings = append(addrStrings, addr.String())
} }
if err = addrFunc(addrStrings...); err != nil { // We can skip the error checking here since netmail.ParseAddressList already performed the
return fmt.Errorf(`failed to parse %q header: %w`, addrHeader, err) // same address checking that the msg methods do.
} _ = addrFunc(addrStrings...)
} }
} }
@ -600,6 +600,8 @@ func parseEMLAttachmentEmbed(contentDisposition []string, multiPart *multipart.P
if err := msg.EmbedReader(filename, dataReader); err != nil { if err := msg.EmbedReader(filename, dataReader); err != nil {
return fmt.Errorf("failed to embed multipart body: %w", err) return fmt.Errorf("failed to embed multipart body: %w", err)
} }
default:
return errors.New("unsupported content disposition type")
} }
return nil return nil
} }