postfix x-headers

In my post last week about the X-Clacks-Overhead HTTP header I mentioned that I had added the header to my postfix configuration as outlined in the advice given at gnuterrypratchett.com. As it turns out that advice does not work exactly as I wanted.

Firstly, and most importantly, using the “header_checks” table is sub-optimal because it adds the header to both outgoing and incoming email. This has the effect that all mail coming in to me (or any of the multiple other email accounts handled by my postfix server) now contains the header so I can’t be sure whether or not the outside originating server added the header or it came from me.

Secondly, for our purposes, the “/^X-Clacks-Overhead:/ IGNORE” line in the sample header_checks file is redundant – all that is necessary is the instruction to postfix to prepend the “X-Clacks-Overhead:” line to the existing header of your choice.

A much better approach I have found is to use the “smtp_header_checks” instruction to postfix – that way the header is only added to mail leaving our server. The postfix manual says:

smtp_header_checks (default: empty)

Restricted header_checks(5) tables for the Postfix SMTP client. These tables are searched while mail is being delivered. Actions that change the delivery time or destination are not available.

Thus the instructions at gnuterryprachett.com would be improved if it said:

Step 1: Where to put it:
/etc/postfix/main.cf
Step 1: What to add to main.cf:
smtp_header_checks = regexp:/etc/postfix/smtp_header_checks
Step 2: Where to put it:
/etc/postfix/smtp_header_checks
Step 2: What to add to smtp_header_checks:
/^Subject:/i PREPEND X-Clacks-Overhead: GNU Terry Pratchett

You could prepend the text to any existing header which you are sure will appear in the outgoing email. I chose “Subject” because all of my outgoing email has that header. Of course if I leave the Subject field empty in any email, then the X-Clacks_Overhead header will not be added.

I’ve emailed the admin of gnuterrypratchett.com.

Permanent link to this article: https://baldric.net/2023/03/14/postfix-x-headers/