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