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 130 131 132 133 134 135
|
use Test::More tests => 18;
use strict;
$^W = 1;
BEGIN {
use_ok 'Email::Reply';
use_ok 'Email::Simple';
use_ok 'Email::Simple::Creator';
use_ok 'Email::MIME::Modifier';
use_ok 'Email::Address::XS';
}
my $response = <<__RESPONSE__;
Welcome to Earth!
__RESPONSE__
my $simple = Email::Simple->create(
header => [
To => Email::Address::XS->new(undef, 'casey@geeknest.com'),
From => 'alien@titan.saturn.sol',
Subject => 'Ping',
],
body => <<__MESSAGE__ );
Are you out there?
--
The New Ones
__MESSAGE__
my $reply = reply to => $simple, body => $response;
$reply->header_set(Date => ());
like(
$reply->header('from'),
qr{casey\@geeknest\.com},
"correct from on reply",
);
like(
$reply->header('to'),
qr{alien\@titan\.saturn\.sol},
"correct to on reply",
);
is(
$reply->header('subject'),
'Re: Ping',
'correct subject',
);
like(
$reply->body,
qr{^> Are you out there\?}sm,
'correct subject',
);
$simple->header_set(Date => ());
$simple->header_set(Cc => 'martian@mars.sol, "Casey" <human@earth.sol>');
$simple->header_set('Message-ID' => '<1232345@titan.saturn.sol>');
$simple->header_set('In-Reply-To'=> '<6789000@titan.saturn.sol>');
$simple->header_set('References' => '<6789000@titan.saturn.sol>');
my $complex = reply to => $simple,
from => Email::Address::XS->new('Casey West', 'human@earth.sol'),
all => 1,
self => 1,
attach => 1,
top_post => 1,
keep_sig => 1,
prefix => '%% ',
attrib => 'Quoth the raven:',
body => $response;
$complex->header_set(Date => ());
$complex->header_set('Content-ID' => ());
$complex->boundary_set('boundary42');
$complex->parts_set([
map { $_->header_set(Date => ()); $_ } $complex->parts
]);
$complex->parts_set([
map { $_->header_set('Content-ID' => ()); $_ } $complex->parts
]);
is($complex->parts, 2, "one reply part, one original part");
like(
($complex->parts)[1]->header('content-type'),
qr{^message/rfc822},
'the second part is the original, rfc822-style',
);
like $complex->header('from'), qr/human\@earth\.sol/, "correct from";
is $complex->header('in-reply-to'),
'<1232345@titan.saturn.sol>',
"correct in-reply-to";
is $complex->header('references'),
'<6789000@titan.saturn.sol> <1232345@titan.saturn.sol>',
"correct references";
$complex->header_set('Message-ID' => '<4506957@earth.sol>');
my $replyreply = reply to => $complex, body => $response;
like $replyreply->header('from'),
qr/alien\@titan\.saturn\.sol/,
"correct from";
is $replyreply->header('in-reply-to'),
'<4506957@earth.sol>',
"correct in-reply-to";
is $replyreply->header('references'),
'<6789000@titan.saturn.sol> <1232345@titan.saturn.sol> <4506957@earth.sol>',
"correct references";
$replyreply->header_set(Date => ());
my $string = $replyreply->as_string;
$string =~ s/\x0d\x0a/\n/g;
like $string, qr{"?Casey West"? wrote:\Q
> Welcome to Earth!
>
> Quoth the raven:
> %% Are you out there?
> %%
> %%
> %% --
> %% The New Ones
\E}, "flat reply contains quoted body";
|