From ff50585007759b9dfe480ddbbf7a214010c3ce4f Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Tue, 30 Aug 2011 10:43:10 +0200 Subject: [PATCH] Folder-Maildir.savemessageflags(): Only parse file name if flags changed Rather than always parsing the filename, we only need to do so if the flags have actually changed, otherwise we can keep the filename. Signed-off-by: Sebastian Spaeth --- offlineimap/folder/Maildir.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/offlineimap/folder/Maildir.py b/offlineimap/folder/Maildir.py index 22a5ef4..d7639f4 100644 --- a/offlineimap/folder/Maildir.py +++ b/offlineimap/folder/Maildir.py @@ -287,22 +287,24 @@ class MaildirFolder(BaseFolder): """Sets the specified message's flags to the given set. This function moves the message to the cur or new subdir, - depending on the Seen flag.""" - # TODO: This function could be improved to only parse the - # filenames if the flags actually changed. + depending on the 'S'een flag.""" + oldfilename = self.messagelist[uid]['filename'] dir_prefix, filename = os.path.split(oldfilename) # If a message has been seen, it goes into 'cur' dir_prefix = 'cur' if 'S' in flags else 'new' - # Strip off existing infostring (preserving small letter flags that - # dovecot uses) - infomatch = self.flagmatchre.search(filename) - if infomatch: - filename = filename[:-len(infomatch.group())] #strip off - infostr = '%s2,%s' % (self.infosep, ''.join(sorted(flags))) - filename += infostr - newfilename = os.path.join(dir_prefix, filename) + if flags != self.messagelist[uid]['flags']: + # Flags have actually changed, construct new filename + # Strip off existing infostring (preserving small letter flags that + # dovecot uses) + infomatch = self.flagmatchre.search(filename) + if infomatch: + filename = filename[:-len(infomatch.group())] #strip off + infostr = '%s2,%s' % (self.infosep, ''.join(sorted(flags))) + filename += infostr + + newfilename = os.path.join(dir_prefix, filename) if (newfilename != oldfilename): try: os.rename(os.path.join(self.getfullname(), oldfilename),