[PATCH 2/4] Handle when UID can't be found on saved messages

Vladimir.Marek at oracle.com Vladimir.Marek at oracle.com
Sun Jul 31 09:48:24 BST 2011


From: Vladimir Marek <vlmarek at volny.cz>

Message was stored to dstfolder, but we can't find it's UID. This means we can't
link current message to the one created in IMAP. So we just delete local message
and on next run we'll sync it back. Also fixed imap.savemessage description.

This was broken by e20d8b967942934ddbf4659b5ec328a9a18da6bc.

Signed-off-by: Vladimir Marek <vlmarek at volny.cz>
---
 docs/FAQ.rst               |    5 +++++
 offlineimap/folder/Base.py |    8 ++++++++
 offlineimap/folder/IMAP.py |    6 ++++--
 3 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/docs/FAQ.rst b/docs/FAQ.rst
index cebe766..3181a8a 100644
--- a/docs/FAQ.rst
+++ b/docs/FAQ.rst
@@ -189,6 +189,11 @@ Then, on your next sync, the message will be re-downloaded with the proper UID.
 `OfflineIMAP`_ makes sure that the message was properly uploaded before
 deleting it, so there should be no risk of data loss.
 
+But if you try to sync between two IMAP servers, where both are unable to
+provide you with UID of the new message, then this will lead to infinite loop.
+`OfflineIMAP`_ will upload the message to one server and delete on second. On
+next run it will upload the message to second server and delete on first, etc.
+
 Does OfflineIMAP support POP?
 -----------------------------
 
diff --git a/offlineimap/folder/Base.py b/offlineimap/folder/Base.py
index 608d361..0d5ddae 100644
--- a/offlineimap/folder/Base.py
+++ b/offlineimap/folder/Base.py
@@ -264,6 +264,14 @@ class BaseFolder(object):
                     uid = newuid
                 # Save uploaded status in the statusfolder
                 statusfolder.savemessage(uid, message, flags, rtime)
+            elif newuid == 0:
+                # Message was stored to dstfolder, but we can't find it's UID
+                # This means we can't link current message to the one created
+                # in IMAP. So we just delete local message and on next run
+                # we'll sync it back
+                # XXX This could cause infinite loop on syncing between two
+                # IMAP servers ...
+                self.deletemessage(uid)
             else:
                 raise UserWarning("Trying to save msg (uid %d) on folder "
                                   "%s returned invalid uid %d" % \
diff --git a/offlineimap/folder/IMAP.py b/offlineimap/folder/IMAP.py
index 19a0340..1fa35f7 100644
--- a/offlineimap/folder/IMAP.py
+++ b/offlineimap/folder/IMAP.py
@@ -409,8 +409,10 @@ class IMAPFolder(BaseFolder):
         the new message after sucessfully saving it.
 
         :param rtime: A timestamp to be used as the mail date
-        :returns: the UID of the new message as assigned by the
-                  server. If the folder is read-only it will return 0."""
+        :returns: the UID of the new message as assigned by the server. If the
+                  message is saved, but it's UID can not be found, it will
+                  return 0. If the message can't be written (folder is
+                  read-only for example) it will return -1."""
         self.ui.debug('imap', 'savemessage: called')
 
         # already have it, just save modified flags
-- 
1.7.3.2





More information about the OfflineIMAP-project mailing list