From 8fc72271895b7e46ad770417e2c5b8211f91eccd Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Fri, 6 Jan 2012 21:57:48 +0100 Subject: [PATCH] SEVERE: Fix getting wrong UID back on IMAP upload This change looks harmless, but it fixes a severe bugfix, potentially leading to data loss! It fixes the "on n new uploads, it will redownload n-1, n-2, n-3,... messages during the next syncs" condition, and this is what happens: If there are more than one Mails to upload to a server, we do that by repeatedly invoking folder.IMAP.savemessage(). If the server supports the UIDPLUS extension we query the resulting UID by doing a: imapobj._get_untagged_response('APPENDUID', True) and that is exactly the problem. The "True" part causes the reply to remain in the "response stack" of the imaplib2 library. When we do the same call on a subsequent message and the connection is still on the same folder, we will get the same UID response back (imaplib2 only looks for the first matching response and returns that). The only time we clear the response stack, is when the IMAP connection SELECTS a different folder. This means that when we upload 10 messages, the IMAP server gives us always the same UID (that of the first one) back. And trying to write out 10 different messages with the same UID will confuse OfflineIMAP. This is the reason why we saw the ongoing UPLOADING/DOWNLOADING behavior that people reported. And this is the reason why we saw the inconsistency in the UID mapping in the IMAP<->IMAP case. I urge everyone to upgrade ASAP. Sorry for that, I don't know why the problem only became prevalent in the recent few releases as this code has been there for quite a while. Signed-off-by: Sebastian Spaeth --- offlineimap/folder/IMAP.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/offlineimap/folder/IMAP.py b/offlineimap/folder/IMAP.py index d804766..68d1216 100644 --- a/offlineimap/folder/IMAP.py +++ b/offlineimap/folder/IMAP.py @@ -570,7 +570,7 @@ class IMAPFolder(BaseFolder): self.ui.warn("Server supports UIDPLUS but got no APPENDUID " "appending a message.") return 0 - uid = long(imapobj._get_untagged_response('APPENDUID', True)[-1].split(' ')[1]) + uid = long(imapobj._get_untagged_response('APPENDUID')[-1].split(' ')[1]) else: # we don't support UIDPLUS