#!/usr/bin/perl -w #output_dir("$dir"); $parser->extract_nested_messages(0); ### Parse a file or stdin. my $ifile; my $entity; if ($ifile = shift(@ARGV)) { $entity = $parser->parse_open($ifile) or die "parse failed\n"; } else { $entity = $parser->parse(\*STDIN) or die "parse failed\n"; } ### Is any further work needed for each generated file? chdir($dir) or die "$dir: cannot chdir: $!\n"; opendir(DIR, ".") or die ".: cannot read: $!\n"; my @files = textfiles(readdir(DIR)); closedir(DIR); my $eachmsg = new MIME::Parser; # new parser for each message. $eachmsg->output_dir("."); $eachmsg->extract_nested_messages(1); print "Message in $dir:\n"; for (@files) { my $eachent; my $mtype; if ($eachent = $eachmsg->parse_open($_)) { $mtype = $eachent->mime_type; print " + checking message $_... $mtype\n"; # We don't have to extract a plain-text message $eachent->purge if $mtype eq "text/plain"; } else { print " - message $_ not MIME\n"; } } exit(0); #--------------------------------------------------------------------- # Look for just the text files in a given list. sub textfiles { my @retval; foreach my $entry (@_) { push @retval, $entry if (-T $entry); } return @retval; } #--------------------------------------------------------------------- # Print a usage message from the comments and exit. sub usage { my ($emsg) = @_; use Pod::Usage qw(pod2usage); warn "$emsg\n" if defined $emsg; pod2usage(-verbose => 99, -sections => "NAME|SYNOPSIS|OPTIONS"); } sub manpage { use Pod::Man(); my $parser = Pod::Man->new(); open(STDOUT, "| groff -T ascii -man | gcat -s | less") || die "groff\n"; $parser->parse_from_file($0); close STDOUT || die "$myname: can't close stdout: $!\n"; $? = 1 if $? == 255; # from die exit($?); } #--------------------------------------------------------------------- # Print the UUID, current version, or source location. sub myuuid { my $UUID = $1 if q$UUID: 70a8604c-172d-3179-9c67-60b7d056f7e7 $ =~ /UUID: (.*) /; print "$UUID\n"; exit(0); } sub version { my $VERSION = sprintf("%d.%02d", q$Revision: 1.8 $ =~ /(\d+)\.(\d+)/); my $DATE = $1 if q$Date: 2009/08/06 22:48:48 $ =~ /Date: (.*) /; print "$myname $VERSION $DATE\n"; exit(0); } sub where { my $SOURCE = $1 /Source: (.*) /; print "file://$HOST", "$SOURCE\n"; exit(0); } #--------------------------------------------------------------------- __END__ =head1 NAME munpack - decode a message with multipart/mixed MIME attachments =head1 SYNOPSIS munpack [-hmuvw] [log ...] =head1 OPTIONS =over 4 =item B<-h> Print a brief help message and exit. =item B<-m> Print the manual page and exit. =item B<-u> Print the script UUID and exit. =item B<-v> Print the version and exit. =item B<-w> Print the source location and exit. =back =head1 DESCRIPTION B will decode a multipart/mixed message possibly containing other MIME messages, and store the results in a directory beneath the current one. If the directory B exists, it will be used as the workspace. Otherwise, a temporary directory will be created. =head1 AUTHOR Karl Vogel Oasis Systems, Inc. =cut