Return new_uid on copy message

In cases where the local UID > 0 but does not match the remote UID,
the `copymessageto()` function should return the new_uid so that
subsequent code can use it to look up the message in the message
cache.

Fixes: #613

Signed-off-by: Nicolas Bock <nicolasbock@gmail.com>
This commit is contained in:
Nicolas Bock 2019-05-04 12:44:01 -06:00
parent 5c735fd327
commit ed29330859
No known key found for this signature in database
GPG Key ID: ACE86353C0EF022A
3 changed files with 15 additions and 8 deletions

View File

@ -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.

View File

@ -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)

View File

@ -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)