[Mimedefang] Filtering on sender, recipient, and subject at the same time
Craig Green
cgreen at sentex.net
Thu Jul 7 13:48:50 EDT 2005
McCarthy, Douglas J wrote:
>Hi -
>
> I'm using MD 2.44.
>
> What I'm trying to do is prevent automatically-generated mail
>from vacation-notification applications from going outside the company I
>work for. The logic I'm using in the filter_recipient subroutine in
>mimedefang-filter is basically:
>
>if ($sender =~ /@mycompany.com>?$/i) {
> if ($recipient !~ /@mycompany.com>?$/i) {
> if ($Subject =~ /Out of Office Autoreply/) { #Exchange vacation
>msg
> return ('DISCARD', "ok");
> }
> if (system("egrep '(^User-Agent: Vacation/|^X-Mailer: vacation
>)' $CWD/HEADERS")) { # UNIX vacation
>msgs
> return ('DISCARD', "ok");
> }
> }
>}
>if ($ip =~ /list.of.internal.systems'.IP.addresses.here/) {
> return ('ACCEPT_AND_NO_MORE_FILTERING', "ok");
> }
>return ('CONTINUE', "ok");
>
>
>I'm having a lot of problems with this.
>
>First off, the system(egrep) call isn't working. It's returning a
>"mimedefang-multiplexor[NNNN]: Slave N stderr: grep:
>/var/spool/MIMEDefang/mdefang-aNNNaaaaNNNNNN/HEADERS: No such file or
>directory" error. This doesn't seem right, because from what I can
>tell, that directory is indeed the right place for the HEADERS file to
>be. (Specifying ./HEADERS instead of $CWD/HEADERS doesn't work either.)
>
>Second off, $Subject isn't available from within filter_recipient. This
>would be okay, if I could egrep for the subject from the HEADERS file...
>but I can't, because of the "No such file or directory" error above.
>
>Any help you could give me would be greatly appreciated
>
>
If I'm not horribly, horribly mistaken, filter_recipient is called after
each RCPT TO: command during the SMTP conversation. RCPT is before the
DATA phase, when the headers--including the subject--would get
transmitted. Accessing HEADERS is giving "No such file" errors and
$Subject isn't available because at that point neither exists...
I'd do what you're trying in filter_end. Autoreplies would only go to
one person so you don't have to worry about multiple recipients and can
just use action_discard().
I also wouldn't use egrep to search the HEADERS file when you can just
access the headers within the MIME entity passed in, but I don't know if
2.44 supports that.
sub filter_end ($) {
my($entity) = @_;
if ($Sender =~ /\@mycompany.com>?$/i &&
$Recipients[0] !~ /\@mycompany.com>?$/i) {
my $header = $entity->head; # Extract a MIME::Head object from the
MIME::Entity object '$entity'.
if ($header->get('User-Agent') =~ /Vacation/ ||
$header->get('X-Mailer') =~ /vacation/ ||
$Subject =~ /Out of Office Autoreply/ ) {
action_discard();
}
}
# Spamassassin checks, etc.
}
Note: untested. YMMV.
Regards,
Craig.
------
More information about the MIMEDefang
mailing list