From c094304f937e13e80ce464ff7819affd39d298cc Mon Sep 17 00:00:00 2001 From: Abdo Roig-Maranges Date: Fri, 3 Apr 2015 03:29:36 +0200 Subject: [PATCH] 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 Signed-off-by: Nicolas Sebrecht --- offlineimap/folder/GmailMaildir.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/offlineimap/folder/GmailMaildir.py b/offlineimap/folder/GmailMaildir.py index 894792d..a8b607a 100644 --- a/offlineimap/folder/GmailMaildir.py +++ b/offlineimap/folder/GmailMaildir.py @@ -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)