gcasa has asked for the wisdom of the Perl Monks concerning the following question:
Good Day Monks! Thank You for sharing your wisdom!!!
I am attempting to save an "attachment" from an email. My code saves the present attachment which is a 7-zip file. Alas, when I attempt to open the file with 7-zip, it balks stating the file is not an archive.
I have pieced my code together from the examples I have found. Most examples seem to elaborate on constructing a message. I am wanting to deconstruct a message. :-)
What have I done wrong?
Thank You again for sharing your time and knowledge!!!
glenn
=====
#!/usr/bin/perl -w use Carp; use MIME::Parser; use strict; use warnings; my $parser = MIME::Parser->new( ); $parser->output_under( "tmp" ); #write attachments to disk my $entity = $parser->parse(\*STDIN); # die( )s if can't parse my $header = $entity->head( ); # object--see docs my $preamble = $entity->preamble; # ref to array of lines my $epilogue = $entity->epilogue; # ref to array of lines my $num_parts = $entity->parts; my @parts = $entity->parts; #get email headers my $from = $header->get('From'); my $to = $header->get('To'); my $subject = $header->get('Subject'); chomp( $from ); chomp( $to ); chomp( $subject ); print " From: $from\n"; print " To: $to\n"; print " Subject: $subject\n\n"; print "Number of Parts: $num_parts\n\n"; print " Head: $header\n"; print " Preamble: $preamble\n"; print " Epilogue: $epilogue\n"; print "________________\n\n"; if( $num_parts > 0 ) { # more than one part my $part; for $part( @parts ) { # get mime type my $type = $part->mime_type; my $bh = $part->bodyhandle; print "MIME Type: $type\n"; my $content .= $bh->as_string if defined $bh; open( my $OUTFILE, ">", "output.7z" ); print $OUTFILE "$content"; close( $OUTFILE ); }; };
|
---|