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:
parent
de537dc09c
commit
ff50585007
@ -287,13 +287,15 @@ 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'
|
||||||
|
|
||||||
|
if flags != self.messagelist[uid]['flags']:
|
||||||
|
# Flags have actually changed, construct new filename
|
||||||
# Strip off existing infostring (preserving small letter flags that
|
# Strip off existing infostring (preserving small letter flags that
|
||||||
# dovecot uses)
|
# dovecot uses)
|
||||||
infomatch = self.flagmatchre.search(filename)
|
infomatch = self.flagmatchre.search(filename)
|
||||||
@ -301,8 +303,8 @@ class MaildirFolder(BaseFolder):
|
|||||||
filename = filename[:-len(infomatch.group())] #strip off
|
filename = filename[:-len(infomatch.group())] #strip off
|
||||||
infostr = '%s2,%s' % (self.infosep, ''.join(sorted(flags)))
|
infostr = '%s2,%s' % (self.infosep, ''.join(sorted(flags)))
|
||||||
filename += infostr
|
filename += infostr
|
||||||
newfilename = os.path.join(dir_prefix, filename)
|
|
||||||
|
|
||||||
|
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),
|
||||||
|
Loading…
Reference in New Issue
Block a user