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 ); }; };

In reply to MIME::Tools to save attachment properly by gcasa

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.