make savemessagelabels honor utime_from_header

Previously, syncing labels on a message always resulted in updating the
file modification time, even with utime_from_headers=true

This patch restores the file mtime to the previous value when
utime_from_headers=true, preventing a label synchronization from
breaking the promise that the file mtimes coincide with the header date.

Signed-off-by: Abdo Roig-Maranges <abdo.roig@gmail.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
Abdo Roig-Maranges 2015-04-03 03:29:36 +02:00 committed by Nicolas Sebrecht
parent d52b1de3d0
commit c094304f93

View File

@ -159,7 +159,7 @@ class GmailMaildirFolder(MaildirFolder):
content = self.deletemessageheaders(content, self.labelsheader)
content = self.addmessageheader(content, '\n', self.labelsheader, labels_str)
rtime = self.messagelist[uid].get('rtime', None)
mtime = long(os.stat(filepath).st_mtime)
# write file with new labels to a unique file in tmp
messagename = self.new_message_filename(uid, set())
@ -174,8 +174,9 @@ class GmailMaildirFolder(MaildirFolder):
(tmppath, filepath, e[1]), OfflineImapError.ERROR.FOLDER), \
None, exc_info()[2]
if rtime != None:
os.utime(filepath, (rtime, rtime))
# if utime_from_header=true, we don't want to change the mtime.
if self.utime_from_header and mtime:
os.utime(filepath, (mtime, mtime))
# save the new mtime and labels
self.messagelist[uid]['mtime'] = long(os.stat(filepath).st_mtime)