[PATCH] make savemessagelabels honor utime_from_header

Abdo Roig-Maranges abdo.roig at gmail.com
Fri Apr 3 02:29:36 BST 2015


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 at gmail.com>
---
 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)
-- 
2.3.5





More information about the OfflineIMAP-project mailing list