-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inline vs Attachment part logic is insufficient for emails in the wild #138
Comments
Hm, this seems to be allowed by the RFC and indicate that the PDF attachment should be displayed with the text of the message. The RFCs allow very surprising things, such as multiple inline parts mixed together with a different MIME type each. |
Thanks for your quick response! I think this particular set of MIME headers is a violation of the standard, as e.g. RFC 2045 section 5 (Content-Type Header field) prescribes that
and RFC 2046 Section 3 says
Of course, we will always see a badly formatted email in the wild, and no library can expect to handle all of these cases - "you can't enumerate badness". I'm wondering what is the best way for a library like Here is one example: we can extend type header interface {
ContentType() (t string, params map[string]string, err error)
ContentDisposition() (t string, params map[string]string, err error)
}
h, ok := p.Header.(header)
if !ok {
// Impossible with the current implementation
} but it would make writing the user code easier. Another good candidate would be If you feel that this is unnecessary, please feel free to close this issue. |
Oh. FWIW, it's also possible for have non-textual parts with an Regarding your suggestion, maybe we can just add these to the existing |
Ah, this is exactly what you suggest. Yes, this sounds reasonable. |
Cool - why don't I work on a pull request then? I will add |
Hello,
with the current implementation, interface
PartHeader
is implemented as eitherInlineHeader
orAttachmentHeader
that both embedmessage.Header
.And although it's not documented by the package, the wiki example implies thatPartHeader
will always be one of the two.The logic to decide whether its
AttachmentHeader
orPartHeader
,unfortunately, doesn't always work for emails in the wild. E.g., I have a message with the following part header:
It's clearly a PDF attachment, but is currently classified as
InlineHeader
, so we cannot useAttachmentHeader.Filename
to extract the filename.To solve this problem, the user code can of course cast
PartHeader
asHeader
(which will succeed with the current implementation), and then effectively re-implementAttachmentHeader.Filename
logic by perusingHeader.ContentDisposition
andHeader.ContentType
methods.The alternative would be, at a minimum, to extend
PartHeader
interface to directly exposeContentDisposition
andContentType
, which will help the user code that works with malformed parts. (If this indeed a desired direction, I'm happy to create a pull request).Another alternative would be to improve the Inline vs Attachment logic, but it will probably be brittle as you cannot enumerate badness in the wild.
Thoughts?
The text was updated successfully, but these errors were encountered: