diff --git a/offlineimap/accounts.py b/offlineimap/accounts.py index b367de1..5478fe7 100644 --- a/offlineimap/accounts.py +++ b/offlineimap/accounts.py @@ -191,10 +191,12 @@ def syncfolder(accountname, remoterepos, remotefolder, localrepos, if not localfolder.isuidvalidityok(): ui.validityproblem(localfolder, localfolder.getsaveduidvalidity(), localfolder.getuidvalidity()) + localrepos.restore_atime() return if not remotefolder.isuidvalidityok(): ui.validityproblem(remotefolder, remotefolder.getsaveduidvalidity(), remotefolder.getuidvalidity()) + localrepos.restore_atime() return else: localfolder.saveuidvalidity() @@ -230,4 +232,5 @@ def syncfolder(accountname, remoterepos, remotefolder, localrepos, ui.syncingmessages(localrepos, localfolder, statusrepos, statusfolder) localfolder.syncmessagesto(statusfolder) statusfolder.save() + localrepos.restore_atime() diff --git a/offlineimap/repository/Base.py b/offlineimap/repository/Base.py index 945183f..94bce09 100644 --- a/offlineimap/repository/Base.py +++ b/offlineimap/repository/Base.py @@ -51,6 +51,18 @@ class BaseRepository(CustomConfig.ConfigHelperMixin): if not os.path.exists(self.uiddir): os.mkdir(self.uiddir, 0700) + # The 'restoreatime' config parameter only applies to local Maildir + # mailboxes. + def restore_atime(self): + if self.config.get('Repository ' + self.name, 'type').strip() != \ + 'Maildir': + return + + if not self.config.has_option('Repository ' + self.name, 'restoreatime') or not self.config.getboolean('Repository ' + self.name, 'restoreatime'): + return + + return self.restore_folder_atimes() + def holdordropconnections(self): pass diff --git a/offlineimap/repository/Maildir.py b/offlineimap/repository/Maildir.py index fc92bc4..bb011d5 100644 --- a/offlineimap/repository/Maildir.py +++ b/offlineimap/repository/Maildir.py @@ -21,6 +21,7 @@ from offlineimap import folder, imaputil from offlineimap.ui import UIBase from mailbox import Maildir import os +from stat import * class MaildirRepository(BaseRepository): def __init__(self, reposname, account): @@ -32,6 +33,24 @@ class MaildirRepository(BaseRepository): self.folders = None self.ui = UIBase.getglobalui() self.debug("MaildirRepository initialized, sep is " + repr(self.getsep())) + self.folder_atimes = [] + + def _append_folder_atimes(self, foldername): + p = os.path.join(self.root, foldername) + new = os.path.join(p, 'new') + cur = os.path.join(p, 'cur') + f = p, os.stat(new)[ST_ATIME], os.stat(cur)[ST_ATIME] + self.folder_atimes.append(f) + + def restore_folder_atimes(self): + if not self.folder_atimes: + return + + for f in self.folder_atimes: + t = f[1], os.stat(os.path.join(f[0], 'new'))[ST_MTIME] + os.utime(os.path.join(f[0], 'new'), t) + t = f[2], os.stat(os.path.join(f[0], 'cur'))[ST_MTIME] + os.utime(os.path.join(f[0], 'cur'), t) def getlocalroot(self): return os.path.expanduser(self.getconf('localfolders')) @@ -86,6 +105,8 @@ class MaildirRepository(BaseRepository): self.ui.warn("NOT YET IMPLEMENTED: DELETE FOLDER %s" % foldername) def getfolder(self, foldername): + if self.config.has_option('Repository ' + self.name, 'restoreatime') and self.config.getboolean('Repository ' + self.name, 'restoreatime'): + self._append_folder_atimes(foldername) return folder.Maildir.MaildirFolder(self.root, foldername, self.getsep(), self, self.accountname) @@ -130,6 +151,8 @@ class MaildirRepository(BaseRepository): self.debug(" foldername = %s" % foldername) + if self.config.has_option('Repository ' + self.name, 'restoreatime') and self.config.getboolean('Repository ' + self.name, 'restoreatime'): + self._append_folder_atimes(foldername) retval.append(folder.Maildir.MaildirFolder(self.root, foldername, self.getsep(), self, self.accountname)) if self.getsep() == '/' and dirname != '.':