From 3b8e1f91cd6bb70799714cce3437b7d58c52b2c6 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Fri, 4 Mar 2011 17:34:23 +0100 Subject: [PATCH] Implement APPENDUID support Rather than inserting our own home-grown header, everytime we save a message to an IMAP server, we check if we suport the UIDPLUS extension which provides us with an APPENDUID reply. Use that to find the new UID if possible, but keep the old way if we don't have that extension. If a folder is read-only, return the uid that we have passed in per API description in folder.Base.py Signed-off-by: Sebastian Spaeth Signed-off-by: Nicolas Sebrecht --- Changelog.draft.rst | 3 ++ offlineimap/folder/IMAP.py | 75 ++++++++++++++++++++++---------------- 2 files changed, 47 insertions(+), 31 deletions(-) diff --git a/Changelog.draft.rst b/Changelog.draft.rst index e099689..f68d747 100644 --- a/Changelog.draft.rst +++ b/Changelog.draft.rst @@ -12,6 +12,9 @@ others. New Features ------------ +* Implement UIDPLUS extension support. OfflineIMAP will now not insert + an X-OfflineIMAP header if the mail server supports the UIDPLUS + extension. * SSL: support subjectAltName. diff --git a/offlineimap/folder/IMAP.py b/offlineimap/folder/IMAP.py index 17b849b..a419664 100644 --- a/offlineimap/folder/IMAP.py +++ b/offlineimap/folder/IMAP.py @@ -274,9 +274,6 @@ class IMAPFolder(BaseFolder): def savemessage_searchforheader(self, imapobj, headername, headervalue): - if imapobj.untagged_responses.has_key('APPENDUID'): - return long(imapobj.untagged_responses['APPENDUID'][-1].split(' ')[1]) - self.ui.debug('imap', 'savemessage_searchforheader called for %s: %s' % \ (headername, headervalue)) # Now find the UID it got. @@ -389,38 +386,42 @@ class IMAPFolder(BaseFolder): This function will update the self.messagelist dict to contain the new message after sucessfully saving it. - :param rtime: A timestamp to be + :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.""" - imapobj = self.imapserver.acquireconnection() self.ui.debug('imap', 'savemessage: called') try: + imapobj = self.imapserver.acquireconnection() + try: - imapobj.select(self.getfullname()) # Needed for search + imapobj.select(self.getfullname()) # Needed for search and making the box READ-WRITE except imapobj.readonly: + # readonly exception. Return original uid to notify that + # we did not save the message. (see savemessage in Base.py) self.ui.msgtoreadonly(self, uid, content, flags) - # Return indicating message taken, but no UID assigned. - return 0 - + return uid + + # UIDPLUS extension provides us with an APPENDUID response to our append() + use_uidplus = 'UIDPLUS' in imapobj.capabilities + # get the date of the message file, so we can pass it to the server. date = self.getmessageinternaldate(content, rtime) - self.ui.debug('imap', 'savemessage: using date %s' % date) + content = re.sub("(?