diff --git a/offlineimap.conf b/offlineimap.conf index 6d01fe7..7e257c7 100644 --- a/offlineimap.conf +++ b/offlineimap.conf @@ -320,6 +320,9 @@ remoterepository = RemoteExample # # The pre sync script has to complete before a sync to the account will start. # +# The environment variable OFFLINEIMAPSYNCMODE will be set to either full, +# quick or idle to communicate the syncmode to the external command. +# #presynchook = imapfilter -c someotherconfig.lua #postsynchook = notifysync.sh diff --git a/offlineimap/accounts.py b/offlineimap/accounts.py index 4cb15ab..86e5b88 100644 --- a/offlineimap/accounts.py +++ b/offlineimap/accounts.py @@ -338,18 +338,6 @@ class SyncableAccount(Account): folderthreads = [] - hook = self.getconf('presynchook', '') - self.callhook(hook) - - if self.utf_8_support and self.remoterepos.getdecodefoldernames(): - raise OfflineImapError("Configuration mismatch in account " + - "'%s'. " % self.getname() + - "\nAccount setting 'utf8foldernames' and repository " + - "setting 'decodefoldernames'\nmay not be used at the " + - "same time. This account has not been synchronized.\n" + - "Please check the configuration and documentation.", - OfflineImapError.ERROR.REPO) - quickconfig = self.getconfint('quick', 0) if quickconfig < 0: quick = True @@ -363,6 +351,19 @@ class SyncableAccount(Account): else: quick = False + + hook = self.getconf('presynchook', '') + self.callhook(hook, "quick" if quick else "full") + + if self.utf_8_support and self.remoterepos.getdecodefoldernames(): + raise OfflineImapError("Configuration mismatch in account " + + "'%s'. " % self.getname() + + "\nAccount setting 'utf8foldernames' and repository " + + "setting 'decodefoldernames'\nmay not be used at the " + + "same time. This account has not been synchronized.\n" + + "Please check the configuration and documentation.", + OfflineImapError.ERROR.REPO) + try: startedThread = False remoterepos = self.remoterepos @@ -444,9 +445,9 @@ class SyncableAccount(Account): remoterepos.holdordropconnections() hook = self.getconf('postsynchook', '') - self.callhook(hook) + self.callhook(hook, "quick" if quick else "full") - def callhook(self, cmd): + def callhook(self, cmd, syncmode): # Check for CTRL-C or SIGTERM and run postsynchook. if Account.abort_NOW_signal.is_set(): return @@ -456,9 +457,11 @@ class SyncableAccount(Account): self.ui.callhook("Calling hook: " + cmd) if self.dryrun: return + environ = os.environ.copy() + environ['OFFLINEIMAPSYNCMODE'] = syncmode p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, - close_fds=True) + close_fds=True, env=environ) stdout, stderr = p.communicate() self.ui.callhook("Hook stdout: %s\nHook stderr:%s\n" % (stdout.decode('utf-8'), stderr.decode('utf-8'))) diff --git a/offlineimap/imapserver.py b/offlineimap/imapserver.py index 1239f46..bc2ab5f 100644 --- a/offlineimap/imapserver.py +++ b/offlineimap/imapserver.py @@ -838,10 +838,10 @@ class IdleThread: remotefolder = remoterepos.getfolder(self.folder, decode=False) hook = account.getconf('presynchook', '') - account.callhook(hook) + account.callhook(hook, "idle") offlineimap.accounts.syncfolder(account, remotefolder, quick=False) hook = account.getconf('postsynchook', '') - account.callhook(hook) + account.callhook(hook, "idle") ui = getglobalui() ui.unregisterthread(currentThread()) # syncfolder registered the thread