BEFORE you go on, please check CPAN for the MIME-tools package, and read the documentation of MIME::Entity, MIME::Head, MIME::Body and MIME::Parser if you really want to parse emails correctly.

Else you are reinventing the wheel and yours won't be that round ...

Please be free to contact me if you need some demo code to show how the MIME-tools operate on your special task.

Update (some code snippets added)

use MIME::Parser; # some code here .... my $message = $pop->get($msg); # I get it from POP3 # parse email my $parser = new MIME::Parser; $parser->output_under($Conf::msg_dir); my $entity = $parser->parse_data($message); split_entity($entity); # example header my $from = $entity->head->decode->get("From"); ############################################################ sub split_entity { ############################################################ local $entity = shift; my $num_parts = $entity->parts; # how many mime parts? if ($num_parts) { # we have a multipart mime message foreach (1..$num_parts) { split_entity( $entity->parts($_ - 1) ); } } else { # we have a single mime message/part # we only want text if ($entity->effective_type =~ /^text\/(?!(html|enriched))/) { my $path = $entity->bodyhandle->path; ### do something here } else { my $path = $entity->bodyhandle->path; ### do something other here; } } }

This snippet is just for demonstration, it won't run.

alex pleiner <alex@zeitform.de>
zeitform Internet Dienste


In reply to Re: Email STDIN by projekt21
in thread Email STDIN by Anonymous Monk

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.