~mailman-coders/mailman/2.1

« back to all changes in this revision

Viewing changes to contrib/courier-to-mailman.py

  • Committer: Mark Sapiro
  • Date: 2019-01-29 05:48:13 UTC
  • Revision ID: mark@msapiro.net-20190129054813-mgptc0jt6f4e21y3
Expand tabs in Python code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
import sys, os, re, string
58
58
 
59
59
def main():
60
 
        os.nice(5)  # Handle mailing lists at non-interactive priority.
61
 
 
62
 
        os.chdir(MailmanVar + "/lists")
63
 
 
64
 
        try:
65
 
                local = string.lower(os.environ["LOCAL"])
66
 
        except:
67
 
                # This might happen if we're not using qmail.
68
 
                sys.stderr.write("LOCAL not set in environment?\n")
69
 
                sys.exit(112)
70
 
 
71
 
        names = ("root", "postmaster", "mailer-daemon", "mailman-owner", "owner",
72
 
                         "abuse")
73
 
        for i in names:
74
 
                if i == local:
75
 
                        os.execv("/usr/bin/sendmail",
76
 
                                         ("/usr/bin/sendmail", MailmanOwner))
77
 
                        sys.exit(0)
78
 
 
79
 
        type = "post"
80
 
        listname = string.lower(local)
81
 
        types = (("-admin$", "admin"),
82
 
                         ("-bounces$", "bounces"),
83
 
                         ("-bounces\+.*$", "bounces"),          # for VERP
84
 
                         ("-confirm$", "confirm"),
85
 
                         ("-confirm\+.*$", "confirm"),
86
 
                         ("-join$", "join"),
87
 
                         ("-leave$", "leave"),
88
 
                         ("-owner$", "owner"),
89
 
                         ("-request$", "request"),
90
 
                         ("-subscribe$", "subscribe"),
91
 
                         ("-unsubscribe$", "unsubscribe"))
92
 
 
93
 
        for i in types:
94
 
                if re.search(i[0],local):
95
 
                        type = i[1]
96
 
                        listname = re.sub(i[0],"",local)
97
 
 
98
 
        if os.path.exists(listname):
99
 
                os.execv(MailmanHome + "/mail/mailman",
100
 
                                 (MailmanHome + "/mail/mailman", type, listname))
101
 
        else:
102
 
                bounce()
103
 
 
104
 
        sys.exit(111)
 
60
        os.nice(5)  # Handle mailing lists at non-interactive priority.
 
61
 
 
62
        os.chdir(MailmanVar + "/lists")
 
63
 
 
64
        try:
 
65
                local = string.lower(os.environ["LOCAL"])
 
66
        except:
 
67
                # This might happen if we're not using qmail.
 
68
                sys.stderr.write("LOCAL not set in environment?\n")
 
69
                sys.exit(112)
 
70
 
 
71
        names = ("root", "postmaster", "mailer-daemon", "mailman-owner", "owner",
 
72
                         "abuse")
 
73
        for i in names:
 
74
                if i == local:
 
75
                        os.execv("/usr/bin/sendmail",
 
76
                                         ("/usr/bin/sendmail", MailmanOwner))
 
77
                        sys.exit(0)
 
78
 
 
79
        type = "post"
 
80
        listname = string.lower(local)
 
81
        types = (("-admin$", "admin"),
 
82
                         ("-bounces$", "bounces"),
 
83
                         ("-bounces\+.*$", "bounces"),          # for VERP
 
84
                         ("-confirm$", "confirm"),
 
85
                         ("-confirm\+.*$", "confirm"),
 
86
                         ("-join$", "join"),
 
87
                         ("-leave$", "leave"),
 
88
                         ("-owner$", "owner"),
 
89
                         ("-request$", "request"),
 
90
                         ("-subscribe$", "subscribe"),
 
91
                         ("-unsubscribe$", "unsubscribe"))
 
92
 
 
93
        for i in types:
 
94
                if re.search(i[0],local):
 
95
                        type = i[1]
 
96
                        listname = re.sub(i[0],"",local)
 
97
 
 
98
        if os.path.exists(listname):
 
99
                os.execv(MailmanHome + "/mail/mailman",
 
100
                                 (MailmanHome + "/mail/mailman", type, listname))
 
101
        else:
 
102
                bounce()
 
103
 
 
104
        sys.exit(111)
105
105
 
106
106
def bounce():
107
 
        bounce_message = """\
 
107
        bounce_message = """\
108
108
TO ACCESS THE MAILING LIST SYSTEM: Start your web browser on
109
109
http://%s/
110
110
That web page will help you subscribe or unsubscribe, and will
111
111
give you directions on how to post to each mailing list.\n"""
112
 
        sys.stderr.write(bounce_message % (os.environ["HOST"]))
113
 
        sys.exit(100)
 
112
        sys.stderr.write(bounce_message % (os.environ["HOST"]))
 
113
        sys.exit(100)
114
114
 
115
115
try:
116
 
        sys.exit(main())
 
116
        sys.exit(main())
117
117
except SystemExit, argument:
118
 
        sys.exit(argument)
 
118
        sys.exit(argument)
119
119
 
120
120
except Exception, argument:
121
 
        info = sys.exc_info()
122
 
        trace = info[2]
123
 
        sys.stderr.write("%s %s\n" % (sys.exc_type, argument))
124
 
        sys.stderr.write("LINE %d\n" % (trace.tb_lineno))
125
 
        sys.exit(111) # Soft failure, try again later.
 
121
        info = sys.exc_info()
 
122
        trace = info[2]
 
123
        sys.stderr.write("%s %s\n" % (sys.exc_type, argument))
 
124
        sys.stderr.write("LINE %d\n" % (trace.tb_lineno))
 
125
        sys.exit(111) # Soft failure, try again later.