Your question is a little confusing. Is it a mbox folder on a local machine or a folder on a remote machine?
In case of the former, you may not want to process each message line by line, to be fast. The messages are separated by lines starting with 'From '. But how do you know which messages to delete? Using MailBox, you could write
script:
while(my $msg = Mail::Message->read(\*STDIN))
{ $msg->write if $want_to_keep_it;
}
./script <large >smaller
That's not the best way to process folders, but most
memory preserving.
In case of a remote folder, you can open it using MailBox. It is a lazy implementation: only the messages you touch will be dowloaded. If you only touch the header, then only the header is downloaded. Even for large folders, memory consumption may stay in limits.
Sometimes, you should process a file in batches: download and process a few, than reopen the folder and process another few.
In any case, if you have huge sets of data, your code become more complicated.
Concluding: as author of MailBox, I didn't receive any complaints about installation or test problems from you. That means that the (maybe) misfunction of the module is your problem! Make it my problem! |