#!/usr/local/bin/perl -w # # mailer.pl (C) 1997-2000 Stuart Caie # homebrew mailing list system # this is distributed under the terms of the GNU public license version 2 # use strict; #------------------------------------------------------------------------------ my $CONFDIR = "$ENV{'HOME'}/list"; # home directory of list lists my $SENDMAIL = '/usr/sbin/sendmail -i -t'; # Sendmail command/options my $DEFGROUP = 'all'; # default group to remail to my @GROUPS = qw(jasmine kitty); # other names of group lists #------------------------------------------------------------------------------ my $DEBUG = 0; my $MAGIC = 'Kyzers Magic Mailer'; ## read in mail headers ## my @headers=(); my $subject='(no subject)'; while () { print "DEBUG: HEADER $_" if $DEBUG; last if /^$/; # anti-cycle protection die "Already mailed this" if /^X\-Mailer\: $MAGIC/i; $subject=$1 if /^Subject: (.+)/i; push @headers, $_ unless /^\s/ or /^Received\:/i or /^From /i or /^Bcc\:/i or /^Subject\:/i or /^X\-Mailer\:/i; } chomp $subject; print "DEBUG: SUBJECT $subject\n" if $DEBUG; ## select appropriate list based on Subject: line ## my $config; map {if ($subject =~ /\b$_\:/i) { $config=$_ unless $config; }} @GROUPS; $config = $DEFGROUP unless $config; print "DEBUG: CONFIG $config\n" if $DEBUG; ## pull the membership of that list into an email list ## my $dest; if (open MEMBERS, "<$CONFDIR/$config") { $dest = join ', ', grep { !/^$/ } map { chomp; s/\#.*$//; s/\;.*$//; if (/^\s*(\S+)/) { $_=$1; $_=$1 if /^\<(.+)\>/; $_=$1 if /^\"(.+)\"/; $_=$1 if /^\'(.+)\'/; $_=$_; } else { $_=''; } } ; close MEMBERS; } else { die "No list for group '$config' - $!"; } print "DEBUG: FINAL LIST $dest\n" if $DEBUG; ## mail the people involved ## if (open MAIL, "|$SENDMAIL") { my $headers = join '',@headers; my $message = join '',; print "DEBUG: MESSAGE BEGINS\n$message\nDEBUG: MESSAGE ENDS\n" if $DEBUG; die "Error sending mail - $!" unless print MAIL $headers; die "Error sending mail - $!" unless print MAIL "X-Mailer: $MAGIC\n"; die "Error sending mail - $!" unless print MAIL "Bcc: $dest\n"; die "Error sending mail - $!" unless print MAIL "Subject: $subject\n"; die "Error sending mail - $!" unless print MAIL $message; close MAIL; } else { die "Failed to send mail - $!"; }