Fix IMAP4 store flags argument, GitLab issue #606
Python's documentation is incorrect, argument name is flag_list. Closes GitLab issue #606. Thanks to Samuel Aebi (@samuelaebi) for the report and debug information. Signed-off-by: Roberto Rosario <roberto.rosario@mayan-edms.com>
This commit is contained in:
@@ -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)
|
||||
==================
|
||||
|
||||
@@ -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/
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user