use Mail::POP3Client; use Mail::DeliveryStatus::BounceParser; # the following module is general housekeeping stuff use Oakbox::Main; my $Main = Oakbox::Main->new("adminemail"=>"richard\@oakbox.com", "logfile" => "Site_Log.txt", "scratch_dir"=> "/tmp/bouncing/"); # connect to the mailbox my $pop = new Mail::POP3Client( USER => "doublebounce", PASSWORD => "password", HOST=> "my.mailserver.com", DEBUG => 0 , AUTH_MODE => 'PASS' ); my $count = $pop->Count; if ($count == -1) { die("Unable to read Mail box! Something went horribly wrong here.");} &listletters; exit; #### sub listletters{ my $nummessages=$pop->Count(); foreach my $i (1 ... $nummessages) { # read this message my $mailpiece = $pop->HeadAndBody($i); # Read the message, if it can't be parsed, delete it my $bounce = eval { Mail::DeliveryStatus::BounceParser->new( $mailpiece ) }; if ($@) { $pop->Delete( $i ); next; } # couldn't parse. # If it's not a bounce, delete it if(! $bounce->is_bounce()){ $pop->Delete( $i ); next; } # After a bunch of testing, this is the consistent # test for a 'real' bounce if($bounce->orig_message_id() =~ /qmail\@my.mailserver.com/){ my @reports = $bounce->reports(); foreach my $report (@reports){ my $email_address = $report->get('email'); my $reason = $report->get('std_reason'); my $orig = $bounce->orig_text(); if($email_address eq ""){ next; } ### This is a series of tests related to different # sites that I'm hosting. If I find the original # message, I email the correct person and return # true, so I know I can delete it. my $ret_code = &check_otm($email_address,$reason,$orig); if($ret_code eq "1"){ $pop->Delete( $i ); next; } # several other tests # It's a bounce, I don't know what to do, # let Richard figure it out my $rawmessage = $report->get('raw'); &default_handler($email_address,$reason,$orig,$rawmessage); $pop->Delete( $i ); } # This message isn't from my server, drop # it }else{ $pop->Delete( $i ); } } # You have to State and Close the POP3 connection # for the messages to actually BE deleted. $pop->State(); $pop->Close(); }