Set attachment's filename to the name from Content-Type #7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I just found a couple of changes from last year that I never got around to submitting PRs for, so here's the first one!
For emails with attachments, the filename for an attachment should be specified in the filename parameter of the Content-Disposition header. But in practice, some email attachments will only have the filename in the name parameter of the Content-Type header. In my particular case, we're sending an email from .NET code using System.Net.Mail, which annoyingly only sets the filename in the Content-Type header.
While it doesn't really conform to any standard AFAIK, this behaviour is widespread enough that real email clients will generally handle it. However, currently when downloading one of these attachments using MailHog, the download does not have any set filename (e.g. in chrome it's just called "download") - I'm assuming this is because web browsers just don't bother handling this quirk that only really applies to emails.
This PR will, when downloading an email part, try to extract the filename from Content-Type header, then set this as the filename in the response's Content-Disposition header (unless the Content-Disposition already has a filename set). It will fall back to using {message_id}-part-{part_index} as the filename if it can't be found in either header.