Quick and dirty fix for corrupted mailbox

I run an old mail server using exim4 which stores its files in mbox format.

My inbox isn’t exactly small these days and I get a large volume of mail, mostly spam unfortunately. Sometimes exim4 has a glitch and corrupts the mailbox. The symptoms are always the same, the start of the mbox file is messed up with some random binary garbage. It always occurs at the very start of the file like this example:

LÍfO@+Yðe
~Ó¹ôêÞ:[çknñPùJ꣺U´-ëüµOi;õ¨ÿ-R$!8öµD¨%wÇßC`
(MʱÔ)wiÎ}1Þméõx¤¾GÊ6DFx£MVLZ¦B{TåQ}­ÃÈÍ ©F!¿ã¶Ùìããé!÷EúýD»Ü>W~sÃ.131.81])
        by adamserver with esmtp (Exim 4.69)
        (envelope-from )
        id 1O7eM3-000229-SH
        for adam@siliconsparrow.com; Fri, 30 Apr 2010 10:45:20 +1000
Received: by p14.nnj.simupt.com (Postfix, from userid 33)
        id 41A4CA7E0; Fri, 30 Apr 2010 00:36:38 +0000 (UTC)
To: adam@siliconsparrow.com
Subject: Hello
...

Now trying to edit a 2GB mbox file using vi or nano is akin to torture so here’s my quick and dirty method which simply deletes the first message in the inbox using the commandline tool awk. I have used this technique 5 or 6 times in the last year with success.

NOTE: Make sure you shut down your SMTP server, POP3 and IMAP servers before you run this.

cd /var/spool/mail
mv adam adam-corrupt
tail -c +500 adam-corrupt | awk '/^From /,0' > adam
chown adam adam

2 thoughts on “Quick and dirty fix for corrupted mailbox

  1. Jacob Miller

    Hey I’ve been trying to find you for a short while and found your previous website on Warcraft 2 installs with DOSBOX. I would really appreciate your support with this as it seems you helped a LOT of people with that, and I would love to have you help me with setting up Warcraft 1. Sorry if I had to do this on your post (I couldn’t figure out how to message you on here). Please get back to me, I’d really love to be able to play my favorite game from back in the day Thanks!

    -Jacob Miller
    PS: Please contact me by method of e-mail zombies1234597@gmail.com thanks again!

Comments are closed.