3 use RT::Test nodb => 1, tests => undef;
6 my $test_string = Encode::decode("UTF-8", 'À');
7 my $encoded_string = Encode::encode( 'iso-8859-1', $test_string );
8 my $mime = MIME::Entity->build(
9 "Subject" => $encoded_string,
10 "Data" => [$encoded_string],
13 # set the wrong charset mime in purpose
14 $mime->head->mime_attr( "Content-Type.charset" => 'utf8' );
17 local $SIG{__WARN__} = sub {
21 RT::I18N::SetMIMEEntityToEncoding( $mime, 'iso-8859-1' );
23 # this is a weird behavior for different perl versions, 5.12 warns twice,
24 # which is correct since we do the encoding thing twice, for Subject
25 # and Data respectively.
26 # but 5.8 and 5.10 warns only once.
27 ok( @warnings == 1 || @warnings == 2, "1 or 2 warnings are ok" );
28 ok( @warnings == 1 || ( @warnings == 2 && $warnings[1] eq $warnings[0] ),
29 'if there are 2 warnings, they should be same' );
33 qr/\QEncoding error: "\x{fffd}" does not map to iso-8859-1/,
34 "We can't encode something into the wrong encoding without Encode complaining"
37 my $subject = Encode::decode( 'iso-8859-1', $mime->head->get('Subject') );
39 is( $subject, $test_string, 'subject is set to iso-8859-1' );
40 my $body = Encode::decode( 'iso-8859-1', $mime->stringify_body );
42 is( $body, $test_string, 'body is set to iso-8859-1' );