[Mimedefang] filter_recipient problem (bug?)

Jan Pieter Cornet johnpc at xs4all.nl
Wed Aug 11 05:57:26 EDT 2004


On Wed, Aug 11, 2004 at 05:07:39PM +0800, Egor Moskvichev wrote:
> Hi, all!
> The problem is...
> Sometimes filter_recipient sub does not return recipient email address and
> sender ip-address.

No, it always does. The problem is the variable doesn't survive between
a call to filter_recipient and filter_begin. They are very often not
run in the same perl process.

See also the section "MAINTAINING STATE" in mimedefang-filter(5).

However, the solution is simple, as the information you are looking for
is also available in globals set by mimedefang. See the section
"GLOBAL VARIABLES SET BY MIMEDEFANG.PL" in mimedefang-filter(5).
Specifically, you need $RelayAddr (instead of $ip/$from_host)
and the @Recipients array (instead of $to_recipient).

You do realize a single email can be sent to multiple recipients,
right? Your current code doesn't really handle that gracefully.

> When i look through my mailstats i notice a few strings without $from_host
> and $to_recipient values.
> But messages itself are not empty and they look rather ordinarily.
> Who can tell me whats going on?
> Its very important for me, because i try to organize mail billing system.
> You can see my mimedefang-filter below for details.
> 
> Thank you,
> Egor Moskvichev
> 
> sub filter_recipient () {
>     my ($recipient, $sender, $ip, $hostname, $first, $helo, $rcpt_mailer,
> $rcpt_host, $rcpt_addr) = @_;
>     $from_host = $ip;
>     $to_recipient = $recipient;
>     return ('CONTINUE', "ok");
> };
> sub filter_begin () {
>     $email_time = scalar(localtime);
>     $email_size = -s "./INPUTMSG";
>     open(LOG, ">> /var/log/mailstats");
>     printf LOG "%-25s %-15s %-50s %s\n", ($email_time, $from_host,
> $to_recipient, $email_size);
>     close(LOG);
>     if ($from_host eq '') {
>         $filename = sprintf("%04d%02d%02d-%02d%02d", sub {($_[5]+1900,
> $_[4]+1, $_[3], $_[2], $_[1])}->(localtime));
>         use File::Copy;
>         copy("./INPUTMSG", "/var/log/$filename");
>     };
> };
> 1;
> 
> 
> _______________________________________________
> Visit http://www.mimedefang.org and http://www.canit.ca
> MIMEDefang mailing list
> MIMEDefang at lists.roaringpenguin.com
> http://lists.roaringpenguin.com/mailman/listinfo/mimedefang
> 

-- 
#!perl -wpl # mmfppfmpmmpp mmpffm <pmmppfmfpppppfmmmf at fpffmm4mmmpmfpmf.ppppmf>
$p=3-2*/[^\W\dmpf_]/i;s.[a-z]{$p}.vec($f=join('',$p-1?chr(sub{$_[0]*9+$_[1]*3+
$_[2]}->(map{/p|f/i+/f/i}split//,$&)+97):qw(m p f)[map{((ord$&)%32-1)/$_%3}(9,
3,1)]),5,1)='`'lt$&;$f.eig;                                # Jan-Pieter Cornet



More information about the MIMEDefang mailing list