• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 586
  • Last Modified:

MIME-tools help?

I am trying to make friends with MIME-tools (from http://www.zeegee.com/code/perl/MIME-tools) but i am not having much luck ( since i am really quite lousy on PERL).

What i want is an example of a piece of code that simply takes a message on STDIN, Decodes it, and writes all mime attachments to files, with the filenames suggested in the attachments. I am sure i will be able to make more sense of it if i have a complete example to work from.
  • 2
1 Solution
use MIME::Parser;

$parser = new MIME::Parser;

# read STDIN
$entity = $parser->read(\*STDIN) or die "couldn't parse MIME stream";

# to get message headers:
$head = $entity->head;
print $head->as_string;
print "\n\n";

# message parts
foreach $part($entity->parts) {
  # do something with message part
  # prints path to extracted file
  print $part->bodyhandle->path;
  print "\n";

  # prints mime-type
  print $part->head->mime_type;
  print "\n";
j2Author Commented:
Works excellent. But uhm.. call me stupid, but what exactly does the writing of the attachments? I mean, i see where it outputs path/type.. but where does the file itself get written?

Thanks :)
j2Author Commented:
And.. uhm, if i only wanted to save parts that were image/jpeg and discard the rest? (I am getting automatical mailings with graphs from a test equipment, but it also attaches a (for my part) useless text part aswell, that i would like to discard.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now