use Time::ParseDate; use Mail::Field; use Mail::Address; use Mail::Header; use Mail::Util qw ( read_mbox ); use Mail::Internet; sub clean { local ($res)=@_[0]; $res=~s/\;/SEMICOLON/g; $res=~s/\n/NEWLINE/g; $res; } @res=read_mbox("nhmail"); #@res=read_mbox("mail/nh.9903"); #@res=read_mbox("tmp1"); #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"); } $subject = $head ->get ("Subject"); chop($subject); $subject=&clean($subject); $name=&clean($name); $user=&clean($user);$host=&clean($host); $date = parsedate($head ->get ("Date")); $tmp=$subject;$tmp=~tr/[A-Z]/[a-z]/; $isRe="no"; if ($tmp =~ /^re:/){ $isRe="yes"; } $isPatch0="no"; if ($tmp =~ /\[patch\]/){ $isPatch0="yes"; } #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;} } $isPatch=0; foreach $i ($nn1 .. $#x){ if ($x[$i] =~ /^Index:/){ $isPatch = 1; } } print "$folderline\;$date\;$name\;$user\@$host\;$isRe\;$isPatch0\;$isPatch\;$subject\n"; @x=@{ $res[$message] }; $folderline+=scalar(@x); }