Can remove the sender and/or the recipient from the key of the greylister.
[apps/pfixtools.git] / tools / rbldns2postlicyd
1 #!/usr/bin/env python
2 ##############################################################################
3 #          pfixtools: a collection of postfix related tools                  #
4 #          ~~~~~~~~~                                                         #
5 #  ________________________________________________________________________  #
6 #                                                                            #
7 #  Redistribution and use in source and binary forms, with or without        #
8 #  modification, are permitted provided that the following conditions        #
9 #  are met:                                                                  #
10 #                                                                            #
11 #  1. Redistributions of source code must retain the above copyright         #
12 #     notice, this list of conditions and the following disclaimer.          #
13 #  2. Redistributions in binary form must reproduce the above copyright      #
14 #     notice, this list of conditions and the following disclaimer in the    #
15 #     documentation and/or other materials provided with the distribution.   #
16 #  3. The names of its contributors may not be used to endorse or promote    #
17 #     products derived from this software without specific prior written     #
18 #     permission.                                                            #
19 #                                                                            #
20 #  THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND   #
21 #  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE     #
22 #  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR        #
23 #  PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS    #
24 #  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR    #
25 #  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF      #
26 #  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS  #
27 #  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN   #
28 #  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)   #
29 #  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF    #
30 #  THE POSSIBILITY OF SUCH DAMAGE.                                           #
31 ##############################################################################
32
33 # Copyright (c) 2008 Florent Bruneau
34
35 import os, re, sys
36
37 def headers(file, source, type):
38     file.write("# Do not edit, file autogenerated by %s\n" % sys.argv[0])
39     file.write("# This file has been generated from %s blacklist\n" % source)
40     file.write("#   it contains %s matching rules for postlicyd\n" % type)
41
42 def convert(rbl):
43     source  = open(rbl, "r")
44     hosts   = open("%s_hosts" % rbl, "w")
45     domains = open("%s_domains" % rbl, "w")
46
47     headers(hosts, rbl, "hosts")
48     headers(domains, rbl, "domains")
49
50     for line in source:
51         if line[0].isalnum():
52             hosts.write(line);
53         elif line[0] == '*':
54             domains.write(line[1:]);
55
56 if __name__ == '__main__':
57     if len(sys.argv) == 1:
58         print "Usage: %s [input] ..." % sys.argv[0]
59         sys.exit(1)
60
61     map(convert, sys.argv[1:])
62
63 # vim:set syntax=python: