Problem syncing mail - crash

Vladimir Marek Vladimir.Marek at Oracle.COM
Sun Jul 24 11:35:10 BST 2011

> According to the FAQ, it is to be expected in "rare instances", see

Nice. The fix is quite simple then (attached). But I believe we can do
better than that. We still should be able to find the message by
fetching message headers.
-------------- next part --------------
diff --git a/offlineimap/folder/ b/offlineimap/folder/
index 608d361..d4580a9 100644
--- a/offlineimap/folder/
+++ b/offlineimap/folder/
@@ -264,6 +264,15 @@ 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
+                # (probably IMAP has neither APPENDUID nor SEARCH implemented).
+                # 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)
                 raise UserWarning("Trying to save msg (uid %d) on folder "
                                   "%s returned invalid uid %d" % \
diff --git a/offlineimap/folder/ b/offlineimap/folder/
index 9297a7b..04f0aa9 100644
--- a/offlineimap/folder/
+++ b/offlineimap/folder/
@@ -409,8 +412,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't 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

More information about the OfflineIMAP-project mailing list