/head: changeset 104

Updated with a fix for when an IMAP server does not return message
data from a STORE
This commit is contained in:
jgoerzen 2002-07-12 00:35:51 +01:00
parent c9ecc54b03
commit 817a10ce0f

View File

@ -20,6 +20,7 @@ from Base import BaseFolder
from offlineimap import imaputil, imaplib from offlineimap import imaputil, imaplib
import rfc822 import rfc822
from StringIO import StringIO from StringIO import StringIO
from copy import copy
class IMAPFolder(BaseFolder): class IMAPFolder(BaseFolder):
def __init__(self, imapserver, name, visiblename, accountname): def __init__(self, imapserver, name, visiblename, accountname):
@ -139,16 +140,30 @@ class IMAPFolder(BaseFolder):
r = imapobj.uid('store', r = imapobj.uid('store',
','.join([str(uid) for uid in uidlist]), ','.join([str(uid) for uid in uidlist]),
'+FLAGS', '+FLAGS',
imaputil.flagsmaildir2imap(flags))[1] imaputil.flagsmaildir2imap(flags))
assert r[0] == 'OK', 'Error with store: ' + r[1]
r = r[1]
finally: finally:
self.imapserver.releaseconnection(imapobj) self.imapserver.releaseconnection(imapobj)
resultcount = 0 # Some IMAP servers do not always return a result. Therefore,
# only update the ones that it talks about, and manually fix
# the others.
needupdate = copy(uidlist)
for result in r: for result in r:
resultcount += 1 if result == None:
continue
flags = imaputil.flags2hash(imaputil.imapsplit(result)[1])['FLAGS'] flags = imaputil.flags2hash(imaputil.imapsplit(result)[1])['FLAGS']
uid = long(imaputil.flags2hash(imaputil.imapsplit(result)[1])['UID']) uid = long(imaputil.flags2hash(imaputil.imapsplit(result)[1])['UID'])
self.messagelist[uid]['flags'] = imaputil.flagsimap2maildir(flags) self.messagelist[uid]['flags'] = imaputil.flagsimap2maildir(flags)
assert resultcount == len(uidlist), "Got incorrect number of results back" try:
needupdate.remove(uid)
except ValueError: # Let it slide if it's not in the list
pass
for uid in needupdate:
for flag in flags:
if not flag in self.messagelist[uid]['flags']:
self.messagelist[uid]['flags'].append(flag)
self.messagelist[uid]['flags'].sort()
def deletemessage(self, uid): def deletemessage(self, uid):
self.deletemessages([uid]) self.deletemessages([uid])
@ -167,6 +182,6 @@ class IMAPFolder(BaseFolder):
finally: finally:
self.imapserver.releaseconnection(imapobj) self.imapserver.releaseconnection(imapobj)
for uid in uidlist: for uid in uidlist:
del(self.messagelist[uid]) del self.messagelist[uid]