chiark / gitweb /
addrcheck: Check incoming mail for valid mailbox names.
[newsgate] / bin / mkcdb
1 #! /usr/bin/python
2
3 from cdb import cdbmake
4 from sre import sub as r_sub, compile as r_compile
5 from sys import argv, stderr, exit
6
7 ego = r_sub(r'^.*[/\\]', '', argv[0])
8 def die(msg, tag = True):
9   if tag: msg = '%s: %s' % (ego, msg)
10   print >>stderr, msg
11   exit(1)
12 if len(argv) != 2:
13   die('usage: %s GROUPFILE' % ego)
14
15 rx_comment = r_compile(r'^\s*(\#|$)')
16 group = argv[1]
17 cdb = cdbmake(group + '.cdb', group + '.cdb.new')
18 i = 0
19 for line in open(group, 'r'):
20   i += 1
21   if rx_comment.match(line): continue
22   f = line.split()
23   if len(f) != 3: die('bad info line %d.' % i)
24   l = ' '.join(f)
25   tag, group, addr = f
26   group = group.replace('.', '-')
27   cdb.add('t:%s' % tag, l)
28   cdb.add('g:%s' % group, l)
29 cdb.finish()