tertullian01 has asked for the wisdom of the Perl Monks concerning the following question:

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();

Replies are listed 'Best First'.
Re: Mail::Audit Resend Never Arrives
by sgifford (Prior) on Jun 29, 2005 at 18:39 UTC
    Here's a wild guess. If you're using sendmail, see what the MeToo setting is set to. If it's false, it will stop messages sent by a user to themselves from being delivered if the delivery is part of an alias expansion.

    Also, try looking in your mail server logs to see if it gives any hints.

      Thank you for your ingenious reply. I looked at the sendmail configuration and the MeToo line was commented out. From what I read on the subject the default value is false so this is probably the problem. Is there anyway to change this within the perl script I am running or will I just have to figure out a work around? I would change it in the server but it is not mine and I do not have write access to the configuration. Any ideas on how to change this within the script?
        You could try a -O MeToo=True option to sendmail. If that doesn't work, you could just use a different envelope sender to avoid the problem.