use Mail::Field; use Mail::Address; use Mail::Header; use Mail::Util qw ( read_mbox ); use Mail::Internet; use Time::ParseDate; sub clean { local ($res)=@_[0]; $res=~s/\;/SEMICOLON/g; $res; } @res=read_mbox("bugmail"); #@res=read_mbox("mail/bugdb.9903"); #@res=read_mbox("tmp1"); open BUGS, ">mailbugs"; #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")); $name="";$user="";$host=""; if (scalar(@addrs)>0){ $name=$addrs[0] ->name (); $user=$addrs[0] ->user (); $host=$addrs[0] ->host (); }else{ $name=$head ->get ("From"); } #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;} } $nn1++; #The following line must be pr number chomp($x[$nn1+1]); if ($x[$nn1+1]=~/^>Number:\W+([0-9]+)/){ $pr=$1;$mod="";$date="";$status="";$sev="";$pri="";$comment=""; foreach $i ($nn1 .. $#x){ if ($x[$i] =~ /^>Category:\W*([^\n]+)/){ $mod=$1; } if ($x[$i] =~ /^>Arrival-Date:\W*([0-z][^\n]+)/){ $date=$1; } if ($x[$i] =~ /^>State:\W*([0-z][^\n]+)/){ $status=$1; } if ($x[$i] =~ /^>Synopsis:\W*([0-z][^\n]+)/){ $comment=$1; } if ($x[$i] =~ /^>Severity:\W*([0-z][^\n]+)/){ $sev=$1; } if ($x[$i] =~ /^>Priority:\W*([0-z][^\n]+)/){ $pri=$1; } } if ($status eq "open"){ $status="$status:$sev:$pri";} $date=parsedate($date); $mod=&clean($mod);$status=&clean($status);$name=&clean($name); $date=&clean($date);$comment=&clean($comment); print "$pr\;$mod\;$folderline\;$status\;$name:$user\@$host\;$date\;$comment\n"; }else{ $subj=$head ->get("Subject"); $subj=~tr/[A-Z]/[a-z]/; $pr="";$mod=""; #if ($folderline == 132353){$subj=~/re: ([^\/]+)\/([0-9]+)/;print STDERR "$subj\;$2\;$1\n";} if ($subj=~/re: ([^\/]+)\/([0-9]+)/){ $pr=$2;$mod=$1; #if ($folderline == 132353){print STDERR "worked\;$2\;$1\;$pr\;$mod\n";} }else{ if ($subj=~/([^\/]+)\/([0-9]+)/){ $pr=$2;$mod=$1; }else{ if ($subj=~/changed information for pr ([^\/]+)\/([0-9]+)/){ $pr=$2;$mod=$1; }else{ print STDERR "$folderline\;$subj"; @x=@{ $res[$message] }; $folderline+=scalar(@x); next; } } } $comment="";$status="";$name="";$date=""; foreach $i ($nn1 .. $#x){ if ($x[$i] =~ /^Synopsis:\W*([^\n]+)/){ $comment=$1; } if ($x[$i] =~ /^State-Changed-From-To:\W*([^\n]+)/){ $status=$1; } if ($x[$i] =~ /^State-Changed-By:\W*([^\n]+)/){ $name=$1; } if ($x[$i] =~ /^State-Changed-When:\W*([^\n]+)/){ $date=$1; } } $date=parsedate($date); $mod=~s/changed information for pr //; $mod=&clean($mod);$status=&clean($status);$name=&clean($name); $date=&clean($date);$comment=&clean($comment); print "$pr\;$mod\;$folderline\;$status\;$name\;$date\;$comment\n"; } @x=@{ $res[$message] }; $folderline+=scalar(@x); }