]> git.madduck.net Git - etc/offlineimap.git/blob - .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:

15824d25adcfb300500f04ae501528baed5a17c4
[etc/offlineimap.git] / .offlineimap / helper.py
1 # -*- coding: utf-8 -*-
2
3 import re, os, stat, time, atexit
4
5 base_excludes = ['delayed', 'outgoing', 'Trash', 'Sent', 'Queue']
6 full_excludes_re = ['discard', 'spool', 'spam', 'store(\..+)?']
7 prioritised = ['outgoing','resubmit','drafts','inbox','phd','ul','debian','sudetia','admin','retrain']
8 deprioritised = ['discard','spam','store','spool']
9
10 def py_foldersort_seamus(x, y):
11     for prefix in prioritised:
12         if x.startswith(prefix):
13             return -1
14         elif y.startswith(prefix):
15             return +1
16     for prefix in deprioritised:
17         if x.startswith(prefix):
18             return +1
19         elif y.startswith(prefix):
20             return -1
21     return cmp(x, y)
22
23 def py_nametrans_seamus(x):
24     return re.sub('^INBOX', 'inbox', x)
25
26 def should_do_full_sync():
27     FILE = os.path.expanduser('~/.var/offlineimap/lastrun')
28     INTERVAL = 86400/2
29     now = int(time.time())
30
31     try:
32         mtime = os.stat(FILE)[stat.ST_MTIME]
33     except OSError:
34         mtime = 0
35
36     since = now - mtime
37     if since > INTERVAL:
38         file(FILE, 'wb').close()
39         return True
40
41     print 'Partial sync; next full sync in %d seconds...' \
42             % (INTERVAL - since)
43     return False
44
45 do_full_sync = should_do_full_sync()
46 def py_folderfilter_seamus(x):
47
48     if do_full_sync:
49         return x not in base_excludes
50     else:
51         if x in base_excludes:
52             return False
53         if x in ('spool', 'discard', 'spam'):
54             return False
55         if re.search('^store(\..+)?', x):
56             return False
57     return True
58
59 def py_folderfilter_mbnames(acct, x):
60     full_excludes_re_mbnames = ['retrain/(sp|h)am'] + full_excludes_re
61     return acct in ['seamus.madduck.net'] \
62             and not re.search('^(' + '|'.join(full_excludes_re_mbnames) + ')', x)