Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MIME-tools help?

Posted on 2002-05-23
3
Medium Priority
?
579 Views
Last Modified: 2008-02-01
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.
0
Comment
Question by:j2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 6

Accepted Solution

by:
andreif earned 800 total points
ID: 7031368
use MIME::Parser;

$parser = new MIME::Parser;
$parser->output_dir("/path/to/target/dir");

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

# to get message headers:
$head = $entity->head;
$head->decode;
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";
}
0
 
LVL 12

Author Comment

by:j2
ID: 7031393
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 :)
0
 
LVL 12

Author Comment

by:j2
ID: 7031439
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.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question