I was going to suggest to keep track of message IDs in a hash with each reply being a value for the parent message. To figure out the "Message-ID:" & "In-Reply-To:" values to extract, i saw " $obj->threads([FOLDERS], OPTIONS)" in "Mail::Box::Manager" pod.
So, try the following & see if it makes any difference ...
#!perl use warnings; use strict; use Mail::Box::Manager; my $mgr = Mail::Box::Manager->new( 'default_folder_type' => 'mbox' ) ; foreach my $mb ( @ARGV ) { my $mbox = $mgr->open( 'folder' => $mb ) or do { warn "Can't open $mb"; next; }; my $threads = $mgr->threads ( 'folders' => [ $mbox ] , 'timespan' => 'EVER' , 'window' => 'ALL +' ); save_thread( $_ ) for $threads->all ; $mgr->close( $mbox ); } { my ( $count , @stat ); sub save_thread { my ( $thread ) = @_; # Generate file name. my $file = 'thread-' . sprintf '%05d' , ++$count; my $save = $mgr->open( 'folder' => $file , 'access' => 'rw' , 'create' => 1 +) or die "Cannot open $file to save the thread.\n" ; push @stat , [ $count , $thread->numberOfMessages ]; $_->copyTo( $save ) for $thread->threadMessages ; $mgr->close( $save ); } sub END { print_stat(); } sub print_stat { my $out = ''; my ( $total_thr , $total_msg ) = ( 0 ) x2; foreach my $s ( @stat ) { $out .= sprintf "%4d : %2d\n" , @{ $s }; $total_thr++; $total_msg += $s->[1]; } my $old = select STDERR; printf "Threads: %4d, Messages: %4d\n%s\n" , $total_thr , $total_msg , join '' , qw( =- ) x20 ; print $out; select $old; } }
For my test case, mind that above code generates triplicates in some cases (but "mutt(1)" does not have the problem in generating threads). In addition, while "mutt" notices 602 threads, above code produces 675 (but that could be /in some part/ due to various threading options that are set for "mutt"). I can provide the original file and those created by "Mail::Box*" if anybody is interested.
*Update, May 23 2006* Added a simple sub to print the statistics; removed unused "Mail::Message" usage.
In reply to Re: Organising mbox into threads?
by parv
in thread Organising mbox into threads?
by LoonyPandora
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |