Implement change_message_uid

Previously, assigning a new UID to a mapped IMAP or Maildir repository
was done by loading the "local" item, saving it under a new UID and
deleting the old one. This involved lots of disk activity for nothing
more than an effective file rename in Maildirs, and lots of network
usage in the MappedUID cases.

We do this on every upload from a local to a remote item, so that can
potentially be quite expensive. This patch lets backends that support it
(Maildir, MappedUID) efficiently rename the file rather than having to
read the mail content, write it out as a new file and delete the old
file. This speeds up uploads from Maildir and the MappedUID server.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
This commit is contained in:
Sebastian Spaeth
2011-08-30 10:52:11 +02:00
parent 09ce56c594
commit de537dc09c
5 changed files with 93 additions and 37 deletions

View File

@ -597,8 +597,8 @@ class IMAPFolder(BaseFolder):
self.ui.debug('imap', 'savemessage: returning new UID %d' % uid)
return uid
def savemessageflags(self, uid, flags):
"""Change a message's flags to `flags`."""
imapobj = self.imapserver.acquireconnection()
try:
try:
@ -684,6 +684,14 @@ class IMAPFolder(BaseFolder):
elif operation == '-':
self.messagelist[uid]['flags'] -= flags
def change_message_uid(self, uid, new_uid):
"""Change the message from existing uid to new_uid
If the backend supports it. IMAP does not and will throw errors."""
raise OfflineImapError('IMAP backend cannot change a messages UID from '
'%d to %d' % (uid, new_uid),
OfflineImapError.ERROR.MESSAGE)
def deletemessage(self, uid):
self.deletemessages_noconvert([uid])