From 6b8ee4a183fc50eb1bcc7b31a9fc09e9cc705163 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20=C5=BBarnowiecki?= Date: Sat, 7 May 2016 12:32:10 +0200 Subject: [PATCH] Handle maxage for davmail correctly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "imapobj.search" returns a list with one string element of numbers separated by one whitespace character for regular box (GMail, AOL...). ['1 2 3 4 5 6 7 8 9 10 11 12'] But if we would like to sync from Davmail it would return a list of numbers. ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12']. The code "return res_data[0].split()" in the first case will return what we already have when using Davmail, hence only one email will be fetched. But if only the first sync would be with maxage the emails will be removed, because offlineimap will think that they were removed by us. The patch distinguishes between syncing with Davmail and regular box and applies split on the first element only when it finds whitespace character. It also handles the case when the first element is empty on first sync. Closes #327 Signed-off-by: Łukasz Żarnowiecki Signed-off-by: Nicolas Sebrecht --- offlineimap/folder/IMAP.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/offlineimap/folder/IMAP.py b/offlineimap/folder/IMAP.py index c105b72..c305334 100644 --- a/offlineimap/folder/IMAP.py +++ b/offlineimap/folder/IMAP.py @@ -177,7 +177,11 @@ class IMAPFolder(BaseFolder): "Search string was '%s'. Server responded '[%s] %s'"% ( self.getrepository(), self, search_cond, res_type, res_data), OfflineImapError.ERROR.FOLDER) - return res_data[0].split() + # 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] == '': + res_data = res_data[0].split() + return res_data res_type, imapdata = imapobj.select(self.getfullname(), True, True) if imapdata == [None] or imapdata[0] == '0':