Parsing mailboxes

cmika_at_-takethisout-25thandclement.com
Date: 08/24/04


Date: Tue, 24 Aug 2004 08:23:24 -0700

Problem: Mozilla mailbox is way to big (800MBs).
Solution: Split it up.

#!/usr/bin/perl

############
# Splits Mozilla style Inboxes into smaller ones (max size = maxMailboxSize)
# use: ./splitMozilla <mailbox name>
# output: mailbox0 [mailbox1] [mailbox2] ...
############

$maxMailboxSize = 104857600;
$mailboxNumber = 0;
open OUTPUTFILE, ">mailbox$mailboxNumber";

while(<>) {
        if(/^From /) {
                if((stat(OUTPUTFILE))[7] > $maxMailboxSize) {
                        close OUTPUTFILE;
                        $mailboxNumber ++;
                        open OUTPUTFILE, ">Inbox$mailboxNumber";
                }
        }
        print OUTPUTFILE $_;
}

Problem: It's not working. It's creating mailbox0, writes about 1.9MBs, then
the system runs out of memory, which shouldn't happen. What I'm basically
trying to do is search for a new message, check if the outputfile is over
100MBs, if it is, create a new one, if it's not, then write the message to
outputfile. Any ideas?

-Chris Mika
cmika@-takethisout-25thandclement.com