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 <Sebastian@SSpaeth.de>
This commit is contained in:
Sebastian Spaeth 2011-08-30 10:43:10 +02:00
parent de537dc09c
commit ff50585007

View File

@ -287,22 +287,24 @@ class MaildirFolder(BaseFolder):
"""Sets the specified message's flags to the given set. """Sets the specified message's flags to the given set.
This function moves the message to the cur or new subdir, This function moves the message to the cur or new subdir,
depending on the Seen flag.""" depending on the 'S'een flag."""
# TODO: This function could be improved to only parse the
# filenames if the flags actually changed.
oldfilename = self.messagelist[uid]['filename'] oldfilename = self.messagelist[uid]['filename']
dir_prefix, filename = os.path.split(oldfilename) dir_prefix, filename = os.path.split(oldfilename)
# If a message has been seen, it goes into 'cur' # If a message has been seen, it goes into 'cur'
dir_prefix = 'cur' if 'S' in flags else 'new' 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): if (newfilename != oldfilename):
try: try:
os.rename(os.path.join(self.getfullname(), oldfilename), os.rename(os.path.join(self.getfullname(), oldfilename),