csplit and procmail

I had misconfigured my procmail slightly, which resulted in 223 mails ending up in an mbox rather than sorted into my maildirs. At least they weren’t lost!

After correcting my procmail setup came the next problem–how to get them all sorted out of the mbox? The easiest way seemed to be to re-deliver them. The procmail man-page says nothing about it being able to handle several emails at once. I didn’t feel adventurous, mails are too important! Instead I went looking and found a new command csplit. The following split my mbox into files containing one email each:

csplit mbox '/From /' '{*}'

The first file it creates, xx00, is of zero length, so I deleted that. Then I passed all files to procmail one at a time:

for f in *; do echo $f; procmail < $f; done

(It took so much time that I interrupted it once and added the “progress reporting”.)

One Comment

Comments are closed.