Hi, I'm trying to parse information out of the body of what I believe is a base64 encoded email:
Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: base64
I'm mostly a perl novice. I'm trying to use MIME::Parser, which I believe is the best module for doing this. I've read practically every google response on how to use this module that exists, and still don't understand how to get the decoded version of the body.

The decoded message is written to disk by default, but I don't understand how to store the decoded body in an array so I can manipulate it.

http://www.perlmonks.org/bare/?node_id=188084

I've even followed this extensive example, and it also doesn't appear to decode the body.

A short, simple example would be most appreciated.

I've written the following bit of code, but it doesn't appear to go into the for-loop:

#!/usr/bin/perl -w use strict; use MIME::Parser; my $tmp_dir = '/tmp/parser-dir'; my $parser = MIME::Parser->new; mkpath($tmp_dir) unless -d $tmp_dir; $parser = MIME::Parser->new( ); $parser->extract_uuencode(1); $parser->extract_nested_messages(1); my $entry = $parser->parse(\*STDIN); for my $part ($entry->parts) { # dig into the parts if($part->mime_type eq 'multipart/alternative') { for my $a ($part->parts) { if($a->mime_type eq 'text/plain') { $part = $a; last; } } } my $mime = $part->mime_type; if($mime =~ m'text/.+' && !$found_msg++) { my $fh = $part->open('r'); if($fh) { while(defined(my $line = $fh->getline)) { $line =~ s/[\r\n]//g; push(@message, $line); } $fh->close; } } }

In reply to Need help parsing email using MIME::Parser by gossamer

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.