/head: changeset 24

Updated so savemessage can take flags
This commit is contained in:
jgoerzen 2002-06-21 02:12:52 +01:00
parent 3aa11b5aec
commit 9c4af270cb
2 changed files with 12 additions and 11 deletions

View File

@ -59,15 +59,17 @@ class BaseFolder:
"""Returns the content of the specified message.""" """Returns the content of the specified message."""
raise NotImplementedException raise NotImplementedException
def savemessage(self, uid, content): def savemessage(self, uid, content, flags):
"""Writes a new message, with the specified uid. """Writes a new message, with the specified uid.
If the uid is < 0, the backend should assign a new uid and return it. If the uid is < 0, the backend should assign a new uid and return it.
If the backend cannot assign a new uid, it returns the uid passed in.
If the backend cannot assign a new uid, it returns the uid passed in
WITHOUT saving the message.
IMAP backend should be the only one that can assign a new uid. IMAP backend should be the only one that can assign a new uid.
If the uid is < 0 and the backend cannot assign a new UID, it is
required to TAKE NO ACTION other than returning the uid passed in.
If the uid is > 0, the backend should set the uid to this, if it can. If the uid is > 0, the backend should set the uid to this, if it can.
If it cannot set the uid to that, it will save it anyway.
It will return the uid assigned in any case. It will return the uid assigned in any case.
""" """
raise NotImplementedException raise NotImplementedException
@ -125,21 +127,18 @@ class BaseFolder:
message = self.getmessage(uid) message = self.getmessage(uid)
flags = self.getmessageflags(uid) flags = self.getmessageflags(uid)
for tryappend in applyto: for tryappend in applyto:
successuid = tryappend.savemessage(uid, message) successuid = tryappend.savemessage(uid, message, flags)
if successuid > 0: if successuid > 0:
tryappend.savemessageflags(uid, flags)
successobject = tryappend successobject = tryappend
break break
# Did we succeed? # Did we succeed?
if successobject != None: if successobject != None:
# Copy the message to the other remote servers. # Copy the message to the other remote servers.
for appendserver in [x for x in applyto if x != successobject]: for appendserver in [x for x in applyto if x != successobject]:
appendserver.savemessage(successuid, message) appendserver.savemessage(successuid, message, flags)
appendserver.savemessageflags(successuid, flags)
# Copy it to its new name on the local server and delete # Copy it to its new name on the local server and delete
# the one without a UID. # the one without a UID.
self.savemessage(successuid, message) self.savemessage(successuid, message, flags)
self.savemessageflags(successuid, flags)
self.deletemessage(uid) self.deletemessage(uid)
else: else:
# Did not find any server to take this message. Delete # Did not find any server to take this message. Delete

View File

@ -95,12 +95,13 @@ class MaildirFolder(BaseFolder):
file.close() file.close()
return retval return retval
def savemessage(self, uid, content): def savemessage(self, uid, content, flags):
if uid < 0: if uid < 0:
# We cannot assign a new uid. # We cannot assign a new uid.
return uid return uid
if uid in self.getmessagelist(): if uid in self.getmessagelist():
# We already have it. # We already have it.
self.savemessageflags(uid, flags)
return uid return uid
newdir = os.path.join(self.getfullname(), 'new') newdir = os.path.join(self.getfullname(), 'new')
tmpdir = os.path.join(self.getfullname(), 'tmp') tmpdir = os.path.join(self.getfullname(), 'tmp')
@ -127,6 +128,7 @@ class MaildirFolder(BaseFolder):
os.unlink(os.path.join(tmpdir, messagename)) os.unlink(os.path.join(tmpdir, messagename))
self.messagelist[uid] = {'uid': uid, 'flags': [], self.messagelist[uid] = {'uid': uid, 'flags': [],
'filename': os.path.join(newdir, messagename)} 'filename': os.path.join(newdir, messagename)}
self.savemessageflags(uid, flags)
return uid return uid
def getmessageflags(self, uid): def getmessageflags(self, uid):