From 26721c60d496c0782dabe0676ddcc8be4d8f97be Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Wed, 7 Sep 2011 15:23:28 +0200 Subject: [PATCH] Don't cache empty IMAP folders If a folder is empty, most servers will return EXISTS 0 and imaplib2 passes back ['0'] as return value to a select(). It returns [None] if no EXISTS response was given by the server at all. Attempting to fetch the UIDs of 0 emails which leads to various error messages (One server responds with "NO No matching messages", Gmail seems to say "BAD Bad message sequence 1:*" for some (although it is working fine for me with Gmail, so it might behave different for different people). In case we get an None or 0 back, we simply stop caching messages as the folder is empty. This should fix the various error reports that have popped up. Signed-off-by: Sebastian Spaeth Signed-off-by: Nicolas Sebrecht --- offlineimap/folder/IMAP.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/offlineimap/folder/IMAP.py b/offlineimap/folder/IMAP.py index 5a14776..d860e85 100644 --- a/offlineimap/folder/IMAP.py +++ b/offlineimap/folder/IMAP.py @@ -120,7 +120,9 @@ class IMAPFolder(BaseFolder): imapobj = self.imapserver.acquireconnection() try: res_type, imapdata = imapobj.select(self.getfullname(), True) - + if imapdata == [None] or imapdata[0] == '0': + # Empty folder, no need to populate message list + return # By default examine all UIDs in this folder msgsToFetch = '1:*'