#!/usr/bin/perl # send-mass.plx -*- Perl -*- # # This program's license gives you software freedom; you can copy, modify, # convey, and/or redistribute it under the terms of the GNU General Public # License as published by the Free Software Foundation; either version 3 of # the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program in a file called 'GPLv3'. If not, write to the: # Free Software Foundation, Inc., 51 Franklin St, Fifth Floor # Boston, MA 02110-1301, USA. use strict; use warnings; use Email::MIME::RFC2047::Encoder; use utf8; my $encoder = Email::MIME::RFC2047::Encoder->new(); use utf8; if (@ARGV != 3 and @ARGV != 4) { print "usage: $0 []\n"; exit 1; } my($LIST_FILE, $MESSAGE_FILE, $FROM_ADDRESS, $SKIP_LIST_FILE) = @ARGV; my %skip; if (defined $SKIP_LIST_FILE) { die "$SKIP_LIST_FILE does not exist or is not readable: $!" unless -r $SKIP_LIST_FILE; open(SKIP_LIST, "<", $SKIP_LIST_FILE); while (my $line = ) { chomp $line; $skip{$line} = $SKIP_LIST_FILE; } } open(LIST, "<$LIST_FILE") or die "unable to open $LIST_FILE: $!"; my @sendTo; while (my $line = ) { chomp $line; $line =~ s/#.*$//; next if $line =~ /^\s*$/; push(@sendTo, $line); } close LIST; open(MESSAGE, "<$MESSAGE_FILE") or die "unable to open $MESSAGE_FILE: $!"; my @message; @message = ; close MESSAGE; foreach my $fullEmailLine (@sendTo) { my $doSkip = 0; foreach my $skip (keys %skip) { if ($fullEmailLine =~ /$skip/) { print STDERR "Skipping $fullEmailLine\n"; $doSkip = 1; last; } } next if $doSkip; $fullEmailLine =~ s/\s*#.*$//; $fullEmailLine =~ s/\s*$//; $fullEmailLine =~ s/^\s*//; my $emailTo; die unless $fullEmailLine =~ /^"?([^\<]+)\s*"?\<\s*([^\>]+)\s*\>\s*$/; ($fullEmailLine, $emailTo) = ($1, $2); $fullEmailLine =~ s/\s*\"?\s*$//; $fullEmailLine =~ s/^\s*"?\s*//; $fullEmailLine = $encoder->encode_phrase($fullEmailLine) . " <" . $emailTo .">"; # open(SENDMAIL, "|/usr/lib/sendmail -f \"$FROM_ADDRESS\" -oi -oem -- \"$emailTo\" \"$FROM_ADDRESS\"") or die "unable to run sendmail: $!"; print SENDMAIL "To: $fullEmailLine\n"; # X-Precedence: bulk\n"; print SENDMAIL @message; close SENDMAIL; print STDERR "Sentto \"$fullEmailLine\" at $emailTo\n"; sleep 1; } # Local variables: # compile-command: "perl -c send-mass.plx" # End: