Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Mail::Internet question

by Anonymous Monk
on Oct 08, 2003 at 12:03 UTC ( #297546=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Any help on this poser would be most appreciated

I am trying to use Mail::Internet to split an inbound email on STDIN into it's body and header parts so I can store what I need in a database.

I can deal with the header no probs but the body part is driving me up the wall, even though the documentation makes it sound simple.

The 'body' method should be a reference to an array containing the lines of the message body. Here is a sub I knocked up to parse the message.

sub parse_message { $message = new Mail::Internet \*STDIN; $sender = $message->head->get("From"); @content = $message->body(); $content = join('\n',@content); }


All I get in $content or @content is something like ARRAY(0x8217224);

I know I'm probably overlooking something very basic here, can anybody help?

Many thanks

Comment on Mail::Internet question
Select or Download Code
Replies are listed 'Best First'.
Re: Mail::Internet question
by liz (Monsignor) on Oct 08, 2003 at 12:13 UTC
    RTFM: ;-)
    body ( BODY )
    Returns the body of the message. This is a reference to an array. Each entry in the array represents a single line in the message.

    If you don't know what a reference is, check out perlreftut. In short:

    $content = join( '',@{$message->body} );

    Liz

Re: Mail::Internet question
by Abigail-II (Bishop) on Oct 08, 2003 at 12:16 UTC
    From the Mail::Internet manual page:
    METHODS body ( [ BODY ] ) Returns the body of the message. This is a reference to an array. Each entry in the array represents a single line in the message.
    So you will have to derefence the body first, like this:
    @content = @{$message -> body};

    It would have been much more convenient if the body method was context aware, and returned a list in list context. But c'est la vie. You could ask the author of the package to add this feature.

    Abigail

Re: Mail::Internet question
by Limbic~Region (Chancellor) on Oct 08, 2003 at 12:15 UTC
    Anonymous Monk,
    I have done something similar with Mail::Audit, which is capable of handling different body types (MIME::Entity). There is some code in this to process the body of the message, regardless of type. I do not know how/if Mail::Internet handles mixed mode MIME message bodies which was a requirement for me at the time.

    Cheers - L~R

Re: Mail::Internet question
by Anonymous Monk on Oct 08, 2003 at 12:29 UTC
    Thank you! all replies most useful

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2015-07-08 02:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls