diff --git a/offlineimap/folder/Base.py b/offlineimap/folder/Base.py index 5f287fa..a1a4f58 100644 --- a/offlineimap/folder/Base.py +++ b/offlineimap/folder/Base.py @@ -818,7 +818,7 @@ class BaseFolder(object): :param dstfolder: A BaseFolder-derived instance :param statusfolder: A LocalStatusFolder instance :param register: whether we should register a new thread." - :returns: Nothing on success, or raises an Exception.""" + :returns: the new UID on success, or raises an Exception.""" # Sometimes, it could be the case that if a sync takes awhile, # a message might be deleted from the maildir before it can be @@ -863,9 +863,10 @@ class BaseFolder(object): self.deletemessage(uid) else: raise OfflineImapError("Trying to save msg (uid %d) on folder " - "%s returned invalid uid %d"% (uid, dstfolder.getvisiblename(), - new_uid), OfflineImapError.ERROR.MESSAGE) except (KeyboardInterrupt): # Bubble up CTRL-C. + "%s returned invalid uid %d" % (uid, dstfolder.getvisiblename(), + new_uid), OfflineImapError.ERROR.MESSAGE) + return new_uid raise except OfflineImapError as e: if e.severity > OfflineImapError.ERROR.MESSAGE: @@ -941,7 +942,8 @@ class BaseFolder(object): thread.start() threads.append(thread) else: - self.copymessageto(uid, dstfolder, statusfolder, register=0) + new_uid = self.copymessageto( + uid, dstfolder, statusfolder, register=0) for thread in threads: thread.join() # Block until all "copy" threads are done. diff --git a/offlineimap/folder/Gmail.py b/offlineimap/folder/Gmail.py index 91fc87d..682bf58 100644 --- a/offlineimap/folder/Gmail.py +++ b/offlineimap/folder/Gmail.py @@ -280,13 +280,14 @@ class GmailFolder(IMAPFolder): :param dstfolder: A BaseFolder-derived instance :param statusfolder: A LocalStatusFolder instance :param register: whether we should register a new thread." - :returns: Nothing on success, or raises an Exception.""" + :returns: the new UID on success, or raises an Exception.""" # Check if we are really copying realcopy = uid > 0 and not dstfolder.uidexists(uid) # first copy the message - super(GmailFolder, self).copymessageto(uid, dstfolder, statusfolder, register) + new_uid = super(GmailFolder, self).copymessageto( + uid, dstfolder, statusfolder, register) # sync labels and mtime now when the message is new (the embedded labels are up to date) # otherwise we may be spending time for nothing, as they will get updated on a later pass. @@ -300,6 +301,8 @@ class GmailFolder(IMAPFolder): except NotImplementedError: return + return new_uid + def syncmessagesto_labels(self, dstfolder, statusfolder): """Pass 4: Label Synchronization (Gmail only) diff --git a/offlineimap/folder/GmailMaildir.py b/offlineimap/folder/GmailMaildir.py index 1405ec7..0154f9b 100644 --- a/offlineimap/folder/GmailMaildir.py +++ b/offlineimap/folder/GmailMaildir.py @@ -208,8 +208,8 @@ class GmailMaildirFolder(MaildirFolder): :param uid: uid of the message to be copied. :param dstfolder: A BaseFolder-derived instance :param statusfolder: A LocalStatusFolder instance - :param register: whether we should register a new thread." - :returns: Nothing on success, or raises an Exception.""" + :param register: whether we should register a new thread. + :returns: the new UID on success, or raises an Exception.""" # Check if we are really copying. realcopy = uid > 0 and not dstfolder.uidexists(uid) @@ -232,6 +232,8 @@ class GmailMaildirFolder(MaildirFolder): except NotImplementedError: return + return new_uid + def syncmessagesto_labels(self, dstfolder, statusfolder): """Pass 4: Label Synchronization (Gmail only)