peterr has asked for the wisdom of the Perl Monks concerning the following question:
I have been using the script below (from Mail::Box) to parse through an mbox folder. It displays how many files are in the folder and for each file, the attchments contents ..
#!/usr/bin/perl # Print the types of messages in the folder. Multi-part messages will # be shown with all their parts. # # This code can be used and modified without restriction. # Mark Overmeer, <*********@overmeer.net>, 9 nov 2001 use warnings; use strict; use lib '..', '.'; use Mail::Box::Manager 2.00; use Mail::Box::Dir; use File::Slurp qw( write_file ); my $outfile = 'output5.txt'; sub show_type($;$); # # Get the command line arguments. # die "Usage: $0 folderfile\n" unless @ARGV==1; my $filename = shift @ARGV; # # Open the folder # my $mgr = Mail::Box::Manager->new; my $folder = $mgr->open ( $filename , extract => 'LAZY' # never take the body unless needed ); # which saves memory and time. die "Cannot open $filename: $!\n" unless defined $folder; # # List all messages in this folder. # my @messages = $folder->messages; print "Mail folder $filename contains ", scalar @messages, " messages: +\n"; File::Slurp::write_file( $outfile, {append => 1 }, $folder->readMessag +eFilenames($filename) ); my $counter = 1; foreach my $message (@messages) { printf "%3d. ", $counter++; print $message->get('Subject') || '<no subject>', "\n"; show_type $message; } sub show_type($;$) { my $msg = shift; my $indent = (shift || '') . ' '; # increase indentation print $indent, " type=", $msg->get('Content-Type'), ', ' , $msg->size, " bytes\n"; if($msg->isMultipart) { foreach my $part ($msg->parts) { show_type $part, $indent; } } } # # Finish # $folder->close;
The number of fies is not correct, so I have modified it with the line
File::Slurp::write_file( $outfile, {append => 1 }, $folder->readMessageFilenames($filename) );I need to display the actual filename for each file found. Nothing is being written to the $outfile though. The documentation for "readMessageFilenames" is at Mail::Box::Dir How can I get the filenames to display please ?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Display filenames in mbox folder
by Anonymous Monk on Mar 01, 2015 at 00:56 UTC | |
by peterr (Scribe) on Mar 01, 2015 at 01:42 UTC | |
by Anonymous Monk on Mar 01, 2015 at 01:58 UTC | |
by peterr (Scribe) on Mar 01, 2015 at 03:16 UTC | |
by choroba (Cardinal) on Mar 01, 2015 at 07:13 UTC | |
|