BADMSG 3 [ Charlie ] : Malformed Message Removal Script

Quick cut-and-paste one-line installation as root:

wget http://www.chamorro.us/rrr/badmsg.install; . badmsg.install;

QMail appears to have a problem handling headers for some messages. The reason is unclear. It may be foreign character sets, it may be bad mail software, it may be incomplete SMTP sessions, or it may be the result of a bug within QMail. If I had the source to Plesk's version of QMail, I might be able to find the exact line which causes this problem. The end result is that Outlook Express and related mail clients get stuck trying to download e-mail if they come across one of these messages. Sometimes the subject line is <nbsp> , sometimes there's half a Message-ID like this:

Return-Path: 
Delivered-To: 10-anonymous@anonymous.com
Received: (qmail 31311 invoked from network); 4 Jul 2004 22:08:36 -0000
Received: from acb6119b.ipt.aol.com (172.182.17.155)
  by server.anonymous.com with SMTP; 4 Jul 2004 22:08:36 -0000
Received: from 123.123.123.123 by 123.123.123.124; Sun, 04 Jul 2004 15:59:00 -0700
Message-ID: <Z[20

After staring a several of these messages, I decided that the only common characteristic they shared were that they were small ( under 1000 bytes for sure, and usually under 500 ) and that they were always missing the 'To:' header. 'From:' and 'Date:' also were rare, but 'To:' was never there. Armed with that finding, I decided to write a minor script which would remove any message under 1000 bytes which did not have that 'To:' header.

The result is the badmsg script. It simply finds all messages under MAXSIZE, then performs a grep for the header. Any message not conforming is moved to another directory.

Version 2 ( previously 9 ) of this script includes all functionality in a single script rather than spreading it out over hourly, daily, and weekly scripts. The hourly invocation is the -x (eXecute) option. The weekly archiving invocation is now the -a (Archive) option. There is now a monthly upgrade / update function ( -u ) which will automatically download and install the latest version if there any bugs which need to be fixed. There is no longer a need for a daily script generator since there are now a couple of 'FIND' commands which will search for your Maildirs under /var/qmail/mailnames/ or any MAILROOT which you define.

The malformed messages collected by badmsg in the $BADROOT/box directory need to be summarized, reported, and archived. This is done by the weekly invocation ( badmsg -a ). Malformed messages are concatenated together, mailed to the the $MAILTO address with a Subject line specified by $MAILSUBJ and then archived in $BADROOT/ar . Archiving is done by using tar and gzip to create date-stamped tarballs. All of these variable are found in the badmsg.conf file. This is the only file which should be administratively modified. It should be placed in /etc/ .

Version 3 ( Charlie ) of badmsg contained a bug which caused the upgrade from Version 2 ( Bravo ) to fail. Specifically, the new badmsg script was uploaded to the file system's root ( / ) instead of $BADROOT . If this happened to you, simply delete the badmsg scripts on ( / ), then reinstall the script from this website using the commands above. The current version is fixed and also includes some new features which were the reason for the upgrade in the first place:

  1. archived malformed messages are now GZipped
  2. automatic upgrade cron $CWD bug has been fixed.
  3. any archives older than 13 weeks ( 3 months ) are deleted
  4. maximum archive age can be modified using the $MAXWEEKS variable
  5. version numbering has been corrected so this is now version 3 ( Charlie )

Installation is done by the badmsg.install script. This is really a simple wrapper for the true installation invocation: badmsg -i . The script is downloaded using the wget utility. This script will also invoke the badmsg 8 uninstallation script if badmsg 8 is detected. Here are the two minimum commands you need to issue as root from the server command line:

wget http://www.chamorro.us/rrr/badmsg.install

. badmsg.install

Afterwards, if you want to customize anything, edit the /etc/badmsg.conf file. That's it! Any other updates will be posted at the page you're reading now . The original version of this script was used on about 20 servers, each a full webhosting company in it's own right. The most active servers gather about 1000 of these messages per week. Worldwide, the script has been downloaded over 200 times. The impetus for a public release came from these two Plesk Forum posts:

forum nbsp | forum 0x800

I hope it helps you keep your server BADMSG free! -- MoChaMan


badmsg 8 uninstall | badmsg 3 install | badmsg 3 | badmsg.conf sample
BADMSG 3 [ Charlie ] : Malformed Message Removal Script