From 769783f0375e928fe43e4c6c594dc951d9ad9f67 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Thu, 24 Oct 2024 16:42:00 +0200 Subject: [PATCH] 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. --- eml.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/eml.go b/eml.go index 61a7151..0363d89 100644 --- a/eml.go +++ b/eml.go @@ -218,9 +218,9 @@ func parseEMLHeaders(mailHeader *netmail.Header, msg *Msg) error { for _, addr := range parsedAddrs { addrStrings = append(addrStrings, addr.String()) } - if err = addrFunc(addrStrings...); err != nil { - return fmt.Errorf(`failed to parse %q header: %w`, addrHeader, err) - } + // We can skip the error checking here since netmail.ParseAddressList already performed the + // 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 { return fmt.Errorf("failed to embed multipart body: %w", err) } + default: + return errors.New("unsupported content disposition type") } return nil }