Ticket #14964: mail_attachment.diff

File mail_attachment.diff, 1.1 KB (added by antonyc, 14 years ago)

The diff between trunk as of 2010-12-24 21:19:48 handling non ASCII filenames in email attachments

  • core/mail/message.py

     
    1111
    1212from django.conf import settings
    1313from django.core.mail.utils import DNS_NAME
    14 from django.utils.encoding import smart_str, force_unicode
     14from django.utils.encoding import smart_str, force_unicode, iri_to_uri
    1515
    1616# Don't BASE64-encode UTF-8 messages so that we avoid unwanted attention from
    1717# some spam filters.
     
    249249                mimetype = DEFAULT_ATTACHMENT_MIME_TYPE
    250250        attachment = self._create_mime_attachment(content, mimetype)
    251251        if filename:
    252             attachment.add_header('Content-Disposition', 'attachment',
    253                                   filename=filename)
     252            if all(ord(c) < 128 for c in filename):
     253                params = {'filename': filename}
     254            else:
     255                params = {'filename': "UTF-8''%s" % iri_to_uri(filename)}}
     256            attachment.add_header('Content-Disposition', 'attachment',**params)
    254257        return attachment
    255258
    256259
Back to Top