Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Mail::Internet question

by Anonymous Monk
on Oct 08, 2003 at 12:03 UTC ( [id://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

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
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-25 15:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found