]>
code.delx.au - offlineimap/blob - offlineimap/head/offlineimap/mbnames.py
1 # Mailbox name generator
2 # Copyright (C) 2002 John Goerzen
3 # <jgoerzen@complete.org>
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.
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.
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
20 import re
# for folderfilter
21 from threading
import *
28 def init(conf
, accts
):
29 global config
, accounts
33 def add(accountname
, foldername
):
34 if not accountname
in boxes
:
35 boxes
[accountname
] = []
36 if not foldername
in boxes
[accountname
]:
37 boxes
[accountname
].append(foldername
)
40 # See if we're ready to write it out.
41 for account
in accounts
:
42 if account
not in boxes
:
48 """Takes a configparser object and a boxlist, which is a list of hashes
49 containing 'accountname' and 'foldername' keys."""
52 localeval
= config
.getlocaleval()
53 if not config
.getdefaultboolean("mbnames", "enabled", 0):
55 file = open(os
.path
.expanduser(config
.get("mbnames", "filename")), "wt")
56 file.write(localeval
.eval(config
.get("mbnames", "header")))
57 folderfilter
= lambda accountname
, foldername
: 1
58 if config
.has_option("mbnames", "folderfilter"):
59 folderfilter
= localeval
.eval(config
.get("mbnames", "folderfilter"),
62 for accountname
in boxes
.keys():
63 for foldername
in boxes
[accountname
]:
64 if folderfilter(accountname
, foldername
):
65 itemlist
.append(config
.get("mbnames", "peritem", raw
=1) % \
66 {'accountname': accountname
,
67 'foldername': foldername
})
68 file.write(localeval
.eval(config
.get("mbnames", "sep")).join(itemlist
))
69 file.write(localeval
.eval(config
.get("mbnames", "footer")))