#!/usr/bin/perl -w use strict; use Mail::POP3Client; use Mail::Mailer; our $junk; my $pophost = ''; my $popuser = ''; my $poppw = ''; my $reflectoraddr = ''; my $subjprefix = ''; my $errorfrom = ''; my $errorbcc = ''; my %participants; open(IN,"participants.txt") or die "Can't open participants.txt: $!\n"; while() { chop; if ($_) { $participants{$_} = 1; } } close IN; my $pop = Mail::POP3Client->new(HOST => $pophost, USER => $popuser, PASSWORD => $poppw); our $mailer = new Mail::Mailer; my $msgcount = $pop->Count(); print "$msgcount messages\n"; foreach my $k (1..1) { my %header; my $head = $pop->Head($k); my @lines = split(/\n/,$head); my $headerinfo; my ($key,$value); for my $i (0..$#lines) { $lines[$i] =~ s/\r/ /g; if (substr($lines[$i],0,1) =~ /[A-Z]/) { if ($lines[$i] =~ /^Date/) { $key = "Date"; ($value = $lines[$i]) =~ s/Date: //; } else { ($key,$value) = split(/\:/,$lines[$i]); } $header{$key} = $value; } else { $lines[$i] =~ s/^\s+//g; $header{$key} .= " $lines[$i]"; } } if ($header{'Subject'} !~ /undeliverable|delivery (failure|error)/i) { delete($header{'Received'}); delete($header{'Envelope-to'}); $header{'Reply-to'} = $reflectoraddr; delete($header{'To'}); $header{'Subject'} =~ s/\[Crawdad\] //g; my $body = $pop->Body($k); open (OUT,">bodytext.txt") or die "No output: $!\n"; print OUT $body; close OUT; my $from; if ($header{'From'} =~ /\<.+\>/) { ($junk, $from) = split(/[\<\>]/,$header{'From'}); } else { $from = $header{'From'}; } if (defined($participants{$from})) { $header{'Subject'} = "\[$subjprefix\] ".$header{'Subject'}; foreach my $p (keys %participants) { unless ($header{'From'} =~ /$p/) { print "Sending to $p\n"; $header{'To'} = $p; $mailer->open(\%header); print $mailer $body; $mailer->close; } } } else { print "Error to $from\n"; errormsg(\%header,$from); } } $pop->Delete($k); } $pop->Close(); sub errormsg { my ($header,$from) = @_; my $errormsg = "The address $from is not authorized to send to this discussion list.\n\nIf you are a registered user, it may be that you are sending from an e-mail account other than the one you normally use. Please contact the discussion host to have this account added."; delete($$header{'Content-Type'}); $$header{'Subject'} = 'ERROR: '.$$header{'Subject'}; $$header{'From'} = $errorfrom; $$header{'To'} = $from; $mailer->open($header); print $mailer $errormsg; $mailer->close; return; }