From e802f5fbd51be67db615ed9dbdb0d38b59260569 Mon Sep 17 00:00:00 2001 From: Nicolas Sebrecht Date: Wed, 20 Dec 2017 08:49:59 +0100 Subject: [PATCH] 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 --- offlineimap/folder/IMAP.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/offlineimap/folder/IMAP.py b/offlineimap/folder/IMAP.py index 97a07c0..ead4396 100644 --- a/offlineimap/folder/IMAP.py +++ b/offlineimap/folder/IMAP.py @@ -209,11 +209,17 @@ class IMAPFolder(BaseFolder): Returns: range(s) for messages or None if no messages are to be fetched.""" - res_type, res_data = imapobj.search(None, search_conditions) - if res_type != 'OK': + 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'. Server responded '[%s] %s'"% ( - self.getrepository(), self, search_cond, res_type, res_data), + "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.