[lug] qmail header re-writing

Jeff Schroeder jeff at neobox.net
Fri Jun 6 20:26:05 MDT 2003


Nate asked:

> Anyone know how to get qmail to rewrite headers and act as a
> smarthost? I have to figure that out here soon, I guess... and I'm
> getting the impression qmail's not going to cooperate and will have
> to be beaten into submission...

You can do this by applying the qmail-queue patch 
(http://www.qmail.com/qmailqueue-patch) and recompiling qmail.  Then, 
if you're running TCP server, just add the name of a shell script you'd 
like to run when messages are received.  For example, I have a TCP 
server ruleset for all SMTP connections, and it just looks like:

:allow,QMAILQUEUE="/var/qmail/bin/qmail-proc"

Then qmail-proc is a shell script:

#!/bin/sh
cat | /usr/local/bin/spamc | /var/qmail/bin/qmail-queue

Basically that will 'cat' any incoming message and send it to the 
SpamAssassin client (spamc) which rewrites the headers.  From there it 
goes to qmail-queue, where it's delivered to its final destination.

In your case, you could do some creative stuff with 'grep' or 'sed' to 
rewrite the headers however you want, e.g.:

#!/bin/sh
sed s/"From:.*"/"From: Your Mom"/ | /var/qmail/bin/qmail-queue

Voila, all messages are now coming from Your Mom. ;)

HTH,
Jeff



More information about the LUG mailing list