mail icon indicating copy to clipboard operation
mail copied to clipboard

Parsing mail with attachment that has no filename will not find attachment

Open lazyatom opened this issue 1 year ago • 4 comments

I've been parsing emails from from Outlook (I think), and I've seen that the attachment parts have no filename information:

# ... earlier parts of email

--_001_ABC123MAILPARTDIVIDERRANDOMNUMBERS_
Content-Type: message/rfc822
Content-Disposition: attachment;
	creation-date="Tue, 03 Dec 2024 12:01:37 GMT";
	modification-date="Tue, 03 Dec 2024 12:01:37 GMT"

From: Alice Smith <[email protected]>
To: "Bob" <[email protected]>
Subject: Some email file I'm attaching

# etc ...

The Mail gem fails to recognise this as an attachment, despite the content disposition, because there's nothing it recognises as the filename, and that's fundamental to how Mail determines if an attachment exists.

According to the RCF, the filename is not mandatory, and I believe the intention that mail implementations can use the value, if present, but also aren't obliged to.

In my particular case, I'd like to be able to get all parts that have Content-Disposition: attachment as attachments, and I am not sure it's technically correct that our gem only reports parts that have filenames. I would be happy to supply a default filename; perhaps message.attachments would expose the nameless attachment's mime type to me and let me use something like Marcel to determine an appropriate file extension.

I'd be more than happy to work on a PR; I have a patch in my app for the particular case I'm hitting, but if we can figure out a general approach that works for all unnamed attachment types, I'd be more than happy to put the work in to address it.

lazyatom avatar Dec 05 '24 15:12 lazyatom

could you check if https://github.com/mikel/mail/pull/1389 fixes the issue? the change hasn't been released yet.

ahorek avatar Dec 17 '24 14:12 ahorek

Unfortunately #1389 doesn't fix this specific issue (although it fixes others, and I'm using the patch in our app, thank you!). This issue only occurs when the mail part has none of the header information that Mail tries to use as the filename specifically.

lazyatom avatar Dec 17 '24 14:12 lazyatom

ok, try this https://github.com/mikel/mail/pull/1628

however, I'm not sure if it handles all real cases...

ahorek avatar Dec 17 '24 16:12 ahorek

That works for my test case, certainly!

lazyatom avatar Dec 18 '24 11:12 lazyatom