2

How can I configure Postfix, Dovecot, and/or SpamAssasin to reject all incoming and outgoing emails with empty subject line emails?

I am running on a Debian 8.6.

KingsInnerSoul
  • 201
  • 2
  • 10

1 Answers1

4

If you want to REJECT the mail, which would be a good idea as it also informs the sender that you don't want to receive mail with empty subject, you should use Postfix header_checks.

Add header_checks = pcre:/etc/postfix/header_checks to your main.conf and then add there this regular expression for empty Subject:

/^subject: *$/   REJECT  Please add subject to your mail.

In order to use this Perl Compatible Regular Expression you must have Postfix PCRE map support (from package postfix-pcre) installed.

Only limitation with header_checks is that it cannot recognize if the Subject field is totally missing. This problem you could address by scoring it higher on SpamAssassin. For global configuration /etc/spamassassin/local.cf and for user configuration ~/.spamassassin/user_prefs add:

score MISSING_SUBJECT          30

If you need to REJECT mails without Subject header, not just flag and/or quietly remove the mail, you can make SpamAssasin reject mail based on score by using it as a proxy-filter for Postfix.

Esa Jokinen
  • 43,252
  • 2
  • 75
  • 122
  • Did not work for me. I edited `/etc/posftfix/main.cf` and then restarted the service - and now I get `header_checks map lookup problem -- message not accepted, try again later` and `warning: maildrop/08E14833B6: error writing B4C1481F54: queue file write error` and `warning: pcre:/etc/postfix/header_checks is unavailable. unsupported dictionary type: pcre` and `warning: pcre:/etc/postfix/header_checks lookup error for "Received: by FQDN (Postfix, from userid 33)` – KingsInnerSoul Apr 03 '17 at 22:04
  • I have installed that, and the install was OK. When I run ` postconf -m` I get mysql but not pcre. – KingsInnerSoul Apr 04 '17 at 13:32
  • Thank you. I had to install `postfix-pcre` on top the `postfix-mysql`. It works now (PS, I added that note to your answer) – KingsInnerSoul Apr 04 '17 at 13:39
  • I rejected your edit because it seemed like it would be better as answer on its own. – chicks Apr 04 '17 at 13:43
  • @EsaJokinen Please erase that comment. You do not need `postfix-mysql`. You need `postfix-pcre` under Deb/Ubuntu/etc. MySQL/postfix-mysql & any assoc libs has nothing to do with the question at all (or answer). Consult. = http://www.postfix.org/PCRE_README.html / https://packages.ubuntu.com/groovy/postfix-pcre – B. Shea Oct 16 '20 at 15:26
  • 1
    @bshea: Thanks. Done. – Esa Jokinen Oct 16 '20 at 17:41