1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
use strict;
use warnings;
package Mail::Box::Dbx::Message;
use vars '$VERSION';
$VERSION = '2.068';
use base 'Mail::Box::File::Message';
use Carp;
use File::Copy qw/move/;
use Mail::Message::Body::String;
use Mail::Message::Head::Partial;
sub init($)
{ my ($self, $args) = @_;
my $dbx = $args->{dbx_record};
unless(defined $dbx)
{ $self->log(ERROR => 'Dbx record required to create the message.');
return;
}
push @{$args->{labels}}, (seen => $dbx->is_seen);
$self->SUPER::init($args);
$self->{MBDM_dbx} = $dbx;
$self->{MBDM_account_name} = $args->{account_name} || $dbx->oe_account_name;
$self->{MBDM_account_nr} = $args->{account_nr} || $dbx->oe_account_num;
$self;
}
#-------------------------------------------
sub loadHead()
{ my $self = shift;
my $head = $self->head;
return $head unless $head->isDelayed;
$self->loadBody;
$self->head;
}
#-------------------------------------------
sub loadBody()
{ my $self = shift;
my $body = $self->body;
return $body unless $body->isDelayed;
my $dbx = $self->dbxRecord or return;
unless(defined $dbx)
{ $self->log(ERROR => 'Unable to read delayed message.');
return;
}
my $head;
if(my $text = $dbx->as_string)
{ my $message = Mail::Message->read($text);
$head = $message->head;
$head->modified(0);
$body = $message->body;
}
else
{ # of course, it is not a complete head :( probably, we need a
# new object... put for now, make it simple.
$head = Mail::Message::Head::Partial->new;
my $ff = 'Mail::Message::Field::Fast';
$head->addNoRealize($ff->new(Subject => $dbx->subject));
$head->addNoRealize($ff->new('Message-ID' => $dbx->msgid));
$head->addNoRealize($ff->new('X-Dbx-Account-Name'=>$self->accountName));
$head->addNoRealize($ff->new('X-Dbx-Account-Nr'=> $self->accountNr));
if(my $parents = $dbx->parents_ids)
{ $head->addNoRealize($ff->new(References => $parents));
}
# I know this is not the right date, but at least it is something.
$head->addNoRealize($ff->new(Date => $ff->toDate($dbx->rcvd_gmtime)));
if(my $send_addr = $dbx->sender_address)
{ my $sender = Mail::Address->new($dbx->sender_name, $send_addr);
# This should be stored in Sender, because From can have
# more than one address,.... however... this is Outlook.
$head->addNoRealize($ff->new(From => $send_addr));
}
if(my $to_addr = $dbx->recip_address)
{ my $to = Mail::Address->new($dbx->recip_name, $to_addr);
# Also not correct to put it in To: Delivered-To is the
# right choice. But it is nice to have a To field...
$head->addNoRealize($ff->new(To => $to));
}
$body = Mail::Message::Body::String->new(data => << 'NOBODY');
* The contents of this message was not received
NOBODY
}
$self->head($head);
$self->storeBody($body);
$self->log(PROGRESS => 'Loaded delayed message.');
$self;
}
#-------------------------------------------
sub dbxRecord() { shift->{MBDM_dbx} }
#-------------------------------------------
sub accountName() { shift->{MBDM_account_name} }
#-------------------------------------------
sub accountNr() { shift->{MBDM_account_nr} }
#-------------------------------------------
1;
|