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 ?


In reply to Display filenames in mbox folder by peterr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.