mirror of
https://github.com/coddingtonbear/django-mailbox.git
synced 2026-07-09 22:38:19 +02:00
Properly decode encoded filename headers. Fixes #96.
This commit is contained in:
commit
5b1ed1c66f
16 changed files with 52264 additions and 196 deletions
|
|
@ -1,6 +0,0 @@
|
|||
from .test_mailbox import *
|
||||
from .test_message_flattening import *
|
||||
from .test_process_email import *
|
||||
from .test_transports import *
|
||||
from .test_integration_imap import *
|
||||
from .test_settings import *
|
||||
|
|
@ -7,7 +7,7 @@ import six
|
|||
from django.conf import settings
|
||||
from django.test import TestCase
|
||||
|
||||
from django_mailbox import models
|
||||
from django_mailbox import models, utils
|
||||
from django_mailbox.models import Mailbox, Message
|
||||
|
||||
|
||||
|
|
@ -34,9 +34,13 @@ class EmailMessageTestCase(TestCase):
|
|||
]
|
||||
|
||||
def setUp(self):
|
||||
self._ALLOWED_MIMETYPES = models.ALLOWED_MIMETYPES
|
||||
self._STRIP_UNALLOWED_MIMETYPES = models.STRIP_UNALLOWED_MIMETYPES
|
||||
self._TEXT_STORED_MIMETYPES = models.TEXT_STORED_MIMETYPES
|
||||
dm_settings = utils.get_settings()
|
||||
|
||||
self._ALLOWED_MIMETYPES = dm_settings['allowed_mimetypes']
|
||||
self._STRIP_UNALLOWED_MIMETYPES = (
|
||||
dm_settings['strip_unallowed_mimetypes']
|
||||
)
|
||||
self._TEXT_STORED_MIMETYPES = dm_settings['text_stored_mimetypes']
|
||||
|
||||
self.mailbox = Mailbox.objects.create(from_email='from@example.com')
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
11
django_mailbox/tests/settings.py
Normal file
11
django_mailbox/tests/settings.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
},
|
||||
}
|
||||
INSTALLED_APPS = [
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django_mailbox',
|
||||
]
|
||||
SECRET_KEY = 'beepboop'
|
||||
|
|
@ -1,4 +1,8 @@
|
|||
from django_mailbox import models
|
||||
import copy
|
||||
|
||||
import mock
|
||||
|
||||
from django_mailbox import models, utils
|
||||
from django_mailbox.models import Message
|
||||
from django_mailbox.tests.base import EmailMessageTestCase
|
||||
|
||||
|
|
@ -74,10 +78,16 @@ class TestMessageFlattening(EmailMessageTestCase):
|
|||
expected_email_object = self._get_email_object(
|
||||
'message_with_many_multiparts_stripped_html.eml',
|
||||
)
|
||||
models.STRIP_UNALLOWED_MIMETYPES = True
|
||||
models.ALLOWED_MIMETYPES = ['text/plain']
|
||||
default_settings = utils.get_settings()
|
||||
|
||||
msg = self.mailbox.process_incoming_message(incoming_email_object)
|
||||
with mock.patch('django_mailbox.utils.get_settings') as get_settings:
|
||||
altered = copy.deepcopy(default_settings)
|
||||
altered['strip_unallowed_mimetypes'] = True
|
||||
altered['allowed_mimetypes'] = ['text/plain']
|
||||
|
||||
get_settings.return_value = altered
|
||||
|
||||
msg = self.mailbox.process_incoming_message(incoming_email_object)
|
||||
|
||||
actual_email_object = msg.get_email_object()
|
||||
|
||||
|
|
|
|||
|
|
@ -41,6 +41,31 @@ class TestProcessEmail(EmailMessageTestCase):
|
|||
'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(
|
||||
u'\u041f\u0430\u043a\u0435\u0442 \u043f\u0440\u0435\u0434\u043b'
|
||||
u'\u043e\u0436\u0435\u043d\u0438\u0439 HSE Career Fair 8 \u0430'
|
||||
u'\u043f\u0440\u0435\u043b\u044f 2016.pdf',
|
||||
attachments[0].get_filename()
|
||||
)
|
||||
self.assertEqual(
|
||||
u'\u0412\u0435\u0434\u043e\u043c\u043e\u0441\u0442\u0438.pdf',
|
||||
attachments[1].get_filename()
|
||||
)
|
||||
self.assertEqual(
|
||||
u'\u041f\u0430\u043a\u0435\u0442 \u043f\u0440\u0435\u0434\u043b'
|
||||
u'\u043e\u0436\u0435\u043d\u0438\u0439 2016.pptx',
|
||||
attachments[2].get_filename()
|
||||
)
|
||||
|
||||
def test_message_with_attachments(self):
|
||||
message = self._get_email_object('message_with_attachment.eml')
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +0,0 @@
|
|||
from django.test import TestCase
|
||||
from django.conf import settings
|
||||
from django_mailbox.models import ATTACHMENT_UPLOAD_TO
|
||||
|
||||
|
||||
class TestSettings(TestCase):
|
||||
def test_default_attachment_upload_to(self):
|
||||
user_setting = getattr(settings, 'DJANGO_MAILBOX_ATTACHMENT_UPLOAD_TO', False)
|
||||
self.assertFalse(user_setting)
|
||||
self.assertEqual(ATTACHMENT_UPLOAD_TO, 'mailbox_attachments/%Y/%m/%d/')
|
||||
Loading…
Add table
Add a link
Reference in a new issue