[PATCH 4/4] Maildir won't be called with min_uid

Nicolas Sebrecht nicolas.s-dev at laposte.net
Wed Mar 25 04:42:30 GMT 2015


Signed-off-by: Nicolas Sebrecht <nicolas.s-dev at laposte.net>
---
 offlineimap/folder/Maildir.py | 41 ++++++++++++++++++++---------------------
 1 file changed, 20 insertions(+), 21 deletions(-)

diff --git a/offlineimap/folder/Maildir.py b/offlineimap/folder/Maildir.py
index c0ad516..308abf3 100644
--- a/offlineimap/folder/Maildir.py
+++ b/offlineimap/folder/Maildir.py
@@ -150,15 +150,13 @@ class MaildirFolder(BaseFolder):
             flags = set((c for c in flagmatch.group(1) if not c.islower()))
         return prefix, uid, fmd5, flags
 
-    def _scanfolder(self, maxage=None, min_uid=None):
+    def _scanfolder(self, maxage=None):
         """Cache the message list from a Maildir.
 
-        If using maxage, this finds the min uid of all messages within
-        maxage, and returns all messages with uid > this min. This
-        ensures consistency with remote (which only restricts to uid >
-        this min) in edge cases where the date is much earlier than
-        messages with similar UID's (e.g. the UID was reassigned much
-        later).
+        If using maxage, this finds the min UID of all messages within maxage
+        and use it as the real cursor up to where we go back in time. This handles
+        the edge cases where the date is much earlier than messages with similar
+        UID's (e.g. the UID was reassigned much later).
 
         Maildir flags are: R (replied) S (seen) T (trashed) D (draft) F
         (flagged).
@@ -176,7 +174,6 @@ class MaildirFolder(BaseFolder):
                          filename in os.listdir(fulldirname))
 
         maxage_excludees = {}
-
         for dirannex, filename in files:
             # We store just dirannex and filename, ie 'cur/123...'
             filepath = os.path.join(dirannex, filename)
@@ -190,9 +187,6 @@ class MaildirFolder(BaseFolder):
                 uid = nouidcounter
                 nouidcounter -= 1
             else:                       # It comes from our folder.
-                # Check min_uid if this message should be considered.
-                if min_uid != None and uid < min_uid:
-                    continue
                 uidmatch = re_uidmatch.search(filename)
                 uid = None
                 if not uidmatch:
@@ -200,10 +194,15 @@ class MaildirFolder(BaseFolder):
                     nouidcounter -= 1
                 else:
                     uid = long(uidmatch.group(1))
-            if maxage and not self._iswithinmaxage(filename, maxage):
-                # Keep track of messages outside of maxage, because the ones
-                # with uid > min(uids of within-maxage messages) will get
-                # re-included.
+            if maxage != None and not self._iswithinmaxage(filename, maxage):
+                # Keep track of messages outside of maxage, because they still
+                # might have UID > min(UIDs of within-maxage). We hit this case
+                # if any message had a known/valid datetime and was re-uploaded
+                # because the UID in the filename got lost (e.g. local
+                # copy/move).  On next sync, it was assigned a new UID from the
+                # server and will be included in the SEARCH condition.  So, we
+                # must re-include them later in this method in order to avoid
+                # inconsistent lists of messages.
                 maxage_excludees[uid] = self.msglist_item_initializer(uid)
                 maxage_excludees[uid]['flags'] = flags
                 maxage_excludees[uid]['filename'] = filepath
@@ -212,7 +211,7 @@ class MaildirFolder(BaseFolder):
                 retval[uid] = self.msglist_item_initializer(uid)
                 retval[uid]['flags'] = flags
                 retval[uid]['filename'] = filepath
-        if maxage:
+        if maxage != None:
             # Re-include messages with high enough uid's.
             positive_uids = filter(lambda uid: uid > 0, retval)
             if positive_uids:
@@ -220,8 +219,8 @@ class MaildirFolder(BaseFolder):
                 for uid in maxage_excludees.keys():
                     if uid > min_uid:
                         # This message was originally excluded because of
-                        # maxage, but is included now because we want all
-                        # messages with uid > min_uid
+                        # maxage. It is re-included now because we want all
+                        # messages with UID > min_uid.
                         retval[uid] = maxage_excludees[uid]
         return retval
 
@@ -246,9 +245,9 @@ class MaildirFolder(BaseFolder):
         return {'flags': set(), 'filename': '/no-dir/no-such-file/'}
 
     # Interface from BaseFolder
-    def cachemessagelist(self, maxage=None, min_uid=None):
+    def cachemessagelist(self, maxage=None):
         if self.ismessagelistempty():
-            self.messagelist = self._scanfolder(maxage=maxage, min_uid=min_uid)
+            self.messagelist = self._scanfolder(maxage=maxage)
 
     # Interface from BaseFolder
     def getmessagelist(self):
@@ -473,7 +472,7 @@ class MaildirFolder(BaseFolder):
             os.unlink(filepath)
         except OSError:
             # Can't find the file -- maybe already deleted?
-            maxage = localfolder.getmaxage()
+            maxage = self.getmaxage()
             # get more than enough messages to be sure we captured the min UID
             # expected on the other side
             newmsglist = self._scanfolder(maxage=maxage + 1)
-- 
2.3.1





More information about the OfflineIMAP-project mailing list