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
|
#!/usr/bin/perl -w
use strict;
use diagnostics;
$| = 1; # autoflush
use vars qw(@ARGV $ARGV);
use lib ".";
use Jcode;
eval { require MIME::Base64 };
if ($@){
print "1..0\n";
exit 0;
}
my ($NTESTS, @TESTS) ;
sub profile {
no strict 'vars';
my $profile = shift;
print $profile if $ARGV[0];
$profile =~ m/(not ok|ok) (\d+)$/o;
$profile = "$1 $2\n";
$NTESTS = $2;
push @TESTS, $profile;
}
my $n = 0;
my $file;
my %mime =
(
"ʡҤ餬" =>
"=?ISO-2022-JP?B?GyRCNEE7eiEiJSslPyUrJUohIiRSJGkkLCRKGyhC?=",
"foo bar" =>
"foo bar",
"ʡҤ餬ʤκäSubject Header." =>
"=?ISO-2022-JP?B?GyRCNEE7eiEiJSslPyUrJUohIiRSJGkkLCRKJE46LiQ4JEMkPxsoQlN1?=\n =?ISO-2022-JP?B?YmplY3Q=?= Header.",
);
for my $k (keys %mime){
$mime{"$k\n"} = $mime{$k} . "\n";
}
for my $decoded (sort keys %mime){
my ($ok, $out);
my $encoded = $mime{$decoded};
my $encoded_i = $encoded; $encoded_i =~ s/^(=\?ISO-2022-JP\?B\?)/lc($1)/eo;
my $t_encoded = jcode($decoded)->mime_encode;
my $t_decoded = jcode($encoded)->mime_decode;
my $t_decoded_i = jcode($encoded_i)->mime_decode;
my $decoded_h = jcode($decoded)->h2z->euc;
my $t_encoded_h = jcode($decoded_h)->mime_encode;
if ($t_decoded eq $decoded){
$ok = "ok";
}else{
$ok = "not ok";
print <<"EOF";
D:>$decoded<
D:>$t_decoded<
EOF
}
profile(sprintf("MIME decode: %s -> %s %s %d\n",
$decoded, $encoded, $ok, ++$n ));
if ($t_decoded_i eq $decoded){
$ok = "ok";
#print $encoded_i, "\n";
}else{
$ok = "not ok";
print <<"EOF";
Di:>$decoded<
Do:>$t_decoded<
EOF
}
profile(sprintf("MIME decode: %s -> %s %s %d\n",
$decoded, $encoded_i, $ok, ++$n ));
if ($t_encoded eq $encoded){
$ok = "ok";
}else{
$ok = "not ok";
print <<"EOF";
Ei>$encoded<
Eo>$t_encoded<
EOF
}
profile(sprintf("MIME encode: %s -> %s %s %d\n",
$decoded, $encoded, $ok, ++$n ));
if ($t_encoded_h eq $encoded){
$ok = "ok";
}else{
$ok = "not ok";
print <<"EOF";
E>$decoded_h<
E>$t_encoded_h<
EOF
}
profile(sprintf("MIME encode: %s -> %s %s %d\n",
$decoded_h, $t_encoded_h, $ok, ++$n ));
}
print 1, "..", $NTESTS, "\n";
for my $TEST (@TESTS){
print $TEST;
}
|