/head: changeset 123

- Made folder/Maildir.py/deletemessage() more tolerant if a message
  asked to be deleted already has been.

- In Base.py/copymessageto(), no longer bother calling getmessage()
  unless a folder's storemessages() returns true. This will also help
  with syncing to LocalStatus if the user deleted messages in the
  Maildir since the cachemessagelist() was called.
This commit is contained in:
jgoerzen
2002-07-16 03:26:58 +01:00
parent 09cf911d53
commit d3f86beb9f
9 changed files with 366 additions and 234 deletions

View File

@ -41,6 +41,12 @@ class BaseFolder:
InstanceLimitedThreads."""
raise NotImplementedException
def storesmessages(self):
"""Should be true for any backend that actually saves message bodies.
(Almost all of them). False for the LocalStatus backend. Saves
us from having to slurp up messages just for localstatus purposes."""
return 1
def getvisiblename(self):
return self.name
@ -171,8 +177,19 @@ class BaseFolder:
pass
def copymessageto(self, uid, applyto):
# Sometimes, it could be the case that if a sync takes awhile,
# a message might be deleted from the maildir before it can be
# synced to the status cache. This is only a problem with
# self.getmessage(). So, don't call self.getmessage unless
# really needed.
__main__.ui.copyingmessage(uid, self, applyto)
message = self.getmessage(uid)
message = ''
# If any of the destinations actually stores the message body,
# load it up.
for object in applyto:
if object.storesmessages():
message = self.getmessage(uid)
break
flags = self.getmessageflags(uid)
for object in applyto:
newuid = object.savemessage(uid, message, flags)

View File

@ -29,6 +29,9 @@ class LocalStatusFolder(BaseFolder):
self.filename = os.path.join(root, name)
self.messagelist = None
def storesmessages(self):
return 0
def isnewfolder(self):
return not os.path.exists(self.filename)

View File

@ -66,7 +66,7 @@ class MaildirFolder(BaseFolder):
self.saveuidvalidity(remotefolder.getuidvalidity())
return 1
def cachemessagelist(self):
def _scanfolder(self):
"""Cache the message list. Maildir flags are:
R (replied)
S (seen)
@ -74,7 +74,7 @@ class MaildirFolder(BaseFolder):
D (draft)
F (flagged)
and must occur in ASCII order."""
self.messagelist = {}
retval = {}
files = []
nouidcounter = -1 # Messages without UIDs get
# negative UID numbers.
@ -114,9 +114,13 @@ class MaildirFolder(BaseFolder):
# more robust.
os.unlink(file)
else:
self.messagelist[uid] = {'uid': uid,
'flags': flags,
'filename': file}
retval[uid] = {'uid': uid,
'flags': flags,
'filename': file}
return retval
def cachemessagelist(self):
self.messagelist = self._scanfolder()
def getmessagelist(self):
return self.messagelist
@ -195,6 +199,13 @@ class MaildirFolder(BaseFolder):
if not uid in self.messagelist:
return
filename = self.getmessagelist()[uid]['filename']
os.unlink(filename)
try:
os.unlink(filename)
except IOError:
# Can't find the file -- maybe already deleted?
newmsglist = self._scanfolder()
if uid in newmsglist: # Nope, try new filename.
os.unlink(newmsglist[uid]['filename'])
# Yep -- return.
del(self.messagelist[uid])