| 1 | #
|
|---|
| 2 | # $Id: mime-header.t,v 2.0 2004/05/16 20:55:19 dankogai Exp $
|
|---|
| 3 | # This script is written in utf8
|
|---|
| 4 | #
|
|---|
| 5 | BEGIN {
|
|---|
| 6 | if ($ENV{'PERL_CORE'}){
|
|---|
| 7 | chdir 't';
|
|---|
| 8 | unshift @INC, '../lib';
|
|---|
| 9 | }
|
|---|
| 10 | require Config; import Config;
|
|---|
| 11 | if ($Config{'extensions'} !~ /\bEncode\b/) {
|
|---|
| 12 | print "1..0 # Skip: Encode was not built\n";
|
|---|
| 13 | exit 0;
|
|---|
| 14 | }
|
|---|
| 15 | if (ord("A") == 193) {
|
|---|
| 16 | print "1..0 # Skip: EBCDIC\n";
|
|---|
| 17 | exit 0;
|
|---|
| 18 | }
|
|---|
| 19 | $| = 1;
|
|---|
| 20 | }
|
|---|
| 21 |
|
|---|
| 22 | no utf8;
|
|---|
| 23 |
|
|---|
| 24 | use strict;
|
|---|
| 25 | #use Test::More qw(no_plan);
|
|---|
| 26 | use Test::More tests => 10;
|
|---|
| 27 | use_ok("Encode::MIME::Header");
|
|---|
| 28 |
|
|---|
| 29 | my $eheader =<<'EOS';
|
|---|
| 30 | From: =?US-ASCII?Q?Keith_Moore?= <[email protected]>
|
|---|
| 31 | To: =?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?= <[email protected]>
|
|---|
| 32 | CC: =?ISO-8859-1?Q?Andr=E9?= Pirard <[email protected]>
|
|---|
| 33 | Subject: =?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?=
|
|---|
| 34 | =?ISO-8859-2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?=
|
|---|
| 35 | EOS
|
|---|
| 36 |
|
|---|
| 37 | my $dheader=<<"EOS";
|
|---|
| 38 | From: Keith Moore <moore\@cs.utk.edu>
|
|---|
| 39 | To: Keld J\xF8rn Simonsen <keld\@dkuug.dk>
|
|---|
| 40 | CC: Andr\xE9 Pirard <PIRARD\@vm1.ulg.ac.be>
|
|---|
| 41 | Subject: If you can read this you understand the example.
|
|---|
| 42 | EOS
|
|---|
| 43 |
|
|---|
| 44 | is(Encode::decode('MIME-Header', $eheader), $dheader, "decode ASCII (RFC2047)");
|
|---|
| 45 |
|
|---|
| 46 | use utf8;
|
|---|
| 47 |
|
|---|
| 48 | my $uheader =<<'EOS';
|
|---|
| 49 | From: =?US-ASCII?Q?Keith_Moore?= <[email protected]>
|
|---|
| 50 | To: =?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?= <[email protected]>
|
|---|
| 51 | CC: =?ISO-8859-1?Q?Andr=E9?= Pirard <[email protected]>
|
|---|
| 52 | Subject: =?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?=
|
|---|
| 53 | =?ISO-8859-2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?=
|
|---|
| 54 | EOS
|
|---|
| 55 |
|
|---|
| 56 | is(Encode::decode('MIME-Header', $uheader), $dheader, "decode UTF-8 (RFC2047)");
|
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 | $dheader=<<'EOS';
|
|---|
| 60 | From: å°é£Œ 匟 <[email protected]>
|
|---|
| 61 | To: [email protected] (å°é£Œ=Kogai, 匟=Dan)
|
|---|
| 62 | Subject: 挢åãã«ã¿ã«ããã²ãããªãå«ããéåžžã«é·ãã¿ã€ãã«è¡ãäžäœå
|
|---|
| 63 | šäœã©ã®ããã«ããŠEncodeãããã®ãïŒ
|
|---|
| 64 | EOS
|
|---|
| 65 |
|
|---|
| 66 | my $bheader =<<'EOS';
|
|---|
| 67 | From:=?UTF-8?B?IOWwj+mjvCDlvL4g?=<[email protected]>
|
|---|
| 68 | To: [email protected] (=?UTF-8?B?5bCP6aO8?==Kogai,=?UTF-8?B?IOW8vg==?==Dan
|
|---|
| 69 | )
|
|---|
| 70 | Subject:
|
|---|
| 71 | =?UTF-8?B?IOa8ouWtl+OAgeOCq+OCv+OCq+ODiuOAgeOBsuOCieOBjOOBquOCkuWQq+OCgA==?=
|
|---|
| 72 | =?UTF-8?B?44CB6Z2e5bi444Gr6ZW344GE44K/44Kk44OI44Or6KGM44GM5LiA5L2T5YWo?=
|
|---|
| 73 | =?UTF-8?B?5L2T44Gp44Gu44KI44GG44Gr44GX44GmRW5jb2Rl44GV44KM44KL44Gu44GL?=
|
|---|
| 74 | =?UTF-8?B?77yf?=
|
|---|
| 75 | EOS
|
|---|
| 76 |
|
|---|
| 77 | my $qheader=<<'EOS';
|
|---|
| 78 | From:=?UTF-8?Q?=20=E5=B0=8F=E9=A3=BC=20=E5=BC=BE=20?=<[email protected]>
|
|---|
| 79 | To: [email protected] (=?UTF-8?Q?=E5=B0=8F=E9=A3=BC?==Kogai,
|
|---|
| 80 | =?UTF-8?Q?=20=E5=BC=BE?==Dan)
|
|---|
| 81 | Subject:
|
|---|
| 82 | =?UTF-8?Q?=20=E6=BC=A2=E5=AD=97=E3=80=81=E3=82=AB=E3=82=BF=E3=82=AB?=
|
|---|
| 83 | =?UTF-8?Q?=E3=83=8A=E3=80=81=E3=81=B2=E3=82=89=E3=81=8C=E3=81=AA=E3=82=92?=
|
|---|
| 84 | =?UTF-8?Q?=E5=90=AB=E3=82=80=E3=80=81=E9=9D=9E=E5=B8=B8=E3=81=AB=E9=95=B7?=
|
|---|
| 85 | =?UTF-8?Q?=E3=81=84=E3=82=BF=E3=82=A4=E3=83=88=E3=83=AB=E8=A1=8C=E3=81=8C?=
|
|---|
| 86 | =?UTF-8?Q?=E4=B8=80=E4=BD=93=E5=85=A8=E4=BD=93=E3=81=A9=E3=81=AE=E3=82=88?=
|
|---|
| 87 | =?UTF-8?Q?=E3=81=86=E3=81=AB=E3=81=97=E3=81=A6Encode=E3=81=95?=
|
|---|
| 88 | =?UTF-8?Q?=E3=82=8C=E3=82=8B=E3=81=AE=E3=81=8B=EF=BC=9F?=
|
|---|
| 89 | EOS
|
|---|
| 90 |
|
|---|
| 91 | is(Encode::decode('MIME-Header', $bheader), $dheader, "decode B");
|
|---|
| 92 | is(Encode::decode('MIME-Header', $qheader), $dheader, "decode Q");
|
|---|
| 93 | is(Encode::encode('MIME-B', $dheader)."\n", $bheader, "encode B");
|
|---|
| 94 | is(Encode::encode('MIME-Q', $dheader)."\n", $qheader, "encode Q");
|
|---|
| 95 |
|
|---|
| 96 | $dheader = "What is =?UTF-8?B?w4RwZmVs?= ?";
|
|---|
| 97 | $bheader = "What is =?UTF-8?B?PT9VVEYtOD9CP3c0UndabVZzPz0=?= ?";
|
|---|
| 98 | $qheader = "What is =?UTF-8?Q?=3D=3FUTF=2D8=3FB=3Fw4RwZmVs=3F=3D?= ?";
|
|---|
| 99 | is(Encode::encode('MIME-B', $dheader), $bheader, "Double decode B");
|
|---|
| 100 | is(Encode::encode('MIME-Q', $dheader), $qheader, "Double decode Q");
|
|---|
| 101 | {
|
|---|
| 102 | # From: Dave Evans <[email protected]>
|
|---|
| 103 | # Subject: Bug in Encode::MIME::Header
|
|---|
| 104 | # Message-Id: <[email protected]>
|
|---|
| 105 | use charnames ":full";
|
|---|
| 106 | my $pound_1024 = "\N{POUND SIGN}1024";
|
|---|
| 107 | is(Encode::encode('MIME-Q' => $pound_1024), '=?UTF-8?Q?=C2=A31024?=',
|
|---|
| 108 | 'pound 1024');
|
|---|
| 109 | }
|
|---|
| 110 | __END__;
|
|---|