1 |
#!/usr/bin/perl -w |
2 |
use strict; |
3 |
|
4 |
use Test; |
5 |
require Message::Entity; |
6 |
require Message::MIME::Charset; |
7 |
|
8 |
Message::MIME::Charset::make_charset ('*default' => |
9 |
encoder => sub { $_[1] }, |
10 |
decoder => sub { $_[1] }, |
11 |
mime_text => 1, |
12 |
); |
13 |
|
14 |
my (%test); |
15 |
my %utf16; |
16 |
|
17 |
BEGIN { |
18 |
%test = ( |
19 |
"foo bar" |
20 |
=> "us-ascii", |
21 |
"\x1B\x24B!y\x1B(B" |
22 |
=> 'iso-2022-jp', |
23 |
"\x1B\x24(O&=\x1B\x24B!y\x1B(B" |
24 |
=> 'x-iso-2022-7bit', |
25 |
"\x1B\x24(O&=\x1B(B" |
26 |
=> 'iso-2022-jp-3-plane1', |
27 |
"\x1B\x24(O&=\x1B\x24(P!!\x1B(B" |
28 |
=> 'iso-2022-jp-3', |
29 |
"\x1B\x24)G\x0El]N)k#\x0F" |
30 |
=> "iso-2022-cn", ## From Hello |
31 |
"\x1b\x24\x29\x41\x0e\x3d\x3b\x3b\x3b\x1b\x24\x29\x47\x47\x28\x5f\x50\x0f" |
32 |
=> "iso-2022-cn", ## From RFC 1922 |
33 |
"\x1B\x24)C\x0EGQ1[\x0F" |
34 |
=> 'iso-2022-kr', ## From Hello |
35 |
"Fran\x1B\x2E\x41\x1B\x4Egais" |
36 |
=> 'iso-2022-jp-2', ## From Hello |
37 |
"\xA1\xA2\xA3\xA4" |
38 |
=> 'iso-8859-1', |
39 |
"\x1B\x2DA\xA1\xA2\xA3\xA4" |
40 |
=> 'x-iso-2022', |
41 |
"\xC1\x81\xC2\x82\xC3\x83\xC4\x84" |
42 |
=> 'utf-8', |
43 |
); |
44 |
%utf16 = ( |
45 |
"\x00A\x00S\x00C\x00I\x00I\x00!" => 'iso-10646-ucs-basic', |
46 |
"\x00L\x00a\x00t\x00i\x00n\x001\x00\xA1" => 'iso-10646-unicode-latin1', |
47 |
"\x01\x00\x4E\x00" => 'iso-10646-ucs-2', |
48 |
"\x30\x41\x30\x43" => 'iso-10646-j-1', |
49 |
"\x01\x00\x4E\x00\xD8\x00\xDC\x00" => 'utf-16be', |
50 |
); |
51 |
plan tests => 2 * keys (%test) + keys (%utf16) } |
52 |
|
53 |
## Charset name auto-minimumization test |
54 |
for (keys %test) { |
55 |
ok (Message::MIME::Charset::name_minimumize ('iso-2022-int-1', |
56 |
$_), $test{$_}, 'name_minimumize is broken'); |
57 |
my $b = Message::Entity->new; |
58 |
$b->body ($_); |
59 |
$b->stringify (-fill_ct => 1, -force_mime_entity => 1, |
60 |
-fill_date => 0, -add_ua => 0, |
61 |
); |
62 |
ok (scalar $b->header->field ('content-type')->parameter ('charset'), $test{$_}, 'name_minimumize with Message::Entity suite is broken'); |
63 |
} |
64 |
for (keys %utf16) { |
65 |
ok (Message::MIME::Charset::name_minimumize ('utf-16be', |
66 |
$_), $utf16{$_}, 'name_minimumize is broken'); |
67 |
} |