]> code.delx.au - offlineimap/blobdiff - offlineimap/accounts.py
New option to only work with subscribed folders
[offlineimap] / offlineimap / accounts.py
index 8e96347944f58c37fcada83fd98fb18dca16e23a..36a7665bcfdadb3cfa6dca7d0f7f70ac039804ca 100644 (file)
@@ -21,6 +21,7 @@ from offlineimap.ui import UIBase
 from offlineimap.threadutil import InstanceLimitedThread, ExitNotifyThread
 from threading import Event
 import os
+from subprocess import Popen, PIPE
 
 def getaccountlist(customconfig):
     return customconfig.getsectionlist('Account')
@@ -83,16 +84,10 @@ class Account(CustomConfig.ConfigHelperMixin):
         
         refreshperiod = int(self.refreshperiod * 60)
         sleepresult = self.ui.sleep(refreshperiod)
-        if sleepresult == 2:
-            # Cancel keep-alive, but don't bother terminating threads
-            for item in kaobjs:
-                item.stopkeepalive(abrupt = 1)
-            return sleepresult
-        else:
-            # Cancel keep-alive and wait for thread to terminate.
-            for item in kaobjs:
-                item.stopkeepalive(abrupt = 0)
-            return sleepresult
+        # Cancel keepalive
+        for item in kaobjs:
+            item.stopkeepalive()
+        return sleepresult
             
 class AccountSynchronizationMixin:
     def syncrunner(self):
@@ -127,6 +122,9 @@ class AccountSynchronizationMixin:
         # We don't need an account lock because syncitall() goes through
         # each account once, then waits for all to finish.
 
+        hook = self.getconf('presynchook', '')
+        self.callhook(hook)
+
         quickconfig = self.getconfint('quick', 0)
         if quickconfig < 0:
             quick = True
@@ -167,6 +165,23 @@ class AccountSynchronizationMixin:
             remoterepos.holdordropconnections()
         finally:
             pass
+
+        hook = self.getconf('postsynchook', '')
+        self.callhook(hook)
+
+    def callhook(self, cmd):
+        if not cmd:
+            return
+        try:
+            self.ui.callhook("Calling hook: " + cmd)
+            p = Popen(cmd, shell=True,
+                      stdin=PIPE, stdout=PIPE, stderr=PIPE,
+                      close_fds=True)
+            r = p.communicate()
+            self.ui.callhook("Hook stdout: %s\nHook stderr:%s\n" % r)
+            self.ui.callhook("Hook return code: %d" % p.returncode)
+        except:
+            self.ui.warn("Exception occured while calling hook")
     
 class SyncableAccount(Account, AccountSynchronizationMixin):
     pass