Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Mail::Internet and attatchments

by stew (Scribe)
on Nov 11, 2003 at 11:59 UTC ( #306167=perlquestion: print w/ replies, xml ) Need Help??
stew has asked for the wisdom of the Perl Monks concerning the following question:

Hi there,
I have a support logging script that handles in-bound emails, logs them in a database and sends notifications to various recipients.
I'm using Mail::Internet to carve up a message on STDIN thus
$message = new Mail::Internet \*STDIN; $who_from = $message->head->get("From"); $sent = $message->head->get("Date"); $subject = $message->head->get("Subject"); $content = join('',@{$message->body} );

This works perfect apart from PHB now requires the system to handle attachments. To be honest I'm quite stumped as to what happens to any attachments. I've scouerd CPAN and this site to no avail.

As always, any advice most welcome, especially if anybody knows of another mod that will deal with attachments.

Cheers Stew

Comment on Mail::Internet and attatchments
Download Code
Re: Mail::Internet and attatchments
by Abigail-II (Bishop) on Nov 11, 2003 at 12:04 UTC
    Does perldoc -q attachment help?

    Abigail

      Thanks for the advice.

      I'm looking to handle the inbound attatchments. While my script can handle the header and body of the message, forward them on and record details in a database, I need to be able to forward any attatchments on as well.
•Re: Mail::Internet and attatchments
by merlyn (Sage) on Nov 11, 2003 at 15:21 UTC
Re: Mail::Internet and attatchments
by zentara (Archbishop) on Nov 11, 2003 at 15:37 UTC
    Mbox::Parser?
    #!/usr/bin/perl use Mail::MboxParser; my $mb = Mail::MboxParser->new('Mboxtest', decode => 'ALL'); # slurping for my $msg ($mb->get_messages) { print "###########################################################\n"; print $msg->header->{subject}, "\n"; print $msg->header->{from}, "\n"; print "###########################################################\n"; $msg->store_all_attachments('tmp'); my ($body) = $msg->body($msg->find_body,0); print ($body->as_string); print "###########################################################\n"; } print "############################################################\n" +; print "############################################################\n" +; print "############################################################\n" +; # we forgot to do something with the messages $mb->rewind; while (my $msg = $mb->next_message) { # iterate again # ... } exit;
Re: Mail::Internet and attatchments
by ysth (Canon) on Nov 11, 2003 at 15:59 UTC
    I've never had to do this, but perhaps MIME-Tools will help.

    I see one piece of code that I use (Mail::Audit) that checks for a MIME-Version header (I think case insensitively) to tell if mime parsing is needed.

Re: Mail::Internet and attatchments
by simonm (Vicar) on Nov 11, 2003 at 21:43 UTC
    Consider using MIME::Explode to parse your message instead of Mail::Internet.

    It will give you a structure of message headers and one or more enclosed content parts, with the attachments spit out into temporary files that you can further process as needed.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://306167]
Approved by EvdB
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (3)
As of 2014-09-24 02:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (244 votes), past polls