Here are some code snippets you might find helpful, from stuff from work I wrote that I probably can't share in full:

my $p= MIME::Parser->new; $p->output_to_core(1); $p->parse($msg_or_fh);
# Find every MIME part which is not a container for other parts sub _leaf_parts { my @parts= $_->parts; @parts? ( map { _leaf_parts() } @parts ) : ( $_ ) } my @leaf_parts= map { _leaf_parts() } $email;
# Open a handle to each part which is an attachment my @attachments= map +{ name => $_->head->recommended_filename, content_type => _decoded_mime_header($_->head, 'Content-Type' +), handle => $_->bodyhandle->open('r'), mimepart => $_, email => $email }, grep length($_->head->recommended_filename//''), @leaf_parts; # Convert zipfile attachments to the list of files within @attachments= map { $_->{name} =~ /\.zip$/? _extract_zipfile($_) : +($_) } @attachments;
# Takes one file info, and returns a list of file infos for each file +within the zip file. # Since these are not directly MIME parts, they are simply: # { # name => $original_filename, # handle => $io_handle # } sub _extract_zipfile { my ($file)= @_; my @files; my $zipfile= IO::Uncompress::Unzip->new($file->{handle}) or die "Can't open zip file: $UnzipError"; my $status; for ($status= 1; $status > 0; $status= $zipfile->nextStream()) { my $name= $zipfile->getHeaderInfo->{Name}; $log->info("Extracting $name from zip file"); my $tmp= File::Temp->new(TEMPLATE => 'email-zip-content-XXXXXXX' +); my $buf; while (($status= $zipfile->read($buf)) > 0) { $tmp->print($buf) or die; } last if $status < 0; push @files, { name => $name, handle => $tmp }; } die "Error processing zip file" if $status < 0; return @files; }

In reply to Re: How to get started with scraping my IMAP emails by NERDVANA
in thread How to get started with scraping my IMAP emails by bliako

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.