New restoreatime patch

From: Ben Kibbey <bjk@luxsci.net>

Attached is a patch to restore the atime of Maildir folders after
syncing. It can be enabled via the 'restoreatime' boolean in the
configuration file. I needed this because offlineimap is run after a
fetchmail and my mail checker breaks.
This commit is contained in:
John Goerzen 2006-03-02 00:12:29 +01:00
parent fabbf81c1a
commit 405275f541
2 changed files with 27 additions and 0 deletions

View File

@ -154,6 +154,12 @@ class AccountSynchronizationMixin:
class SyncableAccount(Account, AccountSynchronizationMixin): class SyncableAccount(Account, AccountSynchronizationMixin):
pass pass
from stat import *
def reset_time(folder, atime, mtime):
t = atime, mtime
os.utime(folder, t)
def syncfolder(accountname, remoterepos, remotefolder, localrepos, def syncfolder(accountname, remoterepos, remotefolder, localrepos,
statusrepos): statusrepos):
global mailboxes global mailboxes
@ -163,6 +169,9 @@ def syncfolder(accountname, remoterepos, remotefolder, localrepos,
localfolder = localrepos.\ localfolder = localrepos.\
getfolder(remotefolder.getvisiblename().\ getfolder(remotefolder.getvisiblename().\
replace(remoterepos.getsep(), localrepos.getsep())) replace(remoterepos.getsep(), localrepos.getsep()))
if localrepos.getrestoreatime():
cur_atime = os.stat(localfolder.getfullname() + "/cur")[ST_ATIME]
new_atime = os.stat(localfolder.getfullname() + "/new")[ST_ATIME]
# Write the mailboxes # Write the mailboxes
mbnames.add(accountname, localfolder.getvisiblename()) mbnames.add(accountname, localfolder.getvisiblename())
# Load local folder # Load local folder
@ -191,10 +200,20 @@ def syncfolder(accountname, remoterepos, remotefolder, localrepos,
if not localfolder.isuidvalidityok(): if not localfolder.isuidvalidityok():
ui.validityproblem(localfolder, localfolder.getsaveduidvalidity(), ui.validityproblem(localfolder, localfolder.getsaveduidvalidity(),
localfolder.getuidvalidity()) localfolder.getuidvalidity())
if localrepos.getrestoreatime():
reset_time(localfolder.getfullname() + "/new", new_atime, \
os.stat(localfolder.getfullname() + "/new")[ST_MTIME])
reset_time(localfolder.getfullname() + "/cur", new_atime, \
os.stat(localfolder.getfullname() + "/cur")[ST_MTIME])
return return
if not remotefolder.isuidvalidityok(): if not remotefolder.isuidvalidityok():
ui.validityproblem(remotefolder, remotefolder.getsaveduidvalidity(), ui.validityproblem(remotefolder, remotefolder.getsaveduidvalidity(),
remotefolder.getuidvalidity()) remotefolder.getuidvalidity())
if localrepos.getrestoreatime():
reset_time(localfolder.getfullname() + "/new", new_atime, \
os.stat(localfolder.getfullname() + "/new")[ST_MTIME])
reset_time(localfolder.getfullname() + "/cur", new_atime, \
os.stat(localfolder.getfullname() + "/cur")[ST_MTIME])
return return
else: else:
localfolder.saveuidvalidity() localfolder.saveuidvalidity()
@ -230,4 +249,9 @@ def syncfolder(accountname, remoterepos, remotefolder, localrepos,
ui.syncingmessages(localrepos, localfolder, statusrepos, statusfolder) ui.syncingmessages(localrepos, localfolder, statusrepos, statusfolder)
localfolder.syncmessagesto(statusfolder) localfolder.syncmessagesto(statusfolder)
statusfolder.save() statusfolder.save()
if localrepos.getrestoreatime():
reset_time(localfolder.getfullname() + "/new", new_atime, \
os.stat(localfolder.getfullname() + "/new")[ST_MTIME])
reset_time(localfolder.getfullname() + "/cur", new_atime, \
os.stat(localfolder.getfullname() + "/cur")[ST_MTIME])

View File

@ -33,6 +33,9 @@ class MaildirRepository(BaseRepository):
self.ui = UIBase.getglobalui() self.ui = UIBase.getglobalui()
self.debug("MaildirRepository initialized, sep is " + repr(self.getsep())) self.debug("MaildirRepository initialized, sep is " + repr(self.getsep()))
def getrestoreatime(self):
return self.getconfboolean('restoreatime', 0)
def getlocalroot(self): def getlocalroot(self):
return os.path.expanduser(self.getconf('localfolders')) return os.path.expanduser(self.getconf('localfolders'))