]> git.madduck.net Git - etc/offlineimap.git/blobdiff - .offlineimap/helper.py

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

use a function call per folder to determine whether to sync
[etc/offlineimap.git] / .offlineimap / helper.py
index 7719a8c420fe0920bff8593f951e3b5604435529..74400cadc20740ac1190bc929331adf0c4f44b56 100644 (file)
@@ -1,6 +1,13 @@
+# -*- coding: utf-8 -*-
+
+import re, os, stat, time, atexit
+
+base_excludes = ['delayed', 'outgoing', 'Trash', 'Sent', 'Queue']
+full_excludes_re = ['discard', 'spool', 'spam', 'store(\..+)?']
+prioritised = ['outgoing','resubmit','drafts','inbox','phd','ul','debian','sudetia','admin','retrain']
+deprioritised = ['discard','spam','store','spool']
+
 def py_foldersort_seamus(x, y):
 def py_foldersort_seamus(x, y):
-    prioritised = ('outgoing','resubmit','drafts','inbox','phd','ul','debian','sudetia','admin','retrain')
-    deprioritised = ('discard','spam','store','spool')
     for prefix in prioritised:
         if x.startswith(prefix):
             return -1
     for prefix in prioritised:
         if x.startswith(prefix):
             return -1
@@ -13,46 +20,44 @@ def py_foldersort_seamus(x, y):
             return -1
     return cmp(x, y)
 
             return -1
     return cmp(x, y)
 
-import re
-
 def py_nametrans_seamus(x):
     return re.sub('^INBOX', 'inbox', x)
 
 def should_do_full_sync():
 def py_nametrans_seamus(x):
     return re.sub('^INBOX', 'inbox', x)
 
 def should_do_full_sync():
-    import os, stat, time
     FILE = os.path.expanduser('~/.var/offlineimap/lastrun')
     INTERVAL = 86400/2
     now = int(time.time())
 
     try:
     FILE = os.path.expanduser('~/.var/offlineimap/lastrun')
     INTERVAL = 86400/2
     now = int(time.time())
 
     try:
-        mtime = os.stat(FILE)[stat.ST_MTIME]
-    except OSError:
-        mtime = 0
+        since = now - os.stat(FILE)[stat.ST_MTIME]
+    except:
+        since = INTERVAL + 1
 
 
-    since = now - mtime
     if since > INTERVAL:
     if since > INTERVAL:
-        file(FILE, 'wb').close()
+        @atexit.register
+        def write_trace():
+            print 'Writing trace file…'
+            file(FILE, 'wb').close()
         return True
 
         return True
 
-    print 'Partial sync; next full sync in %d seconds...' \
+    @atexit.register
+    def write_sync_notice():
+        print 'Partial sync complete; next full sync in %d seconds…' \
             % (INTERVAL - since)
             % (INTERVAL - since)
+
     return False
 
     return False
 
-do_full_sync = should_do_full_sync()
 def py_folderfilter_seamus(x):
 def py_folderfilter_seamus(x):
-    base_excludes = ['delayed', 'outgoing', 'Trash', 'Sent']
-
-    if do_full_sync:
-        return x not in base_excludes
-    else:
-        if x in base_excludes:
-            return False
-        if x in ('spool', 'discard', 'spam'):
-            return False
-        if re.search('^store(\..+)?', x):
-            return False
+
+    if x in base_excludes:
+        return False
+
+    elif re.search('^(' + '|'.join(full_excludes_re) + ')', x):
+        return should_do_full_sync()
+
     return True
 
 def py_folderfilter_mbnames(acct, x):
     return True
 
 def py_folderfilter_mbnames(acct, x):
+    full_excludes_re_mbnames = ['retrain/(sp|h)am'] + full_excludes_re
     return acct in ['seamus.madduck.net'] \
     return acct in ['seamus.madduck.net'] \
-            and not re.search('^(store(/.+)?|retrain/(ham|spam)|spool|discard|spam)', x)
+            and not re.search('^(' + '|'.join(full_excludes_re_mbnames) + ')', x)