2002-06-21 08:51:21 +02:00
|
|
|
# Mailbox name generator
|
|
|
|
# Copyright (C) 2002 John Goerzen
|
|
|
|
# <jgoerzen@complete.org>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
2003-04-16 21:23:45 +02:00
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
2002-06-21 08:51:21 +02:00
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
2006-08-12 06:15:55 +02:00
|
|
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2002-06-21 08:51:21 +02:00
|
|
|
|
|
|
|
import os.path
|
2002-10-01 00:09:27 +02:00
|
|
|
import re # for folderfilter
|
2003-01-06 21:41:14 +01:00
|
|
|
from threading import *
|
2002-06-21 08:51:21 +02:00
|
|
|
|
2003-01-06 21:40:23 +01:00
|
|
|
boxes = {}
|
|
|
|
config = None
|
|
|
|
accounts = None
|
2003-01-06 21:41:14 +01:00
|
|
|
mblock = Lock()
|
2003-01-06 21:40:23 +01:00
|
|
|
|
|
|
|
def init(conf, accts):
|
|
|
|
global config, accounts
|
|
|
|
config = conf
|
|
|
|
accounts = accts
|
|
|
|
|
|
|
|
def add(accountname, foldername):
|
|
|
|
if not accountname in boxes:
|
|
|
|
boxes[accountname] = []
|
|
|
|
if not foldername in boxes[accountname]:
|
|
|
|
boxes[accountname].append(foldername)
|
|
|
|
|
|
|
|
def write():
|
|
|
|
# See if we're ready to write it out.
|
|
|
|
for account in accounts:
|
|
|
|
if account not in boxes:
|
|
|
|
return
|
|
|
|
|
|
|
|
genmbnames()
|
|
|
|
|
|
|
|
def genmbnames():
|
2002-06-21 08:51:21 +02:00
|
|
|
"""Takes a configparser object and a boxlist, which is a list of hashes
|
|
|
|
containing 'accountname' and 'foldername' keys."""
|
2003-01-06 21:41:14 +01:00
|
|
|
mblock.acquire()
|
|
|
|
try:
|
|
|
|
localeval = config.getlocaleval()
|
2003-01-07 04:15:22 +01:00
|
|
|
if not config.getdefaultboolean("mbnames", "enabled", 0):
|
2003-01-06 21:41:14 +01:00
|
|
|
return
|
|
|
|
file = open(os.path.expanduser(config.get("mbnames", "filename")), "wt")
|
|
|
|
file.write(localeval.eval(config.get("mbnames", "header")))
|
|
|
|
folderfilter = lambda accountname, foldername: 1
|
|
|
|
if config.has_option("mbnames", "folderfilter"):
|
|
|
|
folderfilter = localeval.eval(config.get("mbnames", "folderfilter"),
|
|
|
|
{'re': re})
|
|
|
|
itemlist = []
|
|
|
|
for accountname in boxes.keys():
|
|
|
|
for foldername in boxes[accountname]:
|
|
|
|
if folderfilter(accountname, foldername):
|
|
|
|
itemlist.append(config.get("mbnames", "peritem", raw=1) % \
|
|
|
|
{'accountname': accountname,
|
|
|
|
'foldername': foldername})
|
|
|
|
file.write(localeval.eval(config.get("mbnames", "sep")).join(itemlist))
|
|
|
|
file.write(localeval.eval(config.get("mbnames", "footer")))
|
|
|
|
file.close()
|
|
|
|
finally:
|
|
|
|
mblock.release()
|
2002-06-21 08:51:21 +02:00
|
|
|
|
|
|
|
|