Discussion:
[Mimedefang] Question about resend_message() (Sendmail)
John Von Essen
2018-10-18 13:15:40 UTC
Permalink
So Im finishing up my MD setup. I want clean mail delivered to my local user account, Spam I want sent to another alternate local user account. So instead of quarantine, the spam goes to a dedicated spam account where I can check it manually every once in a awhile. So my MD filter code looks like this:


$SpamBox = '***@localhost';

if ($hits < $req) {
action_change_header("X-NoSpam-Score", "$hits ($score) $names");
}
if ($hits >= $req) {
action_change_header("X-Spam-Score", "$hits ($score) $names");
resend_message($SpamBox);
action_discard();
}


The resend_message puts the spam in Sendmail’s clientmqueue, but…. 5 mins later when the queue flushes, the “resent” message gets delivered, which means it goes through MD again, which in turn gets filtered again by MD, resulting in a loop because it keeps getting flagged as spam then resent again.

Whats the easiest way to avoid this loop? Is there a way to put the message directly into the alternate mailbox (maybe add_recipient then delete_recipient)? The obvious option is I can add a snippet of code to MD to catch the loop and not perform a spam check on anything going to that alternate box.

Thanks
John
_______________________________________________
NOTE: If there is a disclaimer or other legal boilerplate in the above
message, it is NULL AND VOID. You may ignore it.

Visit http://www.mimedefang.org and http://www.roaringpenguin.com
MIMEDefang mailing list ***@lists.roaringpenguin.com
http://lists.roaringpenguin.com/mailman/listinf
Dianne Skoll
2018-10-18 13:30:53 UTC
Permalink
Hi,
Post by John Von Essen
if ($hits >= $req) {
action_change_header("X-Spam-Score", "$hits ($score) $names");
resend_message($SpamBox);
action_discard();
}
Rather than using resend_message to resend the message, if you have
a new-enough version of Sendmail you can use delete_recipient to delete all
of the original recipients and then add_recipient to add $SpamBox as
a recipient. You have to loop over @Recipients to delete all the
original recipients.

Otherwise, you could add a magical header to the message and look for
it the next time around. You have to be careful to (1) delete the
magical header before letting the mail go out if it's not being
redirected, and (2) only trust it if the mail does originate from
localhost.

Regards,

Dianne.
_______________________________________________
NOTE: If there is a disclaimer or other legal boilerplate in the above
message, it is NULL AND VOID. You may ignore it.

Visit http://www.mimedefang.org and http://www.roaringpenguin.com
MIMEDefang mailing list ***@lists.roaringpenguin.com
http://lists.roaringpenguin
John Von Essen
2018-10-18 13:57:40 UTC
Permalink
So I tried this:

$SpamBox = '***@localhost';

if ($hits < $req) {
action_change_header("X-NoSpam-Score", "$hits ($score) $names");
}
if ($hits >= $req && $hits < 15) {
action_change_header("X-Spam-Score", "$hits ($score) $names");
delete_recipient('***@essenz.com');
add_recipient($SpamBox);
}
if ($hits >= 15) {
action_discard();
}

And it appears to work. But I am concerned about spammers trying to use alternate means of delivery, like my username @ FQDN, which is ***@bjork.essenz.com not ***@essenz.com which is done in Sendmail’s virtusertable.

If I call delete_recipient(); with no argument, does it act as a catch-all and delete “ALL” recipients?

Or do have do something like:

foreach(@Recipients)
{
delete_recipient($_);
}

Then

add_recipient($SpamBox);

Or could I just null the @Recipients array (@Recipients = (); add_recipient($SpamBox);)

It is a current Sendmail, and this server only serves one email user, me…

-John
Post by Dianne Skoll
Hi,
Post by John Von Essen
if ($hits >= $req) {
action_change_header("X-Spam-Score", "$hits ($score) $names");
resend_message($SpamBox);
action_discard();
}
Rather than using resend_message to resend the message, if you have
a new-enough version of Sendmail you can use delete_recipient to delete all
of the original recipients and then add_recipient to add $SpamBox as
original recipients.
Otherwise, you could add a magical header to the message and look for
it the next time around. You have to be careful to (1) delete the
magical header before letting the mail go out if it's not being
redirected, and (2) only trust it if the mail does originate from
localhost.
Regards,
Dianne.
_______________________________________________
NOTE: If there is a disclaimer or other legal boilerplate in the above
message, it is NULL AND VOID. You may ignore it.
Visit http://www.mimedefang.org and http://www.roaringpenguin.com
http://lists.roaringpenguin.com/mailman/listinfo/mimedefang
_______________________________________________
NOTE: If there is a disclaimer or other legal boilerplate in the above
message, it is NULL AND VOID. You may ignore it.

Visit http://www.mimedefang.org and http://www.roaringpenguin.com
MIMEDefang mailing list ***@lists.roaringpenguin.com
http://lists.roa
Dianne Skoll
2018-10-18 14:16:51 UTC
Permalink
On Thu, 18 Oct 2018 09:57:40 -0400
Post by John Von Essen
If I call delete_recipient(); with no argument, does it act as a
catch-all and delete ALL recipients?
Nope.
Yup. You could wrap it in a delete_all_recipients() function if you like.
Post by John Von Essen
add_recipient($SpamBox);)
Nope. Anything you do in your filter that only affects memory within
the Perl process has absolutely no effect on Sendmail. You have to
call one of the functions that communicates with Sendmail to actually
affect anything.

If you look at the source, you'll see that delete_recipient and
add_recipient make notes in the RESULTS file that ask the C code to
call appropriate milter functions to *actually* make the changes.

Regards,

Dianne.
_______________________________________________
NOTE: If there is a disclaimer or other legal boilerplate in the above
message, it is NULL AND VOID. You may ignore it.

Visit http://www.mimedefang.org and http://www.roaringpenguin.com
MIMEDefang mailing list ***@lists.roaringpenguin.com
http://lists.roar

Loading...