Skip to content

Commit

Permalink
Catches OSError on IMAP connection error
Browse files Browse the repository at this point in the history
When something goes wrong with the imaplib.IMAP4_SSL connection (like the host is
temporarely down or the DNS does not resolve) it generates an OSError which is currently
not catched and handled. Now OSErrors are translated to MailFetcherErrors which get
logged and the IMAP connection is retried in the next IMAP check.

Fixes the-paperless-project#474
  • Loading branch information
syntonym committed Jan 14, 2019
1 parent 60e8990 commit 5c1edf7
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/documents/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,11 @@ def _get_messages(self):
return r

def _connect(self):
self._connection = imaplib.IMAP4_SSL(self._host, self._port)
try:
self._connection = imaplib.IMAP4_SSL(self._host, self._port)
except OSError as e:
msg = "Problem connecting to {}: {}".format(self._host, e.strerror)
raise MailFetcherError(msg)

def _login(self):

Expand Down

0 comments on commit 5c1edf7

Please sign in to comment.