/head: changeset 54
First stab at optimization of message deletion
This commit is contained in:
parent
7c838a4873
commit
11ce82668c
@ -97,6 +97,10 @@ class BaseFolder:
|
||||
newflags.sort()
|
||||
self.savemessageflags(uid, newflags)
|
||||
|
||||
def addmessagesflags(self, uidlist, flags):
|
||||
for uid in uidlist:
|
||||
self.addmessageflags(uid)
|
||||
|
||||
def deletemessageflags(self, uid, flags):
|
||||
"""Removes each flag given from the message's flag set. If a given
|
||||
flag is already removed, no action will be taken for that flag."""
|
||||
@ -174,13 +178,16 @@ class BaseFolder:
|
||||
|
||||
Look for message present in dest but not in self.
|
||||
If any, delete them."""
|
||||
deletelist = []
|
||||
for uid in dest.getmessagelist().keys():
|
||||
if uid < 0:
|
||||
continue
|
||||
if not uid in self.getmessagelist():
|
||||
__main__.ui.deletingmessage(uid, applyto)
|
||||
deletelist.append(uid)
|
||||
if len(deletelist):
|
||||
__main__.ui.deletingmessages(uidlist, applyto)
|
||||
for object in applyto:
|
||||
object.deletemessage(uid)
|
||||
object.deletemessages(uidlist)
|
||||
|
||||
def syncmessagesto_flags(self, dest, applyto):
|
||||
"""Pass 4 of folder synchronization.
|
||||
|
@ -102,12 +102,32 @@ class IMAPFolder(BaseFolder):
|
||||
flags = imaputil.flags2hash(imaputil.imapsplit(result)[1])['FLAGS']
|
||||
self.messagelist[uid]['flags'] = imaputil.flagsimap2maildir(flags)
|
||||
|
||||
def addmessagesflags(self, uidlist, flags):
|
||||
assert(self.imapobj.select(self.getfullname())[0] == 'OK')
|
||||
r = self.imapobj.uid('store',
|
||||
','.join([str(uid) for uid in uidlist]),
|
||||
'+FLAGS',
|
||||
imaputil.flagsmaildir2imap(flags))[1]
|
||||
resultcount = 0
|
||||
for result in r:
|
||||
resultcount += 1
|
||||
flags = imaputil.flags2hash(imaputil.imapsplit(result)[1])['FLAGS']
|
||||
self.messagelist[uid]['flags'] = imaputil.flagsimap2maildir(flags)
|
||||
assert resultcount == len(uidlist), "Got incorrect number of results back"
|
||||
|
||||
def deletemessage(self, uid):
|
||||
if not uid in self.messagelist:
|
||||
self.deletemessages([uid])
|
||||
|
||||
def deletemessage(self, uidlist):
|
||||
# Weed out ones not in self.messagelist
|
||||
uidlist = [uid for uid in uidlist if uid in self.messagelist]
|
||||
if not len(uidlist):
|
||||
return
|
||||
self.addmessageflags(uid, ['T'])
|
||||
|
||||
self.addmessagesflags(uidlist, ['T'])
|
||||
assert(self.imapobj.select(self.getfullname())[0] == 'OK')
|
||||
assert(self.imapobj.expunge()[0] == 'OK')
|
||||
for uid in uidlist:
|
||||
del(self.messagelist[uid])
|
||||
|
||||
|
||||
|
@ -91,6 +91,13 @@ class UIBase:
|
||||
ds = s.folderlist(destlist)
|
||||
s._msg("Deleting message %d in %s" % (uid, ds))
|
||||
|
||||
def deletingmessages(s, uidlist, destlist):
|
||||
ds = s.folderlist(destlist)
|
||||
s._msg("Deleting %d messages (%s) in %s" % \
|
||||
(len(uidlist),
|
||||
", ".join([str(u) for u in uidlist]),
|
||||
ds))
|
||||
|
||||
def addingflags(s, uid, flags, destlist):
|
||||
ds = s.folderlist(destlist)
|
||||
s._msg("Adding flags %s to message %d on %s" % \
|
||||
|
Loading…
Reference in New Issue
Block a user