#perl -Iblib/lib try.pl use Mail::Field; use Mail::Address; use Mail::Header; use Mail::Util qw ( read_mbox ); use Mail::Internet; @res=read_mbox("cvsmail"); #@res=read_mbox("mail/cvs.9905"); #@res=read_mbox("tmp1"); open MRS, ">mailmrs"; open DELTA, ">maildelta"; $MR=0; #keep track of lines read so far in the folder $folderline=0; foreach $message (0 .. $#res){ $MR++; @x=@{ $res[$message] }; $head = new Mail::Header [ @x ], Modify => 0, mail_from => COERCE; @tags=$head ->tags (); #use this to identify people my @addrs = Mail::Address->parse($head ->get ("From")); $nadr=$#addrs; $name=$addrs[0] ->name (); $user=$addrs[0] ->user (); $host=$addrs[0] ->host (); #figure out where the header ends (search for an empty line) $nn1=$#tags; foreach $i ($#tags .. $#x){ $tmp=$x[$i]; chomp($tmp); if ($nn1 == $#tags && $tmp eq ""){ $nn1 = $i;} } #The following line must be login, date, and time chomp($x[$nn1+1]); if ($x[$nn1+1]=~/^([0-z]+)\W+([0-9][0-9])\/([0-9][0-9])\/([0-9][0-9]) +([0-9][0-9]):([0-9][0-9]):([0-9][0-9])/){ $login=$1;$yy=$2;$mm=$3;$dd=$4; #get rid of the header and the login date stuff foreach $i (0 .. $nn1+2){ shift @x; } #remove " " offset from the rest of the file foreach $i (0 .. $#x){ $x[$i]=~s/^ //; } #find all occurances of Modified %mod=""; foreach $i (0 .. $#x){ if ($x[$i]=~/^Modified:/){ $mod{$i}++; } $x[$i]=~s/^Submitted by/Submitted-by/; } if (scalar (keys %mod) > 1){ print STDERR "problem: $folderline $login several modules\n"; } if (scalar (keys %mod) == 1){ #obtain cvs fields $head1 = new Mail::Header [ @x ], Modify => 0; @tags1=$head1 ->tags (); #print $#tags1 .":@tags1\n"; $line=$head1 ->get("Modified"); @lines=split(/\n/, $line); @subsystems=();@files=(); foreach $line (@lines){ #$line=~s/\n/ /g; $line=~s/ -----.+//g; $line=~s/ / /g;$line=~s/ / /g; $line=~s/ / /g;$line=~s/ / /g; $line=~s/^ //g;$line=~s/ $//g; ($subsystem, @filestmp)=split(/ /, $line); @files=(@files, @filestmp); } #print STDERR "@files\n"; #if there were modified files -- proceed if (scalar(@files) > 0){ #find the end of cvs fields $nn1=$#tags1;$nn0=$#tags1; foreach $i ($#tags1 .. $#x){ $tmp=$x[$i]; chomp($tmp); if ($nn1 == $#tags1 && $tmp eq "Revision Changes Path"){ $nn1 = $i-1; } if ($nn0 == $#tags1 && $tmp eq "Log:"){ $nn0 = $i+1; } } if ($nn1 < $nn0){ print STDERR "problem: $folderline $nn1 $nn0\n"; die (); } $comment=""; foreach $i ($nn0 .. $nn1){ $comment .= $x[$i]; } #print $comment; $nadd=0;$ndel=0;$filePath=""; #find the end of file modification comments $second=0; $nfiles=scalar(@files); while ($nfiles > 0){ foreach $i (0 .. $nn1-1){ shift @x; } $nn1=0;$nn0=0; foreach $i (1 .. $#x){ $tmp=$x[$i];chomp($tmp); if (!$second && $nn1 == 0 && $tmp eq ""){ $nn1 = $i-1; } if (!$second && $nn0 == 0 && $tmp eq "Revision Changes Path"){ $nn0 = $i+1; } if ($second && $nn0 == 0 && $tmp =~ /^Index:/){ $nn0 = $i-2;$nn1 = $nn0; } } if ($nn1-$nn0+1 > $nfiles) { $nn1 = $nn0 + $nfiles - 1;} $nfiles -= $nn1-$nn0+1; foreach $i ($nn0 .. $nn1){ $tmp=$x[$i];chomp($tmp); $tmp=~s/ / /g;$tmp=~s/ / /g; $tmp=~s/ / /g;$tmp=~s/ / /g; $tmp=~s/^ //g;$tmp=~s/ $//g; $tmp=~/([0-9]\.[0-9]+) (.[0-9]+) (.[0-9]+) (.+)$/; print DELTA "$MR\;$yy\;$mm\;$dd\;$1\;". substr ($2, 1,length($2)) ."\;". substr ($3, 1,length($3)) ."\;$4\;$login\n"; $nadd += substr ($2, 1,length($2)); $ndel += substr ($3, 1,length($3)); $filePath .="\:$4"; } $second=1; } #print STDERR "@files\n$filePath\n"; $nfiles=scalar(@files); $comment =~ s/\n/NEWLINE/g; $comment =~ s/\;/SEMICOLON/g; $filePath=~s/://; print MRS "$MR\;$yy\;$mm\;$dd\;$nfiles\;$nadd\;$ndel\;$login\;$name\;$user\@$host\;$comment\;$filePath\n"; } } } @x=@{ $res[$message] }; $folderline+=scalar(@x); }