#!/opt/bin/perl ## ## Sendmail mailer for Mailman ## ## Simulates these aliases: ## testlist: "|/opt/pkgs/mailman/mail/wrapper post testlist" ## testlist-admin: "|/opt/pkgs/mailman/mail/wrapper mailowner testlist" ## testlist-request: "|/opt/pkgs/mailman/mail/wrapper mailcmd testlist" ## owner-testlist: testlist-admin ## testlist-owner: testlist-admin use FileHandle; use Sys::Hostname; use Socket; $MMWRAPPER = "/opt/pkgs/mailman/mail/wrapper"; $MMLISTDIR = "/var/mailman/lists"; $SENDMAIL = "/usr/lib/sendmail -oem -oi"; $VERSION = '$Id: mm-handler,v 1.8 2000/09/27 04:58:09 dgc Exp $'; ($VERS_STR = $VERSION) =~ s/^\$\S+\s+(\S+),v\s+(\S+\s+\S+\s+\S+).*/\1 \2/; $BOUNDARY = sprintf("%08x-%d", time, time % $$); ## Informative, non-standard rejection letter sub mail_error { my ($in, $to, $list, $server, $reason) = @_; my $sendmail; if ($server && $server ne "") { $servname = $server; } else { $servname = "This server"; $server = &get_ip_addr; } #$sendmail = new FileHandle ">/tmp/mm-$$"; $sendmail = new FileHandle "|$SENDMAIL $to"; if (!defined($sendmail)) { print STDERR "$0: cannot exec \"$SENDMAIL\"\n"; exit (-1); } $sendmail->print ("From: MAILER-DAEMON\@$server To: $to Subject: Returned mail: List unknown Mime-Version: 1.0 Content-type: multipart/mixed; boundary=\"$BOUNDARY\" Content-Disposition: inline --$BOUNDARY Content-Type: text/plain; charset=us-ascii Content-Description: Error processing your mail Content-Disposition: inline Your mail for $list could not be sent: $reason For a list of publicly-advertised mailing lists hosted on this server, visit this URL: http://$server/ If this does not resolve your problem, you may write to: postmaster\@$server or mailman-owner\@$server Your original mail is attached. --$BOUNDARY Content-Type: text/plain; charset=us-ascii; name=\"boilerplate.txt\" Content-Description: Purpose and scope of this mail system Content-Disposition: inline; filename=\"boilerplate.txt\" $servname delivers e-mail exclusively to mailing lists and to the administrative addresses defined and expected by RFC. The Internet Engineering Task Force[1] (IETF) publishes Requests for Comments (RFC) and Standards (STD) describing observed or defined behaviors for Internet protocols and entities. This process is documented in RFC 2026[2]. This mail system is compliant with RFC 2142[3]. RFC 2142 defines standard e-mail addresses that an Internet electronic mail agent is expect to identify and to which it should deliver or relay mail. [1] http://www.ietf.org/ [2] Bradner, S. RFC 2026, \"The Internet Standards Process -- Revision 3\". Harvard University. October 1996. http://www.ietf.org/rfc/rfc2026.txt [3] RFC 2142 defines standard e-mail address an Internet electronic mail agent is expect to identify: Crocker, D. \"Mailbox Names for Common Services, Roles and Functions\". http://www.ietf.org/rfc/rfc2142.txt --$BOUNDARY Content-Type: message/rfc822 Content-Description: Your undelivered mail Content-Disposition: attachment "); while ($_ = <$in>) { $sendmail->print ($_); } $sendmail->print ("\n"); $sendmail->print ("--$BOUNDARY--\n"); close($sendmail); } ## Get my IP address, in case my sendmail doesn't tell me my name. sub get_ip_addr { my $host = hostname; my $ip = gethostbyname($host); return inet_ntoa($ip); } ## Split an address into its base list name and the appropriate command ## for the relevant function. sub split_addr { my ($addr) = @_; my ($list, $cmd); if ($addr =~ /(.*)-admin$/ || $addr =~ /(.*)-owner$/ || $addr =~ /^owner-(.*)$/) { $list = $1; $cmd = "mailowner"; } elsif ($addr =~ /(.*)-request$/) { $list = $1; $cmd = "mailcmd"; } else { $list = $addr; $cmd = "post"; } return ($list, $cmd); } ## The time, formatted as for an mbox's "From_" line. sub mboxdate { my ($time) = @_; my @days = qw(Sun Mon Tue Wed Thu Fri Sat); my @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime($time); if ($year < 70) { $year += 2000; } elsif ($year < 1900) { $year += 1900; } return sprintf ("%s %s %2d %02d:%02d:%02d %d", $days[$wday], $months[$mon], $mday, $hour, $min, $sec, $year); } BEGIN: { $sender = undef; $server = undef; @to = (); while ($#ARGV >= 0) { if ($ARGV[0] eq "-r") { $sender = $ARGV[1]; shift @ARGV; } elsif (!defined($server)) { $server = $ARGV[0]; } else { push(@to, $ARGV[0]); } shift @ARGV; } # uncomment for debugging.... #$DEBUG = 1; if ($DEBUG) { $to = join(',', @to); print STDERR "to: $to\n"; print STDERR "sender: $sender\n"; print STDERR "server: $server\n"; exit(-1); } ADDR: for $addr (@to) { $prev = undef; $list = $addr; $cmd= "post"; if (! -f "$MMLISTDIR/$list/config.db") { ($list, $cmd) = &split_addr($list); if (! -f "$MMLISTDIR/$list/config.db") { $was_to = $addr; $was_to .= "\@$server" if ("$server" ne ""); mail_error(\*STDIN, $sender, $was_to, $server, "no list named \"$list\" is known by $server"); next ADDR; } } $wrapper = new FileHandle "|$MMWRAPPER $cmd $list"; if (!defined($wrapper)) { ## Defer? print STDERR "$0: cannot exec ", "\"$MMWRAPPER $cmd $list\": deferring\n"; exit (-1); } # Don't need these without the "n" flag on the mailer def.... #$date = &mboxdate(time); #$wrapper->print ("From $sender $date\n"); # ...because we use these instead. $from_ = ; $wrapper->print ($from_); $wrapper->print ("X-Mailman-Handler: $VERSION\n"); while () { $wrapper->print ($_); } close($wrapper); } }