fixing a broken mbox that procmail thinks is a Maildir

fixing a broken mbox that procmail thinks is a Maildir

Today I made the wonderful discovery that gnome.org email was working fine, and that my attempts to subscribe to the f-spot-list were successful – at least, as far as sending me the request for confirmation makes it a successful transaction. Trouble is, procmail had been deciding for some time now to deliver certain mail to the wrong spot.

The short of it is this: if the \/ match command includes some whitespace in $MATCH, then procmail will treat something like this:

:0
.list.$MATCH/

as two targets, and skip the second part. For example, with the above recipe, a $MATCH of ’ f-spot-list' will end up telling procmail to deliver to thw two words .list. f-spot-list/, and will then tell you that it is skipping f-spot-list/ and delivering to .list.. However, in the process, procmail has seen the / at the end of the line and decided to remove the From_ magic from the start of the message when it is delivered to the mbox .list., and so you’ll end up with not only a new mbox that you didn’t want, but also one with a single message in it containing what you’d expect to be many messages.

So, first fix procmail to match out the whitespace before using the $MATCH variable, this is just sensible sanitising.

Second, move your broken mbox out of the way, so that we don’t duplicate mail when you inevitably break this process in a moment. Create a scratch directory, and cd into it.

% mkdir scratchmonkey
% cd scratchmonkey
% csplit ~/borken.mbox '/^Return-Path/' '{*}'

You want to make sure that the first line of your broken mbox messages are actually Return-Path: headers, otherwise adjust to suit. You also want to be doing this on a single message, so if you’ve got an mbox with correct message delimiters in it, first move them to the right place (formail -s procmail < ~/borken.mbox then find where the uber message got delivered, and move it out of the Maildir).

Now you’ve got a directory full of single files. There are now three ways to deliver them. If you like manual labour and also like to cheat death by breaking Maildir delivery protocol, you can just move these files to your inbox Maildir/new directory.

If you want safe delivery, but still like manual labour, try safecat:

% for i in xx*; do safecat Maildir/tmp Maildir/new < $i; done

If you’re certain your procmail is now correct, let it take care of the safe delivery and also the filtering job:

% for i in xx*; do procmail < $i; done

Check your mail, all the messages from the busted mailbox should now be safely stowed and visible to your MUA.