diff --git a/offlineimap/accounts.py b/offlineimap/accounts.py
index 8e96347..631771d 100644
--- a/offlineimap/accounts.py
+++ b/offlineimap/accounts.py
@@ -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')
@@ -127,6 +128,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 +171,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
diff --git a/offlineimap/ui/Blinkenlights.py b/offlineimap/ui/Blinkenlights.py
index 6982351..577f601 100644
--- a/offlineimap/ui/Blinkenlights.py
+++ b/offlineimap/ui/Blinkenlights.py
@@ -127,6 +127,10 @@ class BlinkenBase:
             return tf
         finally:
             s.tflock.release()
+
+    def callhook(s, msg):
+        s.gettf().setcolor('white')
+        s.__class__.__bases__[-1].callhook(s, msg)
             
     def sleep(s, sleepsecs):
         s.gettf().setcolor('red')
diff --git a/offlineimap/ui/Machine.py b/offlineimap/ui/Machine.py
index d02bbbc..0a07e3e 100644
--- a/offlineimap/ui/Machine.py
+++ b/offlineimap/ui/Machine.py
@@ -175,3 +175,5 @@ class MachineUI(UIBase):
     def init_banner(s):
         s._printData('initbanner', offlineimap.version.banner)
 
+    def callhook(s, msg):
+        s._printData('callhook', msg)
diff --git a/offlineimap/ui/UIBase.py b/offlineimap/ui/UIBase.py
index d0e92e6..ffdbc78 100644
--- a/offlineimap/ui/UIBase.py
+++ b/offlineimap/ui/UIBase.py
@@ -322,6 +322,12 @@ class UIBase:
         s.delThreadDebugLog(thread)
         s.unregisterthread(thread)
 
+    ################################################## Hooks
+
+    def callhook(s, msg):
+        if s.verbose >= 0:
+            s._msg(msg)
+
     ################################################## Other
 
     def sleep(s, sleepsecs):
