procmail
[Top] [All Lists]

Re: Help splitting mail archives

1995-12-15 13:33:26
| 
| I was wondering if one of you formail experts can help me with the
| following problem.  I have a huge majordomo archive for a mailing list.  I
| want to separate it into several different files by the month in which
| they were sent.  How can I do this using formail? 
| 

the following perl script does something similar to what you
need.  it saves each message to a file with a unique name
based on the yyyymmddhhmi(.nn) where .nn goes from .01 up,
if two messages happen to have been sent at the same minute.
modifying it to do what you want should be easy.

cheers
meng

#!/usr/bin/perl

############################################################
#                 formail2yyyymmddhhmi.pl
# 
#                      Meng Weng Wong
#               Sun Oct  8 05:11:40 EDT 1995
# $Id: formail2yyyymmddhhmi.pl,v 1.1 1995/12/15 20:29:16 mengwong Exp $
# formail -s formail2yyyymmddhhmi.pl < mailbox
# will save each messge in that mailbox as files
# called yyyymmddhhmi(nn) based on the time sent.
############################################################

# ----------------------------------------------------------
#                      initialization
# ----------------------------------------------------------

@input = (<STDIN>);
close STDIN;
print STDERR ".";

# ----------------------------------------------------------
# no user-serviceable parts below this line
# ----------------------------------------------------------

%montomm = ("Jan", 1, "Feb", 2, "Mar", 3, "Apr", 4,
            "May", 5, "Jun", 6, "Jul", 7, "Aug", 8,
            "Sep", 9, "Oct",10, "Nov",11, "Dec",12);

for (keys %montomm) { $montomm{$_} = sprintf("%02d", $montomm{$_});
                      $mmtomon{$montomm{$_}} = $_; }

# format seems to be Sun Aug 22 10:10:30 1993
chop($firstline = $input[0]);

$firstline =~ s/^(From \S+\s+\S+\s+\S+\s+\S+\s+\S+\s+)\S+\s+(\S+)$/$1$2/;
($from, $sender, $dow, $mon, $dd, $time, $yyyy) =
    ($firstline =~ /^(From) (\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)$/);

$mm = $montomm{$mon};
$yyyy = "19$yyyy" if (length ($yyyy) == 2);

($hh, $mi, $ss) = split(/:/, $time);

$newname = sprintf("%04d%02d%02d%02d%02d", $yyyy, $mm, $dd, $hh, $mi);
if (-e $newname) { $newname .= ".01"; }
while (-e $newname) { $newname++; }
# print "$newname: $firstline\n";

open (OUT, ">$newname") || die "unable to open $newname for writing.\n";
print OUT @input;
close OUT;

# ----------------------------------------------------------
#                           end
# ----------------------------------------------------------

<Prev in Thread] Current Thread [Next in Thread>