Add extra logging to the IMAP email source
GitLab issue #682. Thanks to Patrick Hütter (@PatrickHuetter) for the report. Signed-off-by: Roberto Rosario <roberto.rosario@mayan-edms.com>
This commit is contained in:
@@ -36,6 +36,8 @@
|
|||||||
- Add a version attribute to setting namespace. These are dumped
|
- Add a version attribute to setting namespace. These are dumped
|
||||||
as SMART_SETTINGS_NAMESPACES.
|
as SMART_SETTINGS_NAMESPACES.
|
||||||
- Add savesettings command.
|
- Add savesettings command.
|
||||||
|
- Add extra logging to the IMAP email source. GitLab issue #682.
|
||||||
|
Thanks to Patrick Hütter (@PatrickHuetter) for the report.
|
||||||
|
|
||||||
3.2.8 (2019-10-01)
|
3.2.8 (2019-10-01)
|
||||||
==================
|
==================
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ from mayan.apps.documents.models import Document
|
|||||||
from mayan.apps.metadata.api import set_bulk_metadata
|
from mayan.apps.metadata.api import set_bulk_metadata
|
||||||
from mayan.apps.metadata.models import MetadataType
|
from mayan.apps.metadata.models import MetadataType
|
||||||
|
|
||||||
|
from ..exceptions import SourceException
|
||||||
from ..literals import (
|
from ..literals import (
|
||||||
DEFAULT_IMAP_MAILBOX, DEFAULT_METADATA_ATTACHMENT_NAME,
|
DEFAULT_IMAP_MAILBOX, DEFAULT_METADATA_ATTACHMENT_NAME,
|
||||||
DEFAULT_POP3_TIMEOUT, SOURCE_CHOICE_EMAIL_IMAP, SOURCE_CHOICE_EMAIL_POP3,
|
DEFAULT_POP3_TIMEOUT, SOURCE_CHOICE_EMAIL_IMAP, SOURCE_CHOICE_EMAIL_POP3,
|
||||||
@@ -238,9 +239,22 @@ class IMAPEmail(EmailBaseModel):
|
|||||||
mailbox = imaplib.IMAP4(host=self.host, port=self.port)
|
mailbox = imaplib.IMAP4(host=self.host, port=self.port)
|
||||||
|
|
||||||
mailbox.login(user=self.username, password=self.password)
|
mailbox.login(user=self.username, password=self.password)
|
||||||
mailbox.select(mailbox=self.mailbox)
|
try:
|
||||||
|
mailbox.select(mailbox=self.mailbox)
|
||||||
|
except Exception as exception:
|
||||||
|
raise SourceException(
|
||||||
|
'Error selecting mailbox: {}; {}'.format(
|
||||||
|
self.mailbox, exception
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
status, data = mailbox.search(None, 'NOT', 'DELETED')
|
||||||
|
except Exception as exception:
|
||||||
|
raise SourceException(
|
||||||
|
'Error executing search command; {}'.format(exception)
|
||||||
|
)
|
||||||
|
|
||||||
status, data = mailbox.search(None, 'NOT', 'DELETED')
|
|
||||||
if data:
|
if data:
|
||||||
messages_info = data[0].split()
|
messages_info = data[0].split()
|
||||||
logger.debug('messages count: %s', len(messages_info))
|
logger.debug('messages count: %s', len(messages_info))
|
||||||
@@ -250,15 +264,30 @@ class IMAPEmail(EmailBaseModel):
|
|||||||
status, data = mailbox.fetch(
|
status, data = mailbox.fetch(
|
||||||
message_set=message_number, message_parts='(RFC822)'
|
message_set=message_number, message_parts='(RFC822)'
|
||||||
)
|
)
|
||||||
EmailBaseModel.process_message(
|
try:
|
||||||
source=self, message_text=data[0][1]
|
EmailBaseModel.process_message(
|
||||||
)
|
source=self, message_text=data[0][1]
|
||||||
|
)
|
||||||
|
except Exception as exception:
|
||||||
|
raise SourceException(
|
||||||
|
'Error processing message number: {}; {}'.format(
|
||||||
|
message_number, exception
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
if not test:
|
if not test:
|
||||||
mailbox.store(
|
try:
|
||||||
message_set=message_number, command='+FLAGS',
|
mailbox.store(
|
||||||
flags=r'\Deleted'
|
message_set=message_number, command='+FLAGS',
|
||||||
)
|
flags=r'\Deleted'
|
||||||
|
)
|
||||||
|
except Exception as exception:
|
||||||
|
raise SourceException(
|
||||||
|
'Error executing IMAP store command '
|
||||||
|
'on message number {}; {}'.format(
|
||||||
|
message_number, exception
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
mailbox.expunge()
|
mailbox.expunge()
|
||||||
mailbox.close()
|
mailbox.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user