1

I use Postfix to block terms in headers and bodies. In few cases, it blocks legitimate mails because the term used is present in a long string (probably an id or reference or a coded string).

For example:

/AQHV/ REJECT SPAM RULE #5

Emails containing the following text in their headers are rejected. Because the characters "AQHV" are in the one of the headers:-

Thread-Index: AQHVSEXnJ2u6futfzU6u85aNv7EgTg

I have tried to add a space before + after the term AQHV, like so:-

/ AQHV/ REJECT SPAM RULE #5

/AQHV / REJECT SPAM RULE #6

This error occurs:

postmap: warning: /etc/postfix/header_checks.db: duplicate entry: "/"

How can I tell Postfix to treat the term "AQHV" as a separate word only, and not as part of a string?

Thanks in advance!

tripleee: apologies for the comments - still struggling with these forums.

I have decided to uninstall Postfix and reinstall it again. It might solve this problem. I will accept your answer. Many thanks.

2
  • The error message sounds vaguely like you put these in the wrong file or something. Can you show how you have configured this db?
    – tripleee
    Commented Aug 1, 2019 at 14:35
  • They are put in /etc/postfix/header_checks file. Then: # postmap /etc/postfix/header_checks # service postfix restart
    – Quest
    Commented Aug 1, 2019 at 16:44

2 Answers 2

0

Try /\bAHQV\b/. Here \b is a regex word boundary marker.

6
  • Thank you for your response. This /\bAQHV\b/ hasn't worked for me. Tested an email with subject AQHV and it was not rejected. I am not using regex. As explained in the post, they are just terms followed by REJECT
    – Quest
    Commented Aug 1, 2019 at 16:46
  • Correction: I meant /\AQHV\b/ hasn't worked for me. The previous one was a typo
    – Quest
    Commented Aug 1, 2019 at 16:54
  • Then switch to regexp, or probably preferably the pcre filter type. The syntax with slashes is specific to the regex filters.
    – tripleee
    Commented Aug 1, 2019 at 16:57
  • The 2 lines were already added to main.cf:- header_checks = pcre:/etc/postfix/header_checks body_checks = pcre:/etc/postfix/body_checks Please point me in the right direction!
    – Quest
    Commented Aug 1, 2019 at 17:03
  • Just to add that the command: postconf -m shows that both pcre + regexp are installed.
    – Quest
    Commented Aug 1, 2019 at 17:21
0

Make sure you include this in main.cf:

header_checks = pcre:/etc/postfix/header_checks

Run these commands, assuming header_checks is in /etc/postfix/.

postmap /etc/postfix/header_checks
postfix reload

To deal with spaces in regex/pcre, you can comment them out. For example, if you wanted to reject any email with a space in the header, you could put this in header_checks:

/\ / REJECT NO SPACES ALLOWED!!!!

So, if you wanted to just block an email with a line in the header that contained AHQV, but just the string AHQV, not AHQV as a substring in a larger string, then this is the regex you need:

/\ AHQV\ / REJECT NO AHQV PLS

I hope this helps!!

1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Feb 8, 2022 at 15:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .