/offlineimap/head: changeset 131

Fixed problems when a UID is not forthcoming from a server after
uploading a message.
This commit is contained in:
jgoerzen
2002-07-18 01:51:03 +01:00
parent 035fa2a96e
commit 7880564520
4 changed files with 47 additions and 11 deletions

View File

@ -94,6 +94,10 @@ class BaseFolder:
If the backend cannot assign a new uid, it returns the uid passed in
WITHOUT saving the message.
If the backend CAN assign a new uid, but cannot find out what this UID
is (as is the case with many IMAP servers), it returns 0 but DOES save
the message.
IMAP backend should be the only one that can assign a new uid.
@ -160,18 +164,20 @@ class BaseFolder:
flags = self.getmessageflags(uid)
for tryappend in applyto:
successuid = tryappend.savemessage(uid, message, flags)
if successuid > 0:
if successuid >= 0:
successobject = tryappend
break
# Did we succeed?
if successobject != None:
# Copy the message to the other remote servers.
for appendserver in [x for x in applyto if x != successobject]:
appendserver.savemessage(successuid, message, flags)
# Copy it to its new name on the local server and delete
# the one without a UID.
self.savemessage(successuid, message, flags)
self.deletemessage(uid)
if successuid: # Only if IMAP actually assigned a UID
# Copy the message to the other remote servers.
for appendserver in \
[x for x in applyto if x != successobject]:
appendserver.savemessage(successuid, message, flags)
# Copy to its new name on the local server and delete
# the one without a UID.
self.savemessage(successuid, message, flags)
self.deletemessage(uid) # It'll be re-downloaded.
else:
# Did not find any server to take this message. Ignore.
pass

View File

@ -22,6 +22,8 @@ import rfc822
from StringIO import StringIO
from copy import copy
import __main__
class IMAPFolder(BaseFolder):
def __init__(self, imapserver, name, visiblename, accountname):
self.name = imaputil.dequote(name)
@ -114,11 +116,20 @@ class IMAPFolder(BaseFolder):
# Checkpoint. Let it write out the messages, etc.
assert(imapobj.check()[0] == 'OK')
# Now find the UID it got.
matchinguids = imapobj.uid('search', None,
'(HEADER Message-Id %s)' % mid)[1][0]
try:
matchinguids = imapobj.uid('search', None,
'(HEADER Message-Id %s)' % mid)[1][0]
except imapobj.error:
# IMAP server doesn't implement search or had a problem.
return 0
matchinguids = matchinguids.split(' ')
if len(matchinguids) != 1 or matchinguids[0] == None:
return 0
matchinguids.sort()
uid = long(matchinguids[-1])
try:
uid = long(matchinguids[-1])
except ValueError:
return 0
self.messagelist[uid] = {'uid': uid, 'flags': flags}
return uid
finally: