Courriel
view release on metacpan or search on metacpan
t/Headers.t view on Meta::CPAN
my $chinese = "\x{4E00}" x 100;
my $h = Courriel::Headers->new( headers => [ Subject => $chinese ] );
my $string = <<'EOF';
Subject:
=?UTF-8?B?5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA?=
=?UTF-8?B?5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA?=
=?UTF-8?B?5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA?=
=?UTF-8?B?5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA?=
=?UTF-8?B?5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA?=
=?UTF-8?B?5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA?=
=?UTF-8?B?5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA5LiA?=
EOF
$string =~ s/\n/$crlf/g;
is(
$h->as_string,
$string,
'Chinese subject is encoded properly'
);
is_deeply(
_headers_as_arrayref(
Courriel::Headers->parse( text => $h->as_string )
),
[ Subject => $chinese ],
'Chinese subject header round trips properly'
);
}
{
my $headers = <<'EOF';
Subject: has three spaces
EOF
my $h = Courriel::Headers->parse( text => \$headers );
like(
$h->as_string,
qr/\QSubject: has three spaces/,
'original spacing in header value is preserved when stringified'
);
}
{
my $header = Courriel::Header->new(
name => 'To',
value => q{ÄÄá¶È© ÈȯÆÅķẠ<autarch@urth.org>},
);
like(
$header->as_string,
qr/
\Q?UTF-8?B?\E
\S+
\s+
\Q<autarch\E\@\Qurth.org>\E
/x,
'email address is not encoded but unicode content before it is when address has no UTF-8'
);
}
{
my $header = Courriel::Header->new(
name => 'To',
value => q{ÄÄá¶È© ÈȯÆÅķẠ<Äutarch@urth.org>},
);
like(
$header->as_string,
qr/
\Q?UTF-8?B?\E
\S+
\s+
\Q<Äutarch\E\@\Qurth.org>\E
/x,
'email address is not encoded but unicode content before it is even when address has UTF-8'
);
}
{
my $header = Courriel::Header->new(
name => 'To',
value =>
q{ÄÄá¶È© ÈȯÆÅķẠ<Äutarch@urth.org>, "Joe Smith" <joe@example.com>},
);
like(
$header->as_string,
qr/
\Q?UTF-8?B?\E
\S+
\s+
\Q<Äutarch\E\@\Qurth.org>\E
\Q, "Joe Smith" <joe\E\@\Qexample.com>\E
/x,
'multiple addresses in To header are handled correctly when encoding'
);
}
{
my $value = q{from ÄÄá¶È© ÈȯÆÅÄ·áº};
my $header = Courriel::Header->new(
name => 'Received',
value => $value,
);
like(
$header->as_string,
qr/\Q$value/,
'Received header is not encoded'
);
}
{
my $header = Courriel::Header->new(
name => 'Subject',
value =>
'0000000000000000000000000000000000000000000000000000000000000000000 0',
);
my $expect = <<'EOF';
Subject: 0000000000000000000000000000000000000000000000000000000000000000000
0
EOF
$expect =~ s/\n/\r\n/g;
is(
$header->as_string,
$expect,
'header value that is all zeroes is folded correctly'
);
}
{
my $real = <<'EOF';
Return-Path: <rtcpan@cpan.rt.develooper.com>
( run in 1.668 second using v1.01-cache-2.11-cpan-2398b32b56e )