The following are patches written by me to solve problems I ran into at various times. They may or may not be helpful to you.
diagnoseio logfile program [ args ... ]
If diagnoseio sees that the environment variable RECORDIO is set it will open logfile for writing in append mode, print a header "Logging: <value of $RECORDIO>" and wrap recordio around program, sending the output to logfile. If RECORDIO is not set, diagnoseio simply runs program.
As the name implies, this should be used for diagnostics only. It doesn't handle multiple writes to logfile and refuses to run if it gets its file descriptors in a twist. You would run qmail-smtpd with
tcpserver [options] 0 25 diagnoseio /tmp/recordedio qmail-smtpd
Then, if you were experiencing funny behaviour from a machine with IP 172.16.23.5, for example, you'd edit /etc/tcp.smtp (or whatever) and put in a line like this:
Now remake /etc/tcp.smtp.cdb and SMTP sessions from that host will be logged to /tmp/recordedio. Don't forget to remove that entry once you've finished diagnosing your IO.
qmail-smtpd pid, qp log
The patch makes qmail-smtpd log a line similar to the following:
@4000000039b89c95026a89b4 mail recv: pid 8155 from <firstname.lastname@example.org> qp 8157
The pid allows you to match the message up with a given tcpserver process and the qp lets you find a particular delivery.
The patch applies cleanly if you've already applied my MySQL patches (and you wouldn't be here if you hadn't or weren't going to right?) but will also apply, albeit with a bit of fuzz, to a vanilla qmail source tree.
qmail-smtpd verbose logging
This patch extends the pid,qp log patch by also making qmail-smtpd log any denied relaying attempts.
MDaemon is a popular mail server used by sites who run NT networks (masochists) and have intermittent internet access. It supports SMTP via ETRN or can pick up its mail via POP3 for redistribution on the local network.
MDaemon parses the To: family of headers to work out which local user it should forward received mail to. Unfortunately many mailing lists do not provide a To: header, or if they do it doesn't provide useful information. MDaemon can fall back to parse any arbitrary header set by the administrator or, by default, will look for a for <email@example.com> section of the first Received: header it finds. for is an optional part of the RFC822 specification and is not written by all SMTP daemons.
Have a guess whether qmail writes it.
Good guess. This patch to qmail-smptd.c and received.c makes qmail-smtpd spit out sendmail-like Received: lines. Witness the following spam examples.
Received: from web5102.mail.yahoo.com (18.104.22.168) by brotteaux.babasse.com with SMTP; 31 Jul 2000 15:14:42 -0000 Message-ID: <firstname.lastname@example.org> Received: from [22.214.171.124] by web5102.mail.yahoo.com; Mon, 31 Jul 2000 17:14:13 CEST Date: Mon, 31 Jul 2000 17:14:13 +0200 (CEST)
Received: from unknown (HELO GRACIE.retailnet.com) (126.96.36.199) brotteaux.babasse.com with SMTP; 1 Aug 2000 14:29:11 -0000 Received: from pppnet.com ([188.8.131.52]) by GRACIE.retailnet.com Post.Office MTA v3.1.2 release (PO205-101c) ID# 0-43054U100L2S100) with SMTP id AAA441 for <email@example.com>; Tue, 1 Aug 2000 04:12:24 -0400 From: <firstname.lastname@example.org> To: <email@example.com>
As of 2000-08-07, this patch can (subject to your uncommenting a few lines) help really broken servers that can't even parse the above correctly. MDaemon, you see, will skip past qmail's first Received: header, in which it writes "qmail blabla invoked from network" to find the relevant one. Some kit can't even perform this simple task and will barf on the first header it finds. I've yet to see such a server that can't recognise X-Envelope-To:, however, and this patch can write it in.