Sync INTERNALDATE <-> mtime

The attached patch adds syncing the INTERNALDATE of IMAP folders with
the mtime of messages in maildir folders.
I want this to happen, because I'm running a dovecot over the maildirs
synced by offlineimap, and that uses the mtime as the INTERNALDATE.
When using mutt to view messages I generally sort based on the received
date, which for IMAP folders is the INTERNALDATE.

Since this is the first real coding I've done in Python the patch may
need to be cleaned up some, but it's working pretty well for me.  I've
added new messages to each side, and the received date has been
preserved going both ways.
This commit is contained in:
John Goerzen
2006-08-22 02:09:36 +01:00
parent e4db4200a2
commit 03488ba81b
6 changed files with 56 additions and 23 deletions

View File

@ -133,7 +133,7 @@ class BaseFolder:
"""Returns the content of the specified message."""
raise NotImplementedException
def savemessage(self, uid, content, flags):
def savemessage(self, uid, content, flags, rtime):
"""Writes a new message, with the specified uid.
If the uid is < 0, the backend should assign a new uid and return it.
@ -152,6 +152,10 @@ class BaseFolder:
"""
raise NotImplementedException
def getmessagetime(self, uid):
"""Return the received time for the specified message."""
raise NotImplementedException
def getmessageflags(self, uid):
"""Returns the flags for the specified message."""
raise NotImplementedException
@ -203,8 +207,9 @@ class BaseFolder:
successuid = None
message = self.getmessage(uid)
flags = self.getmessageflags(uid)
rtime = self.getmessagetime(uid)
for tryappend in applyto:
successuid = tryappend.savemessage(uid, message, flags)
successuid = tryappend.savemessage(uid, message, flags, rtime)
if successuid >= 0:
successobject = tryappend
break
@ -214,10 +219,10 @@ class BaseFolder:
# Copy the message to the other remote servers.
for appendserver in \
[x for x in applyto if x != successobject]:
appendserver.savemessage(successuid, message, flags)
appendserver.savemessage(successuid, message, flags, rtime)
# Copy to its new name on the local server and delete
# the one without a UID.
self.savemessage(successuid, message, flags)
self.savemessage(successuid, message, flags, rtime)
self.deletemessage(uid) # It'll be re-downloaded.
else:
# Did not find any server to take this message. Ignore.
@ -272,11 +277,12 @@ class BaseFolder:
message = self.getmessage(uid)
break
flags = self.getmessageflags(uid)
rtime = self.getmessagetime(uid)
for object in applyto:
newuid = object.savemessage(uid, message, flags)
newuid = object.savemessage(uid, message, flags, rtime)
if newuid > 0 and newuid != uid:
# Change the local uid.
self.savemessage(newuid, message, flags)
self.savemessage(newuid, message, flags, rtime)
self.deletemessage(uid)
uid = newuid