#!/usr/bin/perl # # To: procmail@Informatik.RWTH-Aachen.DE # From: mengwong@ICG.RESNET.UPENN.EDU (Meng Weng Wong) # Message-Id: <199512152031.PAA29505@icg.resnet.upenn.edu> # Subject: Re: Help splitting mail archives # Date: Fri, 15 Dec 1995 15:31:35 -0500 (EST) # # | 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 # ############################################################ # # 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 = (); 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 # ---------------------------------------------------------- exit (0);