| The two scripts finally used where quite simple. I'm just showing you some specialities:
The modified base64-Algorithm
Yes... I know: I did not want to tell it in the section above, but I'm showing
it here anyway because I do not want to receive mails of puzzled sysadmins that cannot
work it out. It's PHP-Code:
<?php
function decode_address($str){
return base64_decode(preg_replace('/\.([a-z])/e', "strtoupper('\1')", $str));
}
function encode_address($str){
return preg_replace('/([A-Z])/e', "strtolower('.\1')", base64_encode($str));
}
?>
Reading the address and flag it in the database
This is also really simple, I'm just showing it here in case you cannot understand
what I'm writing about in this tutorial (my PHP might be better than my English):
<?php
//...
$address = decode_address($argv[1]);
// $address now contains the address, the mail that
// just bounced was sent to
//...
$hsh = get_bounce_state($address);
$flag = $hsh['BounceFlag'];
if ($flag == BOUNCE_ERR) exit(0); //no error code. This would lead to
//bounce being generated. -> loop
/*
BOUNCE_ONCE is never the state of a mail that fails. The mailer-
script sets the Flag to bounce_check before sending the mail
*/
$old_flag = $flag;
if ($flag == BOUNCE_OK)
$flag = BOUNCE_ONCE;
elseif($flag == BOUNCE_CHECK)
$flag = BOUNCE_FAIL;
if ($flag != $old_flag)
set_bounce_flag($address, $flag);
/*
The code above is just twiddling with my whish to have two bounces
received before the message is blocked. I cannot just increment a
counter everytime I receive a bounce. And decrement when sending it
because I wanted to handle also the complex cases where mail was
bouncing sometimes and sometimes not...
*/
?>
Setting the envelope-From
This is the most important step: We want the Mails we generate to have
this special Envelope-From-Address where the bounces are to be sent to.
the PHP mail() function does not
allow this, so I was calling exim directely:
<?php
$env_from = 'webreply-'.encode_address($email).'@domain.com';
$exim = popen("/usr/local/exim/bin/exim -f $env_from $email", "w");
?>
For this to work, the user calling the command must be listed in the
trusted_users list of your exim.conf:
trusted_users = domain:root:pilif
(jepp. I always trust myself... mostly... at least when dealing with computers... sometimes.)
|