3
## Sendmail mailer for Mailman
5
## Simulates these aliases:
7
##testlist: "|/home/mailman/mail/mailman post testlist"
8
##testlist-admin: "|/home/mailman/mail/mailman admin testlist"
9
##testlist-bounces: "|/home/mailman/mail/mailman bounces testlist"
10
##testlist-confirm: "|/home/mailman/mail/mailman confirm testlist"
11
##testlist-join: "|/home/mailman/mail/mailman join testlist"
12
##testlist-leave: "|/home/mailman/mail/mailman leave testlist"
13
##testlist-owner: "|/home/mailman/mail/mailman owner testlist"
14
##testlist-request: "|/home/mailman/mail/mailman request testlist"
15
##testlist-subscribe: "|/home/mailman/mail/mailman subscribe testlist"
16
##testlist-unsubscribe: "|/home/mailman/mail/mailman unsubscribe testlist"
17
##owner-testlist: testlist-owner
19
#### Begin configuration here ####
21
$MMWRAPPER = "/usr/lib/mailman/mail/mailman";
22
$MMLISTDIR = "/var/lib/mailman/lists";
23
$SENDMAIL = "/usr/lib/sendmail -oem -oi";
24
$VERSION = '$Id: mm-handler 2.1.10 2008-04-14 00:00:00 $';
26
## Comment this if you offer local user addresses.
27
$NOUSERS = "\nPersonal e-mail addresses are not offered by this server.";
29
# set for debugging....
32
# Define the set of actions you want to allow (that is, which aliases
33
# you want to emulate). This should be a subset of @ValidActions,
34
# defined below, plus the special "post" action.
35
#@ApprovedActions = qw(admin bounces confirm join leave
36
# owner request subscribe unsubscribe);
37
# aliases removed to suppress spam backscatter
38
@ApprovedActions = qw(bounces confirm owner request post);
40
# Allow backscatter for unapproved actions?
41
$BounceUnapproved = 0;
43
# Allow backscatter for undefined lists?
46
#### End of configuration ####
52
use Unix::Syslog qw(:macros);
53
use Unix::Syslog qw(:subs);
56
my $syslog_ident = basename $0;
57
my $syslog_options = LOG_PID;
58
my $syslog_facility = LOG_MAIL;
60
# These are the listname-action actions defined by the mailman wrapper
61
# program. Do not alter this unless a new Mailman version changes the
62
# set of supported actions.
63
@ValidActions = qw(admin bounces confirm join leave
64
owner request subscribe unsubscribe);
66
($VERS_STR = $VERSION) =~ s/^\$\S+\s+(\S+)(?:,v)?\s+(\S+\s+\S+\s+\S+).*/\1 \2/;
68
$BOUNDARY = sprintf("%08x-%d", time, time % $$);
70
## Informative, non-standard rejection letter
72
my ($in, $to, $list, $server, $reason) = @_;
75
if ($server && $server ne "") {
78
$servname = "This server";
79
$server = &get_ip_addr;
82
#$sendmail = new FileHandle ">/tmp/mm-$$";
83
$sendmail = new FileHandle "|$SENDMAIL $to";
84
if (!defined($sendmail)) {
85
syslog LOG_ERR, "cannot exec \"$SENDMAIL\"";
89
$sendmail->print ("From: MAILER-DAEMON\@$server
91
Subject: Returned mail: List unknown
93
Content-type: multipart/mixed; boundary=\"$BOUNDARY\"
94
Content-Disposition: inline
97
Content-Type: text/plain; charset=us-ascii
98
Content-Description: Error processing your mail
99
Content-Disposition: inline
101
Your mail for $list could not be sent:
104
For a list of publicly-advertised mailing lists hosted on this server,
108
If this does not resolve your problem, you may write to:
111
mailman-owner\@$server
114
$servname delivers e-mail to registered mailing lists
115
and to the administrative addresses defined and required by IETF
116
Request for Comments (RFC) 2142 [1].
119
The Internet Engineering Task Force [2] (IETF) oversees the development
120
of open standards for the Internet community, including the protocols
121
and formats employed by Internet mail systems.
123
For your convenience, your original mail is attached.
126
[1] Crocker, D. \"Mailbox Names for Common Services, Roles and
127
Functions\". http://www.ietf.org/rfc/rfc2142.txt
129
[2] http://www.ietf.org/
132
Content-Type: message/rfc822
133
Content-Description: Your undelivered mail
134
Content-Disposition: attachment
139
$sendmail->print ($_);
142
$sendmail->print ("\n");
143
$sendmail->print ("--$BOUNDARY--\n");
148
## Get my IP address, in case my sendmail doesn't tell me my name.
151
my $ip = gethostbyname($host);
152
return inet_ntoa($ip);
155
## Split an address into its base list name and the appropriate command
156
## for the relevant function.
161
if ($addr =~ /(.*)-([^-]+)\+.*$/) {
164
} elsif ($addr =~ /(.*)-([^-]+)$/) {
169
return ($addr, "post");
171
if ($list eq "owner") {
172
# Allow owner-listname to work as listname-owner
175
} elsif (! grep /^$cmd$/, @ValidActions) {
176
# If an undefined action, restore list name
180
## Otherwise use $list and $cmd as already assigned
182
return ($list, $cmd);
185
## Determine whether a list is defined in Mailman.
189
return 1 if (-f "$MMLISTDIR/$list/config.pck");
190
return 1 if (-f "$MMLISTDIR/$list/config.db");
194
## The time, formatted as for an mbox's "From_" line.
197
my @days = qw(Sun Mon Tue Wed Thu Fri Sat);
198
my @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
199
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
202
## Two-digit year handling complies with RFC 2822 (section 4.3),
203
## with the addition that three-digit years are accommodated.
206
} elsif ($year < 1900) {
210
return sprintf ("%s %s %2d %02d:%02d:%02d %d",
211
$days[$wday], $months[$mon], $mday,
212
$hour, $min, $sec, $year);
216
openlog $syslog_ident, $syslog_options, $syslog_facility;
220
while ($#ARGV >= 0) {
221
if ($ARGV[0] eq "-r") {
224
} elsif (!defined($server)) {
233
my $to = join(',', @to);
234
syslog LOG_INFO, "to: $to; sender: $sender; server: $server";
237
ADDR: for $addr (@to) {
242
$was_to .= "\@$server" if ("$server" ne "");
245
($list, $cmd) = &split_addr($list);
247
syslog LOG_INFO, "list: $list; cmd: $cmd";
249
if (! &list_exists($list)) {
250
syslog LOG_INFO, "no list named \"$list\" is known by $server";
251
if ($BounceNonlist) {
252
mail_error(\*STDIN, $sender, $was_to, $server,
253
"no list named \"$list\" is known by $server");
258
if (! grep /^$cmd$/, @ApprovedActions) {
259
syslog LOG_INFO, "$cmd is not a recognized action for $list";
260
if ($BounceUnapproved) {
261
mail_error(\*STDIN, $sender, $was_to, $server,
262
"$cmd is not a recognized action for $list");
268
syslog LOG_INFO, "invoking $MMWRAPPER";
270
$wrapper = new FileHandle "|$MMWRAPPER $cmd $list";
271
if (!defined($wrapper)) {
273
syslog LOG_ERR, "cannot exec ",
274
"\"$MMWRAPPER $cmd $list\": deferring";
278
# Don't need these without the "n" flag on the mailer def....
279
#$date = &mboxdate(time);
280
#$wrapper->print ("From $sender $date\n");
282
# ...because we use these instead.
284
$wrapper->print ($from_);
286
$wrapper->print ("X-Mailman-Handler: $VERSION\n");
288
$wrapper->print ($_);
292
syslog LOG_INFO, "message processed";