Re: Directly changing To & From field in the header

Vic Norton <[email protected]> Sun, 6 Feb 2005 11:38:26 -0500
Newsgroups gmane.comp.lang.perl.modules.mail-box
Message-ID <p06210203be2bf4cf721e@[192.168.1.100]>
I must be missing something. I guess I don't 
understand the reset method either. Here is an 
example of a problem with reset:

### begin example ###

use strict;
use Mail::Message;

my $head = Mail::Message::Head->build(
    From => 'Vic Norton <[email protected]>',
    To => 'Vic Norton <[email protected]>',
    Subject => 'Reset Test',
    'Content-Type' => 'text/plain; charset="us-ascii"',
);
my $body = Mail::Message::Body->new(
    data => "Hello, world\n",
);
my $msg = Mail::Message->new (
    head => $head,
    body => $body,
);

$msg->print;   # no problem to this point

$msg->head->reset('To', "\"Vic\" <norton\@dacor.net>");  # problem here
$msg->print;

### end example ###

What is wrong with this example. Why can't I 
reset the 'To' field. I get the error message

Error: File Complete.pm; Line 172:
   Can't call method "clone" without a package or object reference

which refers to the line(s)

169:    # Cloning required, otherwise double registrations will not be
170:    # removed from the ordered list: that's controled by 'weaken'
171:
172:    my @fields = map {$_->clone} @_;

in Mail::Message::Head::Complete.


Regards,

Vic

At 2:04 PM +0100 2/6/05, Gilles wrote:
>Hello.
>
>>    $Message->reset('To','[email protected]');
>>    $Message->reset('From','[email protected]');
>
>"reset" is a method of "Mail::Message::Head", so
>you should write
>
>   $Message->head->reset('To','[email protected]');
>

At 7:25 PM -0800 2/5/05, Zaphod wrote:
>Hello all.
>
>I am rather new to MailBox (3 Days actually) so 
>please bear with me, my question my be quite 
>simplistic since I am almost equally new to OOP.
>
>I would like to be able to simply change the To 
>& From lines in the header and send the message.
>
>Here is what I am trying to do, it does not work it pops an error(see below)
>
>use Mail::Box::Manager 2.00;
>my $InBoxName='/home/foobar/mail/foobar/inbox';
>my $Manager = Mail::Box::Manager->new;
>my $Folder = $Manager->open($InBoxName,extract=>'LAZY', access=>'rw');
>die "Cannot open $InBoxName: $!\n" unless defined $Folder;
>my $Counter=0;
>foreach $Message ($Folder->messages){
>   if($Counter==0){$Counter++;next;}
>   $Message->reset('To','[email protected]');
>   $Message->reset('From','[email protected]');
>   $Message->send
>}
>
>throws the following error message;
>
>Method reset() is not defined for a Mail::Box::Mbox::Message.
>Mail::Reporter::AUTOLOAD('Mail::Box::Mbox::...','From','vailmail@truckloa...') 
>called at 
>/usr/lib/perl5/site_perl/5.8.3/Mail/Message/Construct.pm 
>line 61
>Mail::Message::AUTOLOAD('Mail::Box::Mbox::...','From','vailmail@truckloa...') 
>called at test2.cgi line 24
>
>Am I way offbase or is there something simple I 
>am missing in my OOP/MailBox naïveté.