I have submitted this problem once already and I received a few quick answers primarily commenting on my incorrect code. However, even after fixing the problems pointed out the error still occurs and interest in this has essentially died.
I am currently writing a simple filter and forward script. Essentially when an email comes to a certain domain it is passed to the script. The script checks a database to see where the email should be forwarded to and then it also does a lookup against a filter table to see if the body of the email should be stored. (This is for a research project in the university) The script works fine except in the one case where the sender address is the same as the address the email will be forwarded to. The logs I am writing say that the email is sent successfully but the email never arrives. Coming from any other address and the email arrives without a problem.
Each email address in our domain will forward to one personal email address and according to the user's contacts and what they submit to us each email will have the body stripped and stored for further linguistic analysis.
Here are the specs for the server:
perl v5.6.1 built for i386-freebsd
Mail::Audit
Sendmail 8.12.11(I think)

Here is the code:
#Declare packages to be used always including strict and utf8 use strict; use warnings; use Mail::Audit; use IO::Handle; use DBI; #Connect to the database my $dbh = DBI->connect("dbi:Pg:dbname=database", "username", "password +", {AutoCommit => 0}); #Declare variables to be used including command line variables if need +ed my ($stored_email, $log, $to, $from, $forward_address, $store, $body, +$sql, $sth, $date, $local_address); my (@filter, @row, @time); my (%forward); @time = localtime; $date = sprintf("%2d/%2d/%4d %02d:%02d:%02d", $time[4] + 1, $time[3], +$time[5] + 1900, @time[2,1,0]); #Create any functions necessary #Main body of program ##Set variable values $sql = "SELECT \"ForwardMailTo\", \"ForwardMailFrom\" FROM \"tblForwardMail\""; $sth = $dbh->prepare($sql); $sth->execute; while (@row = $sth->fetchrow) { $forward{$row[0]} = $row[1]; } $stored_email = "/home/gevterm/Mail_Script/stored_mail.txt"; $log = "/home/gevterm/Mail_Script/audit_mail.log"; $store = 0; ##Open the log file open (LOG, ">>$log") or die "$date --- Couldn't open $log"; ##See if there is a match for the to email to find the forward address my $incoming = Mail::Audit->new; $incoming->noexit(1); $to = $incoming->to(); $from = $incoming->from(); ##Test to see if the to address exists and map the forwarding address while(my ($key, $value) = each(%forward)) { if ($to =~ $key) { $local_address = $key; $forward_address = $value; } } if ($forward_address) { print LOG "$date --- $to has been mapped to $forward_address\n"; $sql = <<EOF; SELECT "tblForwardMail"."ForwardMailID", "tblFilterMail"."FilterMailEm +ail" FROM "tblForwardMail" JOIN "tblFilterMail" ON "tblForwardMail"."ForwardMailID"="tblFilterMai +l"."ForwardMailID" WHERE "tblForwardMail"."ForwardMailTo"='$local_address' EOF $sth = $dbh->prepare($sql); $sth->execute; while (@row = $sth->fetchrow) { push(@filter, $row[1]); } } else { print LOG "$date --- No mapping for $to\n"; close (LOG); exit(); } ##Check to see if the from address is part of the filter list print LOG "$date --- Searching for filter email.\n"; foreach my $email_address(@filter) { if (($from =~ $email_address)){ $store = 1; } } ##Either store the email and forward it or just forward the email $incoming->resend($forward_address) or print LOG "$date --- Couldn't f +orward to $forward_address\n"; if ($store) { open (OUTPUT, ">>", $stored_email) or print LOG "$date --- Couldn' +t open $stored_email.\n"; print OUTPUT "##--------------------------------Start $date------- +------------------------##\n"; my $body = ""; if ($incoming->is_mime()) { if ($incoming->is_multipart()) { my $temp = $incoming->parts(0); $body = $temp->stringify_body; } else { $body = $incoming->stringify_body; } } else { $body = @{$incoming->body()}; } #Grab the charset value my $header = $incoming->header(); if ($header =~ m/charset="(\S+)"/m){ if ($1 ne "UTF-8") { print LOG "ENCODING IS UTF8\n"; #$body = $body . "\n" . to_utf8({ -string => $body, -chars +et => $1 }); } } #If there is no charset then assume charset ASCII or ISO-8859-1 else { #$body = $body . "\n" . to_utf8({ -string => $body, -charset = +> 'ISO-8859-1' }); } print OUTPUT $body . "\n"; print OUTPUT "##-------------------------------- End $date ------- +------------------------##\n"; close(OUTPUT); print LOG "$date --- Filter address found. $to has been forwarded +to $forward_address\n"; } if (!$store) { print LOG "$date --- No filter address found. $to has been forwar +ded to $forward_address.\n"; } ##Close the log file close (LOG); $dbh->disconnect();

In reply to Mail::Audit Resend Never Arrives by tertullian01

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.