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

Greetings folk monks,

I'm currently rewriting a script that used Net::POP3 and Mail::Internet to use the Mail::Box series of modules.

I've been scouring the documentation for Mail::Box and have managed to get most things working - except for displaying a message, either as part of a loop or individually.

What follows is the basic script I'm using:

#! /usr/bin/perl -w # ignoring -T - just testing. use strict; use Mail::Box::Manager; die "Usage: $0 message_number\n" unless @ARGV==1; my $msg_num = shift @ARGV; my $mailspool = "/var/spool/mail/baz"; my $mgr = Mail::Box::Manager->new; my $folder = $mgr->open($mailspool); # Get message specified on command line. my $message $folder->message($msg_num); print $message; $folder->close;

This code runs without errors and returns

Mail::Box::Mbox::Message=HASH(0x84c560)
Or some other reference to a hash, so I changed print $message to print %$message, only to get the same output.

I'm not finding anything helpful in the Mail::Box-Cookbook or Mail::Box::Mbox::Message manpages.

Is there something that I'm missing here? My code is basically the same as that shown in the Mail::Box manual!

Could someone please enlighten me, please?
I've only found one node ( Mail::Box-addMessage vs. Net::Pop3 ) that even mentions Mail::Box, and it's not relevant to this problem.

Cheers,

BazB.

Replies are listed 'Best First'.
(shockme) Re: Problems displaying a single message with Mail::Box
by shockme (Chaplain) on Dec 19, 2001 at 21:43 UTC
    Three things that might help:
    1. Are you sure the given $msg_num exists?
    2. Can you print $folder->message($msg_num);?
    3. Can you print $folder->message(0);?

    If things get any worse, I'll have to ask you to stop helping me.

      shockme, I did have a debug print statement just to check that $msg_num was being set OK, I just omitted it from the code I posted - it's working OK.

      The message number I've given does exist in the given mailspool.

      print $folder->message($msg_num); print $folder->message(0); # first message
      These two also produce a reference to a hash, with the first statement giving a different reference than the second (since I have been using $msg_num=2 or 3 as test cases).

      No joy with those.

      Cheers.

      Baz.

Re: Problems displaying a single message with Mail::Box
by Juerd (Abbot) on Dec 19, 2001 at 22:13 UTC
    Don't ask me why, but the Mail::Box documentation appears to be wrong somehow, or perl's behaviour has changed while the documentation hasn't.
    $message is a Mail::Box::Mbox::Message object, which can't be printed directly.

    Use $message->print(), or $message->head() and $message->body() if you need a scalar.

    I think some older perl parsed print $folder->message(0) as $folder->message(0)->print, but it does CORE::print($folder->message(0)).

    2;0 juerd@ouranos:~$ perl -e'undef christmas' Segmentation fault 2;139 juerd@ouranos:~$

      Juerd - Thanks - this does work, but I'm a bit puzzled - where is this documented?

      $folder->message($msg_num)->print;
      Prints the message out just fine.
      Is this something that I should consider emailling the author/maintainer about?

      Cheers.

      Baz.

        The available methods are documented in Mail::Box::Mbox::Message's documentation.

        You could mail the maintainer about print $folder->message($num) not working.

        2;0 juerd@ouranos:~$ perl -e'undef christmas' Segmentation fault 2;139 juerd@ouranos:~$