Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

Commit

Permalink
ascii_attachments: don't process filename's extension apart
Browse files Browse the repository at this point in the history
  • Loading branch information
Bertrand Mathieu committed Sep 18, 2014
1 parent 352b530 commit ee8c1eb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
7 changes: 2 additions & 5 deletions flask_mail.py
Expand Up @@ -352,11 +352,8 @@ def as_string(self):
if filename and ascii_attachments:
# force filename to ascii
filename = unicodedata.normalize('NFKD', filename)
filename = filename.encode('ascii', 'ignore')
filename, ext = filename.decode('ascii').rsplit(u'.')
ext = ext.strip()
filename = SPACES.sub(u' ', filename)
filename = u'{0}.{1}'.format(filename.strip(), ext)
filename = filename.encode('ascii', 'ignore').decode('ascii')
filename = SPACES.sub(u' ', filename).strip()

try:
filename and filename.encode('ascii')
Expand Down
5 changes: 2 additions & 3 deletions tests.py
Expand Up @@ -321,14 +321,13 @@ def test_plain_message_with_ascii_converted_attachment(self):

msg.attach(data=b"this is a test",
content_type="text/plain",
filename=u'ünicöde ←→ ✓.txt')
filename=u'ünicödeß ←.→ ✓.txt')

parsed = email.message_from_string(msg.as_string())
self.assertIn(
'Content-Disposition: attachment; filename="unicode.txt"',
'Content-Disposition: attachment; filename="unicode . .txt"',
msg.as_string())


def test_html_message(self):
html_text = "<p>Hello World</p>"
msg = Message(sender="from@example.com",
Expand Down

0 comments on commit ee8c1eb

Please sign in to comment.