diff --git a/HISTORY.rst b/HISTORY.rst index eda8594a63..0457be7fab 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -3,6 +3,9 @@ * Support configurable GUnicorn timeouts. Defaults to current value of 120 seconds. * Fix help text of the platformtemplate command. +* Fix IMAP4 mailbox.store flags argument. Python's documentation + incorrectly state it is named flag_list. Closes GitLab issue + #606. 3.2.3 (2019-06-21) ================== diff --git a/docs/releases/3.2.4.rst b/docs/releases/3.2.4.rst index 9db3ec8308..5236a7da58 100644 --- a/docs/releases/3.2.4.rst +++ b/docs/releases/3.2.4.rst @@ -10,6 +10,10 @@ Changes - Support configurable GUnicorn timeouts. Defaults to current value of 120 seconds. - Fix help text of the platformtemplate command. +- Fix IMAP4 mailbox.store flags argument. Python's documentation + incorrectly state it is named flag_list. Closes GitLab issue + #606. Thanks to Samuel Aebi (@samuelaebi) for the report and + debug information. Removals -------- @@ -98,6 +102,7 @@ Backward incompatible changes Bugs fixed or issues closed --------------------------- +- :gitlab-issue:`606` Delete after IMAP Processing - :gitlab-issue:`628` mailbox.user in POP3Email gets passed keyword argument, but only accepts "user" or positional argument .. _PyPI: https://pypi.python.org/pypi/mayan-edms/ diff --git a/mayan/apps/sources/models/email_sources.py b/mayan/apps/sources/models/email_sources.py index 57435e201e..ca8b13846b 100644 --- a/mayan/apps/sources/models/email_sources.py +++ b/mayan/apps/sources/models/email_sources.py @@ -247,10 +247,11 @@ class IMAPEmail(EmailBaseModel): EmailBaseModel.process_message( source=self, message_text=data[0][1] ) + if not test: mailbox.store( message_set=message_number, command='+FLAGS', - flag_list='\\Deleted' + flags=r'\Deleted' ) mailbox.expunge() diff --git a/mayan/apps/sources/tests/test_models.py b/mayan/apps/sources/tests/test_models.py index ab5faa913c..0d7fcdc624 100644 --- a/mayan/apps/sources/tests/test_models.py +++ b/mayan/apps/sources/tests/test_models.py @@ -20,8 +20,9 @@ from mayan.apps.metadata.models import MetadataType from mayan.apps.storage.utils import mkdtemp from ..literals import SOURCE_UNCOMPRESS_CHOICE_Y -from ..models import POP3Email, WatchFolderSource, WebFormSource -from ..models.email_sources import EmailBaseModel +from ..models.email_sources import EmailBaseModel, IMAPEmail, POP3Email +from ..models.watch_folder_sources import WatchFolderSource +from ..models.webform_sources import WebFormSource from .literals import ( TEST_EMAIL_ATTACHMENT_AND_INLINE, TEST_EMAIL_BASE64_FILENAME, @@ -60,7 +61,7 @@ class CompressedUploadsTestCase(GenericDocumentTestCase): ) -class EmailFilenameDecodingTestCase(GenericDocumentTestCase): +class EmailBaseTestCase(GenericDocumentTestCase): auto_upload_document = False def _create_email_source(self): @@ -190,6 +191,55 @@ class EmailFilenameDecodingTestCase(GenericDocumentTestCase): self.assertEqual(2, Document.objects.count()) +class IMAPSourceTestCase(GenericDocumentTestCase): + auto_upload_document = False + + class MockIMAPServer(object): + def login(self, user, password): + return ('OK', ['{} authenticated (Success)'.format(user)]) + + def select(self, mailbox='INBOX', readonly=False): + return ('OK', ['1']) + + def search(self, charset, *criteria): + return ('OK', ['1']) + + def fetch(self, message_set, message_parts): + return ( + 'OK', [ + ( + '1 (RFC822 {4800}', + TEST_EMAIL_BASE64_FILENAME + ), ' FLAGS (\\Seen))' + ] + ) + + def store(self, message_set, command, flags): + return ('OK', ['1 (FLAGS (\\Seen \\Deleted))']) + + def expunge(self): + return ('OK', ['1']) + + def close(self): + return ('OK', ['Returned to authenticated state. (Success)']) + + def logout(self): + return ('BYE', ['LOGOUT Requested']) + + @mock.patch('imaplib.IMAP4_SSL', autospec=True) + def test_download_document(self, mock_imaplib): + mock_imaplib.return_value = IMAPSourceTestCase.MockIMAPServer() + self.source = IMAPEmail.objects.create( + document_type=self.test_document_type, label='', host='', + password='', username='' + ) + + self.source.check_source() + self.assertEqual( + Document.objects.first().label, 'Ampelm\xe4nnchen.txt' + ) + + class POP3SourceTestCase(GenericDocumentTestCase): auto_upload_document = False