Skip to content

Commit

Permalink
Refactor error handling in eml parser
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wneessen committed Oct 24, 2024
1 parent 9f1e197 commit 769783f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions eml.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
}
}

Expand Down Expand Up @@ -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
}

0 comments on commit 769783f

Please sign in to comment.