]> 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:

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