holo has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,

I'm having a tiny problem with Mail::Message. I'm trying to feed an email to a perl script (STDIN) that is supposed to put it in a Mail::Message object to be able to manipulate it. After looking at Mail::Message and friends, I came up with the following snippet:

use Mail::Message; my $s = "Subject: hello\n\n1\n2\n"; my $msg1 = Mail::Message->read(\$s);

That is supoposed to construct an object from the given scalar ref and throw it in $msg1 but, when I run it, I get the following:

Can't use string ("Mail::Message") as a HASH ref while "strict refs" i +n use at usr/share/perl5/Mail/Message.pm line 853.

After further investigation, I found the following code in a the module's test suite:

my $scalar = "Subject: hello world\n\nbody1\nbody2\n"; my $msg2 = Mail::Message->read(\$scalar); ok(defined $msg2); is(ref $msg2, 'Mail::Message'); ok(defined $msg2->head); isa_ok($msg2->head, 'Mail::Message::Head');

I installed Mail::Message using CPAN.pm and all the tests passed ... leading me to think that I'm missing something ?

Can someone enlighten me ?

10x

--
holo

Replies are listed 'Best First'.
Re: Feeding Mail::Message ...
by PodMaster (Abbot) on Jan 07, 2003 at 05:01 UTC
    The author of this module is a giant weirdo.

    Have you tried

    use Data::Dumper; use Mail::Message::Construct; print Dumper( Mail::Message->read(\"Subject:hello\n\n1\n2\n") ); __END__ $VAR1 = bless( { 'MM_labels' => {}, 'MM_modified' => 0, 'MR_trace' => 4, 'MM_head' => bless( { 'MMH_fields' => { 'message-id' +=> bless( [ + 'Message-ID', + ' mailbox-fjord-232-1041916062 ' + ], 'Mail::Message::Field::Fast' ), 'subject' => +bless( [ + 'Subject', + ' hello ' + ], 'Mail::Message::Field::Fast' ) }, 'MR_trace' => 4, 'MMH_begin' => 0, 'MMH_order' => [ $VAR1->{'MM_he +ad'}{'MMH_fields'}{'subject'}, $VAR1->{'MM_he +ad'}{'MMH_fields'}{'message-id'} ], 'MMH_message' => $VAR1, 'MMH_modified' => 1, 'MMH_end' => '15', 'MR_log' => 4 }, 'Mail::Message::Head::Complete +' ), 'MM_message_id' => 'mailbox-fjord-232-1041916062', 'MM_trusted' => 0, 'MM_body' => bless( { 'MMBL_array' => [ '1 ', '2 ' ], 'MM_modified' => 0, 'MMB_end' => '19', 'MMB_type' => bless( [ 'Content +-Type', ' text/p +lain; charset="us-ascii" ' ], 'Mail:: +Message::Field::Fast' ), 'MMB_begin' => '15', 'MR_trace' => 4, 'MMB_seqnr' => 0, 'MMB_checked' => 0, 'MMB_message' => $VAR1, 'MMB_disposition' => bless( [ ' +Content-Disposition', ' + none ' ], +'Mail::Message::Field::Fast' ), 'MMB_eol' => 'NATIVE', 'MR_log' => 4, 'MMB_transfer' => bless( [ 'Con +tent-Transfer-Encoding', ' no +ne ' ], 'Ma +il::Message::Field::Fast' ) }, 'Mail::Message::Body::Lines' ) +, 'MR_log' => 4 }, 'Mail::Message' );
    cause it works for me (same with what you got).

    Also, what version of that distribution do you have, cause the latest copy of Mail::Message (our $VERSION = 2.034; # Part of Mail::Box) is only around 550 lines long.


    MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
    ** The Third rule of perl club is a statement of fact: pod is sexy.

      $VERSION = 2.009

      Upgraded to latest (2.0.34) and now it works!

      Thanks PodMaster

      --
      holo