]>
code.delx.au - offlineimap/blob - 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 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
)
39 def sort(accountname
, foldersort
):
40 boxes
[accountname
].sort(foldersort
)
43 # See if we're ready to write it out.
44 for account
in accounts
:
45 if account
not in boxes
:
51 """Takes a configparser object and a boxlist, which is a list of hashes
52 containing 'accountname' and 'foldername' keys."""
55 localeval
= config
.getlocaleval()
56 if not config
.getdefaultboolean("mbnames", "enabled", 0):
58 file = open(os
.path
.expanduser(config
.get("mbnames", "filename")), "wt")
59 file.write(localeval
.eval(config
.get("mbnames", "header")))
60 folderfilter
= lambda accountname
, foldername
: 1
61 if config
.has_option("mbnames", "folderfilter"):
62 folderfilter
= localeval
.eval(config
.get("mbnames", "folderfilter"),
65 for accountname
in boxes
.keys():
66 for foldername
in boxes
[accountname
]:
67 if folderfilter(accountname
, foldername
):
68 itemlist
.append(config
.get("mbnames", "peritem", raw
=1) % \
69 {'accountname': accountname
,
70 'foldername': foldername
})
71 file.write(localeval
.eval(config
.get("mbnames", "sep")).join(itemlist
))
72 file.write(localeval
.eval(config
.get("mbnames", "footer")))