4

ATM I'm using the normal method to put all messages on HOLD to pass them from postfix to MailScanner as described on http://www.mailscanner.info/postfix.html:

In the Postfix configuration file /etc/postfix/main.cf add this line:

header_checks = regexp:/etc/postfix/header_checks 

In the file /etc/postfix/header_checks add this line:

/^Received:/ HOLD 

The effect of this is to tell Postfix to move all messages to the HOLD queue.

But I have some SMTP message that I have no need to pass them through MailScanner, messages identified by a custom header. I need to find a way to bypass MailScanner for these messages, but I can't find it, given I need to check the presence of a custom header and not i.e. the From: or To: address...

Tried modifying /etc/postfix/header_checks:

/^X-Custom-Header:/ FILTER smtp:[ip.addr.next.hop]:10025

in the mail.log I see the message filtered:

Aug 19 17:52:17 servername postfix/cleanup[19423]: AFB842E33A: filter: header X-Custom-Header: from relay.sender.foo[xx.yy.zz.kk]; from=<sender@senderdomain.foo> to=<me@mydomain.foo> proto=ESMTP helo=<mail.sender.foo>: smtp:[ip.addr.next.hop]:10025

and if the one above is the only rule in header_checks it's delivered to the next hop via smtp.

Now I need to catch everything else in the Mailscanner (so in the Postfix HOLD queue), so how can I tell header_checks to do that? If I leave the /^Received:/ check even the AFB842E33A is held in the HOLD queue...

Maybe is just a dumb question, but... any idea?

Zixyar
  • 43
  • 1
  • 4

1 Answers1

3

Yes there is even a solution. It is called header_checks and is part of the *_restrictions. The format (dependent on what you want) is described at it's own documentation.

But I can't recommend using after-queue-filters like Mailscanner and Spamassassin. The better way to reduce Spam and inform the sender are before-queue-filters like the built-in postscreen, client_restrictions, sender_restrictions, recipient_restrictions, before-queue milters and external tools like policyd-weight.

Only before-queue-filters reduce the load and resources on the server and can block 80% of all Spam before they even reach the server. Mailscanner in particular is on my personal "hate-list" as it only has a crippled integration into Postfix and is not able to use Postfix' built-in interfaces for anti-spam filters and filters in general.

Edit: Due to the edited question, I will answer that now.

FILTER is not an action that stops Postfix from working on the header_checks-file. It only tells "when I'm finished with the checks I'll filter". And so the next line matches and sets the mail on hold.

The solution (even if it looks crippled) is this header_checks-file:

/^X-Custom-Header:/ FILTER smtp:[ip.addr.next.hop]:10025
/^X-Custom-Header:/ OK
/^Received:/ HOLD    
mailq
  • 16,882
  • 2
  • 36
  • 66
  • Thanks, but I understood that the headers are parsed in the order they are in the message, so your `header_checks` won't work if the "Received" one is parsed before the "X-Custom-Header", thus queuing the message on HOLD. Also I thought that the check stops at the first occurrence, making the OK line useless... am I wrong? I tried it anyway, and in the mail.log I found first the "Received"-check putting the message on HOLD and only after that the "X-Custom-Header"-check FILTERing it, but to no avail since it's being processed by MailScanner. If that's confirmed I'll edit my question again. – Zixyar Aug 25 '11 at 14:43
  • 1
    1) You are right on the problem that the custom header is checked later than the other. 2) FILTER is no stop-action. 3) Workaround is to have 2 header check-files. The first file with the custom-header-thing and another file with the received-header-thing. Both chained in the header_checks. – mailq Aug 25 '11 at 16:41