hpop
hpop copied to clipboard
Correct attachment file name whien message content type name is null or ...
When converting message to mail message using ToMailMessage method, attachments file names were taken only from property "attachmentMessagePart.ContentType.Name".
Unfortunatelly when this propery was null then attachement file name in new mail message object was also null, although it could be read from "attachmentMessagePart.FileName". I can't tell you which e-mail client generates such EML messages without attachmentMessagePart.ContentType.Name but I got one from on of my bussiness client. Unfortunatelly it's confidential so I can't post it here.
Your code actually modifies the MessagePart. If I was calling ToMailMessage, I would not expect it to modify the original content. It would be wise to clone the ContentType instead.
The filename
parameter on the Content-Disposition header is what you should be using as your primary property for the name of the file to use on the file system.
The name
parameter on the Content-Type header is more of a "display name" and can be different (or, as in your message, not even set).
By convention, when a mail client saves to disk, it will first check the Content-Disposition filename parameter. If that is not set, it will fall back to the name parameter on the Content-Type, and, failing that, will simply prompt the user.