]> code.delx.au - offlineimap/blob - offlineimap/head/offlineimap/mbnames.py
/offlineimap/head: changeset 267
[offlineimap] / offlineimap / head / offlineimap / mbnames.py
1 # Mailbox name generator
2 # Copyright (C) 2002 John Goerzen
3 # <jgoerzen@complete.org>
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 import os.path
20 import re # for folderfilter
21
22 def genmbnames(config, localeval, boxlist):
23 """Takes a configparser object and a boxlist, which is a list of hashes
24 containing 'accountname' and 'foldername' keys."""
25 if not config.getboolean("mbnames", "enabled"):
26 return
27 file = open(os.path.expanduser(config.get("mbnames", "filename")), "wt")
28 file.write(localeval.eval(config.get("mbnames", "header")))
29 folderfilter = lambda accountname, foldername: 1
30 if config.has_option("mbnames", "folderfilter"):
31 folderfilter = localeval.eval(config.get("mbnames", "folderfilter"),
32 {'re': re})
33 itemlist = [localeval.eval(config.get("mbnames", "peritem", raw=1)) % item\
34 for item in boxlist \
35 if folderfilter(item['accountname'], item['foldername'])]
36 file.write(localeval.eval(config.get("mbnames", "sep")).join(itemlist))
37 file.write(localeval.eval(config.get("mbnames", "footer")))
38 file.close()
39
40
41