mirror of
https://github.com/coddingtonbear/django-mailbox.git
synced 2026-07-09 22:38:19 +02:00
[#96] Decode attachment filenames into unicodes.
This commit is contained in:
parent
b4a3cdc843
commit
276917c6e6
2 changed files with 26 additions and 3 deletions
|
|
@ -724,9 +724,7 @@ class MessageAttachment(models.Model):
|
||||||
"""Returns the original filename of this attachment."""
|
"""Returns the original filename of this attachment."""
|
||||||
file_name = self._get_rehydrated_headers().get_filename()
|
file_name = self._get_rehydrated_headers().get_filename()
|
||||||
if isinstance(file_name, six.text_type):
|
if isinstance(file_name, six.text_type):
|
||||||
return file_name
|
return utils.convert_header_to_unicode(file_name)
|
||||||
elif file_name:
|
|
||||||
return convert_header_to_unicode(file_name)
|
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,31 @@ class TestProcessEmail(EmailMessageTestCase):
|
||||||
'Adam Coddington <test@adamcoddington.net>',
|
'Adam Coddington <test@adamcoddington.net>',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_message_with_encoded_attachment_filenames(self):
|
||||||
|
message = self._get_email_object(
|
||||||
|
'message_with_koi8r_filename_attachments.eml'
|
||||||
|
)
|
||||||
|
|
||||||
|
mailbox = Mailbox.objects.create()
|
||||||
|
msg = mailbox.process_incoming_message(message)
|
||||||
|
|
||||||
|
attachments = msg.attachments.order_by('pk').all()
|
||||||
|
self.assertEqual(
|
||||||
|
'\u041f\u0430\u043a\u0435\u0442 \u043f\u0440\u0435\u0434\u043b'
|
||||||
|
'\u043e\u0436\u0435\u043d\u0438\u0439 HSE Career Fair 8 \u0430'
|
||||||
|
'\u043f\u0440\u0435\u043b\u044f 2016.pdf',
|
||||||
|
attachments[0].get_filename()
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
'\u0412\u0435\u0434\u043e\u043c\u043e\u0441\u0442\u0438.pdf',
|
||||||
|
attachments[1].get_filename()
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
'\u041f\u0430\u043a\u0435\u0442 \u043f\u0440\u0435\u0434\u043b'
|
||||||
|
'\u043e\u0436\u0435\u043d\u0438\u0439 2016.pptx',
|
||||||
|
attachments[2].get_filename()
|
||||||
|
)
|
||||||
|
|
||||||
def test_message_with_attachments(self):
|
def test_message_with_attachments(self):
|
||||||
message = self._get_email_object('message_with_attachment.eml')
|
message = self._get_email_object('message_with_attachment.eml')
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue