[wellylug] Mail processing

Don Jones don.jones at linuxmail.org
Tue May 6 19:56:45 NZST 2003


> If you are using mailboxes in mbox format and you wish to split the large file into individual files, there is a utility called formail which does the job. Syntax is a bit difficult - man formail.

heres a bit of perl I wrote at some stage that wraps formail:

----------------------------------------------------------
#!/usr/bin/perl -w
#
use strict;

my $number = $ARGV[0];
my $input = $ARGV[1];
my $output = $ARGV[2];

if (@ARGV != 3 ) {
        print "Usage: $0 number mbox output_number\nWhere number is the number of mails to process, mbox is the mbox file to process and output_number is the output directory\neg : $0 20 /home/don/spam/buzz /home/don/spam/spams/\n";
} else {
        foreach my $i (0 .. $number) {
                system "formail +$i -1 -ds < $input > ${output}email.$i";
                print "processing file number: $i (email.$i)\n";
        }
}
-----------------------------------------------
obviously error checking and the like could be fixed up (it was a one off script for splitting out some spam from a mbox testing)
to use : ./scriptname [number of mails to split off top of mbox] [mbox filename] [full path to directory for placing individual email files], check out man formail for fixing it to do what want
-- 
______________________________________________
http://www.linuxmail.org/
Now with e-mail forwarding for only US$5.95/yr

Powered by Outblaze



More information about the wellylug mailing list