folder: IMAP: improve search logging

Log when exception occured during search command, too.

Github-ref: https://github.com/OfflineIMAP/offlineimap/issues/512
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
Nicolas Sebrecht 2017-12-20 08:49:59 +01:00
parent e8b31af4c2
commit e802f5fbd5

View File

@ -209,12 +209,18 @@ class IMAPFolder(BaseFolder):
Returns: range(s) for messages or None if no messages
are to be fetched."""
try:
res_type, res_data = imapobj.search(None, search_conditions)
if res_type != 'OK':
raise OfflineImapError("SEARCH in folder [%s]%s failed. "
"Search string was '%s'. Server responded '[%s] %s'"% (
self.getrepository(), self, search_cond, res_type, res_data),
OfflineImapError.ERROR.FOLDER)
except Exception as e:
raise OfflineImapError("SEARCH in folder [%s]%s failed. "
"Search string was '%s'. Error: %s"% (
self.getrepository(), self, search_cond, str(e)),
OfflineImapError.ERROR.FOLDER)
# Davmail returns list instead of list of one element string.
# On first run the first element is empty.
if ' ' in res_data[0] or res_data[0] == '':