Skip to content

Commit 276917c

Browse files
[coddingtonbear#96] Decode attachment filenames into unicodes.
1 parent b4a3cdc commit 276917c

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

django_mailbox/models.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -724,9 +724,7 @@ def get_filename(self):
724724
"""Returns the original filename of this attachment."""
725725
file_name = self._get_rehydrated_headers().get_filename()
726726
if isinstance(file_name, six.text_type):
727-
return file_name
728-
elif file_name:
729-
return convert_header_to_unicode(file_name)
727+
return utils.convert_header_to_unicode(file_name)
730728
else:
731729
return None
732730

django_mailbox/tests/test_process_email.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,31 @@ def test_message_without_attachments(self):
4040
'Adam Coddington <[email protected]>',
4141
)
4242

43+
def test_message_with_encoded_attachment_filenames(self):
44+
message = self._get_email_object(
45+
'message_with_koi8r_filename_attachments.eml'
46+
)
47+
48+
mailbox = Mailbox.objects.create()
49+
msg = mailbox.process_incoming_message(message)
50+
51+
attachments = msg.attachments.order_by('pk').all()
52+
self.assertEqual(
53+
'\u041f\u0430\u043a\u0435\u0442 \u043f\u0440\u0435\u0434\u043b'
54+
'\u043e\u0436\u0435\u043d\u0438\u0439 HSE Career Fair 8 \u0430'
55+
'\u043f\u0440\u0435\u043b\u044f 2016.pdf',
56+
attachments[0].get_filename()
57+
)
58+
self.assertEqual(
59+
'\u0412\u0435\u0434\u043e\u043c\u043e\u0441\u0442\u0438.pdf',
60+
attachments[1].get_filename()
61+
)
62+
self.assertEqual(
63+
'\u041f\u0430\u043a\u0435\u0442 \u043f\u0440\u0435\u0434\u043b'
64+
'\u043e\u0436\u0435\u043d\u0438\u0439 2016.pptx',
65+
attachments[2].get_filename()
66+
)
67+
4368
def test_message_with_attachments(self):
4469
message = self._get_email_object('message_with_attachment.eml')
4570

0 commit comments

Comments
 (0)