[PATCH] UI message inaccurate

Janna Martl janna.martl109 at gmail.com
Sat Mar 21 06:15:25 GMT 2015


Some messages were excluded from the copy/delete list after the UI message said
they were copied/deleted. Also fix Internaldate2epoch(), which was wrong.

Signed-off-by: Janna Martl <janna.martl109 at gmail.com>
---
 offlineimap/folder/Base.py    | 39 +++++++++++++++++++++++++--------------
 offlineimap/folder/IMAP.py    |  2 --
 offlineimap/folder/Maildir.py |  3 ---
 offlineimap/imaplibutil.py    |  4 +++-
 4 files changed, 28 insertions(+), 20 deletions(-)

diff --git a/offlineimap/folder/Base.py b/offlineimap/folder/Base.py
index af4bfc9..8538637 100644
--- a/offlineimap/folder/Base.py
+++ b/offlineimap/folder/Base.py
@@ -373,7 +373,8 @@ class BaseFolder(object):
         dryrun mode."""
 
         for uid in uidlist:
-            self.addmessageflags(uid, flags)
+            if self.uidexists(uid):
+                self.addmessageflags(uid, flags)
 
     def deletemessageflags(self, uid, flags):
         """Removes each flag given from the message's flag set.  If a given
@@ -703,11 +704,6 @@ class BaseFolder(object):
                 content = self.getmessage(uid)
                 rtime = emailutil.get_message_date(content, 'Date')
 
-            if uid > 0 and dstfolder.uidexists(uid):
-                # dst has message with that UID already, only update status
-                statusfolder.savemessage(uid, None, flags, rtime)
-                return
-
             # If any of the destinations actually stores the message body,
             # load it up.
             if dstfolder.storesmessages():
@@ -774,6 +770,16 @@ class BaseFolder(object):
             # bail out on CTRL-C or SIGTERM
             if offlineimap.accounts.Account.abort_NOW_signal.is_set():
                 break
+            if uid > 0 and dstfolder.uidexists(uid):
+                # dst has message with that UID already, only update status
+                flags = self.getmessageflags(uid)
+                rtime = self.getmessagetime(uid)
+                if dstfolder.utime_from_message:
+                    content = self.getmessage(uid)
+                    rtime = emailutil.get_message_date(content, 'Date')
+                statusfolder.savemessage(uid, None, flags, rtime)
+                copylist.remove(uid)
+
             self.ui.copyingmessage(uid, num+1, num_to_copy, self, dstfolder)
             # exceptions are caught in copymessageto()
             if self.suggeststhreads() and not globals.options.singlethreading:
@@ -798,19 +804,24 @@ class BaseFolder(object):
         that were deleted in 'self'. Delete those from dstfolder and
         statusfolder.
 
-        This function checks and protects us from action in ryrun mode.
+        This function checks and protects us from action in dryrun mode.
         """
 
         deletelist = filter(lambda uid: uid >= 0 and not
             self.uidexists(uid), statusfolder.getmessageuidlist())
         if len(deletelist):
-            self.ui.deletingmessages(deletelist, [dstfolder])
-            if self.repository.account.dryrun:
-                return #don't delete messages in dry-run mode
-            # delete in statusfolder first to play safe. In case of abort, we
-            # won't lose message, we will just retransmit some unneccessary.
-            for folder in [statusfolder, dstfolder]:
-                folder.deletemessages(deletelist)
+            # Delete in statusfolder first to play safe. In case of abort, we
+            # won't lose message, we will just unneccessarily retransmit some.
+            # Delete messages from statusfolder that were either deleted by the
+            # user, or not being tracked (e.g. because of maxage).
+            statusfolder.deletemessages(deletelist)
+            # Filter out untracked messages
+            deletelist = filter(lambda uid: dstfolder.uidexists(uid), deletelist)
+            if len(deletelist):
+                self.ui.deletingmessages(deletelist, [dstfolder])
+                if self.repository.account.dryrun:
+                    return #don't delete messages in dry-run mode
+                dstfolder.deletemessages(deletelist)
 
     def __syncmessagesto_flags(self, dstfolder, statusfolder):
         """Pass 3: Flag synchronization.
diff --git a/offlineimap/folder/IMAP.py b/offlineimap/folder/IMAP.py
index 20f5cda..a493277 100644
--- a/offlineimap/folder/IMAP.py
+++ b/offlineimap/folder/IMAP.py
@@ -837,8 +837,6 @@ class IMAPFolder(BaseFolder):
         self.__deletemessages_noconvert(uidlist)
 
     def __deletemessages_noconvert(self, uidlist):
-        # Weed out ones not in self.messagelist
-        uidlist = [uid for uid in uidlist if self.uidexists(uid)]
         if not len(uidlist):
             return
 
diff --git a/offlineimap/folder/Maildir.py b/offlineimap/folder/Maildir.py
index 8bbfa07..3e9deb2 100644
--- a/offlineimap/folder/Maildir.py
+++ b/offlineimap/folder/Maildir.py
@@ -440,9 +440,6 @@ class MaildirFolder(BaseFolder):
         :return: Nothing, or an Exception if UID but no corresponding file
                  found.
         """
-        if not self.uidexists(uid):
-            return
-
         filename = self.messagelist[uid]['filename']
         filepath = os.path.join(self.getfullname(), filename)
         try:
diff --git a/offlineimap/imaplibutil.py b/offlineimap/imaplibutil.py
index 30aed9a..4f33be1 100644
--- a/offlineimap/imaplibutil.py
+++ b/offlineimap/imaplibutil.py
@@ -222,6 +222,8 @@ def Internaldate2epoch(resp):
 
     Returns seconds since the epoch."""
 
+    from calendar import timegm
+
     mo = InternalDate.match(resp)
     if not mo:
         return None
@@ -245,4 +247,4 @@ def Internaldate2epoch(resp):
 
     tt = (year, mon, day, hour, min, sec, -1, -1, -1)
 
-    return time.mktime(tt)
+    return timegm(tt) - zone
-- 
2.3.3





More information about the OfflineIMAP-project mailing list