canonical_charset.t 779 Bytes
Newer Older
1
2
3
use warnings;
use strict;

4
use RT::Test nodata => 1, tests => 11;
5
6
7
8
use RT::I18N;
use Encode;

my %map = (
9
10
    'euc-cn'  => 'gbk',
    'gb-2312' => 'gbk',
11
12
13
14
15
16
17
18
19
20
21
22
23
24
    gb2312  => 'gbk',
    utf8    => 'utf-8',
    'utf-8' => 'utf-8',
);

for my $charset ( keys %map ) {
    is( RT::I18N::_CanonicalizeCharset($charset),
        $map{$charset}, "$charset => $map{$charset}" );
    is( RT::I18N::_CanonicalizeCharset( uc $charset ),
        $map{$charset}, uc( $charset ) . " => $map{$charset}" );
}

my $mime   = MIME::Entity->build(
    Type => 'text/plain; charset=gb2312',
25
    Data => [Encode::encode("gbk", Encode::decode( "UTF-8", "法新社倫敦11日電"))],
26
27
28
29
30
);

RT::I18N::SetMIMEEntityToUTF8($mime);
is( $mime->stringify_body, '法新社倫敦11日電', 'gb2312 => gbk in mail'  );