#26227: Unicode attachment filename displays incorrectly in some clients
-------------------------------------+-------------------------------------
Reporter: Sergey Gornostaev | Owner: nobody
Type: Bug | Status: new
Component: Core (Mail) | Version: 1.9
Severity: Normal | Resolution:
Keywords: email attachment, | Triage Stage:
filenames, i18n | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Thomi Richards):
* status: closed => new
* resolution: invalid =>
Comment:
Hi,
I came across this issue in django 1.11.11 - using the `EmailMessage`
class, attachments with non-ascii characters in their filenames render as
'noname' in GMail.
I'm no expert in MIME - I've read RFC2231 and RFC2047, which seem to be
on-topic for this case. However, the exact "correct" behaviour here isn't
obvious to me. However, I was able to fix the issue like so:
{{{
class EmailMessageWithAttachmentEncoding(EmailMessage):
def _create_attachment(self, filename, content, mimetype=None):
attachment = self._create_mime_attachment(content, mimetype)
if filename:
try:
parameters = {
'filename': filename.encode('ascii'),
}
except UnicodeEncodeError:
# Include both parameters manually because Python's
implementation
# only adheres to RFC2231 and not RFC2047 which breaks
some clients
# such as GMail.
filename = Header(filename, 'utf-8').encode()
parameters = {
'filename*': filename, # RFC2231
'filename': filename, # RFC2047
}
attachment.add_header('Content-Disposition', 'attachment',
**parameters)
return attachment
}}}
I'm not sure if the django project would accept this as a patch,
especially since it seems to me like the correct behaviour here is
somewhat undefined (perhaps there's a MIME expert willing to testify?). In
any case, this solution has worked for me, and might help others who
stumble across this page while trying to debug the same issue.
I've re-opened the issue, since it seems like we probably want django's
email features to work with GMail, even if the fix differs from what I've
pasted above.
--
Ticket URL: <https://code.djangoproject.com/ticket/26227#comment:6>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/068.412b7e96d78a56a4bd4220dccca2e812%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.