| 1 |
wakaba |
1.1 |
|
| 2 |
|
|
=head1 NAME
|
| 3 |
|
|
|
| 4 |
|
|
Message::MIME::Charset::Jcode --- Japanese Coding Systems Support
|
| 5 |
|
|
with jcode.pl and/or Jcode.pm for Message::* Perl Modules
|
| 6 |
|
|
|
| 7 |
|
|
=head1 DESCRIPTION
|
| 8 |
|
|
|
| 9 |
|
|
Message::* therselves don't convert coding systems of parts of
|
| 10 |
|
|
messages, but have mechanism to define to call external functions.
|
| 11 |
|
|
This module provides such macros for Japanese coding systems,
|
| 12 |
|
|
supported by jcode.pl and/or Jcode.pm.
|
| 13 |
|
|
|
| 14 |
|
|
=cut
|
| 15 |
|
|
|
| 16 |
|
|
package Message::MIME::Charset::Jcode;
|
| 17 |
|
|
use strict;
|
| 18 |
|
|
use vars qw(%CODE $VERSION);
|
| 19 |
|
|
$VERSION=do{my @r=(q$Revision: 1.1 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
|
| 20 |
|
|
|
| 21 |
|
|
require Message::Util;
|
| 22 |
|
|
require Message::MIME::Charset;
|
| 23 |
|
|
|
| 24 |
|
|
=head1 CODING SYSTEMS
|
| 25 |
|
|
|
| 26 |
|
|
=over 4
|
| 27 |
|
|
|
| 28 |
|
|
=item C<euc>
|
| 29 |
|
|
|
| 30 |
|
|
Japanese EUC. (MIME: euc-jp)
|
| 31 |
|
|
|
| 32 |
|
|
=item C<jis>
|
| 33 |
|
|
|
| 34 |
|
|
7bit ISO/IEC 2022, so-called junet code. ASCII, JIS X 0201 Roman,
|
| 35 |
|
|
JIS X 0201 Katakana, JIS X 0208, JIS X 0212 are supported by
|
| 36 |
|
|
jcode.pl and Jcode.pm. ISO-2022-JP, ISO-2022-JP-1 are subsets of
|
| 37 |
|
|
junet code.
|
| 38 |
|
|
|
| 39 |
|
|
=item C<sjis>
|
| 40 |
|
|
|
| 41 |
|
|
Shift JIS. (MIME: Shift_JIS)
|
| 42 |
|
|
|
| 43 |
|
|
=item C<utf8>
|
| 44 |
|
|
|
| 45 |
|
|
UTF-8. (MIME: UTF-8) This coding system is not supported by jcode.pl.
|
| 46 |
|
|
|
| 47 |
|
|
=item C<ucs2>
|
| 48 |
|
|
|
| 49 |
|
|
UCS-2 (or Unicode without surrogate pairs) big endian (network
|
| 50 |
|
|
byte order). This coding system is not supported by jcode.pl.
|
| 51 |
|
|
|
| 52 |
|
|
=back
|
| 53 |
|
|
|
| 54 |
|
|
=head1 VARIABLES
|
| 55 |
|
|
|
| 56 |
|
|
=over 4
|
| 57 |
|
|
|
| 58 |
|
|
=item $Messag::MIME::Charset::Jcode::CODE{internal}
|
| 59 |
|
|
|
| 60 |
|
|
Internal coding system. You can get strings written in this
|
| 61 |
|
|
coding system from Message::* Perl modules. (Default: C<euc>)
|
| 62 |
|
|
|
| 63 |
|
|
=item $Messag::MIME::Charset::Jcode::CODE{input}
|
| 64 |
|
|
|
| 65 |
|
|
Coding system of input string. (Default: auto-detect)
|
| 66 |
|
|
|
| 67 |
|
|
=item $Messag::MIME::Charset::Jcode::CODE{output}
|
| 68 |
|
|
|
| 69 |
|
|
Coding system of output string. (Default: C<jis>)
|
| 70 |
|
|
|
| 71 |
|
|
=back
|
| 72 |
|
|
|
| 73 |
|
|
=cut
|
| 74 |
|
|
|
| 75 |
|
|
$CODE{internal} = 'euc';
|
| 76 |
|
|
$CODE{input} = '';
|
| 77 |
|
|
$CODE{output} = 'jis';
|
| 78 |
|
|
|
| 79 |
|
|
sub import ($;%) {
|
| 80 |
|
|
shift;
|
| 81 |
|
|
for (@_) {
|
| 82 |
|
|
if ($_ eq 'jcode.pl') {
|
| 83 |
|
|
require 'jcode.pl';
|
| 84 |
|
|
Message::MIME::Charset::make_charset ('*default' =>
|
| 85 |
|
|
encoder => sub { jcode::to ($CODE{output}, $_[1], $CODE{internal}) },
|
| 86 |
|
|
decoder => sub { jcode::to ($CODE{internal}, $_[1], $CODE{input}) },
|
| 87 |
|
|
mime_text => 1,
|
| 88 |
|
|
);
|
| 89 |
|
|
Message::MIME::Charset::make_charset ('iso-2022-jp' =>
|
| 90 |
|
|
encoder => sub { jcode::jis ($_[1], $CODE{internal}) },
|
| 91 |
|
|
decoder => sub { jcode::to ($CODE{internal}, $_[1], 'jis') },
|
| 92 |
|
|
mime_text => 1,
|
| 93 |
|
|
cte_7bit_preferred => 'base64',
|
| 94 |
|
|
);
|
| 95 |
|
|
Message::MIME::Charset::make_charset ('euc-jp' =>
|
| 96 |
|
|
encoder => sub { jcode::euc ($_[1], $CODE{internal}) },
|
| 97 |
|
|
decoder => sub { jcode::to ($CODE{internal}, $_[1], 'euc') },
|
| 98 |
|
|
mime_text => 1,
|
| 99 |
|
|
);
|
| 100 |
|
|
Message::MIME::Charset::make_charset (shift_jis =>
|
| 101 |
|
|
encoder => sub { jcode::sjis ($_[1], $CODE{internal}) },
|
| 102 |
|
|
decoder => sub { jcode::to ($CODE{internal}, $_[1], 'sjis') },
|
| 103 |
|
|
mime_text => 1,
|
| 104 |
|
|
);
|
| 105 |
|
|
} elsif ($_ eq 'Jcode' || $_ eq 'Jcode.pm') {
|
| 106 |
|
|
require Jcode;
|
| 107 |
|
|
Message::MIME::Charset::make_charset ('*default' =>
|
| 108 |
|
|
## Very tricky:-)
|
| 109 |
|
|
encoder => sub { my $s = $_[1]; Jcode::convert (\$s, $CODE{output}, $CODE{internal}); $s },
|
| 110 |
|
|
decoder => sub { my $s = $_[1]; Jcode::convert (\$s, $CODE{internal}, $CODE{input}); $s },
|
| 111 |
|
|
mime_text => 1,
|
| 112 |
|
|
);
|
| 113 |
|
|
Message::MIME::Charset::make_charset ('iso-2022-jp' =>
|
| 114 |
|
|
encoder => sub { Jcode->new ($_[1], $CODE{internal})->iso_2022_jp },
|
| 115 |
|
|
decoder => sub { my $s = $_[1]; Jcode::convert (\$s, $CODE{internal}, 'jis'); $s },
|
| 116 |
|
|
mime_text => 1,
|
| 117 |
|
|
cte_7bit_preferred => 'base64',
|
| 118 |
|
|
);
|
| 119 |
|
|
Message::MIME::Charset::make_charset ('euc-jp' =>
|
| 120 |
|
|
encoder => sub { Jcode->new ($_[1], $CODE{internal})->euc },
|
| 121 |
|
|
decoder => sub { my $s = $_[1]; Jcode::convert (\$s, $CODE{internal}, 'euc'); $s },
|
| 122 |
|
|
mime_text => 1,
|
| 123 |
|
|
);
|
| 124 |
|
|
Message::MIME::Charset::make_charset (shift_jis =>
|
| 125 |
|
|
encoder => sub { Jcode->new ($_[1], $CODE{internal})->sjis },
|
| 126 |
|
|
decoder => sub { my $s = $_[1]; Jcode::convert (\$s, $CODE{internal}, 'sjis'); $s },
|
| 127 |
|
|
mime_text => 1,
|
| 128 |
|
|
);
|
| 129 |
|
|
Message::MIME::Charset::make_charset ('utf-8' =>
|
| 130 |
|
|
encoder => sub { Jcode->new ($_[1], $CODE{internal})->utf8 },
|
| 131 |
|
|
decoder => sub { my $s = $_[1]; Jcode::convert (\$s, $CODE{internal}, 'utf8'); $s },
|
| 132 |
|
|
mime_text => 1,
|
| 133 |
|
|
);
|
| 134 |
|
|
Message::MIME::Charset::make_charset ('ucs-2be' =>
|
| 135 |
|
|
encoder => sub { Jcode->new ($_[1], $CODE{internal})->ucs2 },
|
| 136 |
|
|
decoder => sub { my $s = $_[1]; Jcode::convert (\$s, $CODE{internal}, 'ucs2'); $s },
|
| 137 |
|
|
);
|
| 138 |
|
|
Message::MIME::Charset::make_charset ('ucs-2' => alias_of => 'ucs-2be');
|
| 139 |
|
|
Message::MIME::Charset::make_charset ('utf-16' => alias_of => 'ucs-2');
|
| 140 |
|
|
Message::MIME::Charset::make_charset ('utf-16be' => alias_of => 'ucs-2be');
|
| 141 |
|
|
} else {
|
| 142 |
|
|
Carp::croak "Jcode: $_: Module not supported";
|
| 143 |
|
|
}
|
| 144 |
|
|
Message::MIME::Charset::make_charset (jis => alias_of => 'iso-2022-jp');
|
| 145 |
|
|
Message::MIME::Charset::make_charset ('iso-2022-jp-1' => alias_of => 'iso-2022-jp');
|
| 146 |
|
|
Message::MIME::Charset::make_charset ('iso-2022-jp-3' => alias_of => 'iso-2022-jp');
|
| 147 |
|
|
Message::MIME::Charset::make_charset ('x-iso-2022-jp-3' => alias_of => 'iso-2022-jp-3');
|
| 148 |
|
|
Message::MIME::Charset::make_charset ('iso-2022-jp-3-plane1' => alias_of => 'iso-2022-jp-3');
|
| 149 |
|
|
Message::MIME::Charset::make_charset (euc => alias_of => 'euc-jp');
|
| 150 |
|
|
Message::MIME::Charset::make_charset (euc_jp => alias_of => 'euc-jp');
|
| 151 |
|
|
Message::MIME::Charset::make_charset ('x-euc' => alias_of => 'euc-jp');
|
| 152 |
|
|
Message::MIME::Charset::make_charset ('x-euc-jp' => alias_of => 'euc-jp');
|
| 153 |
|
|
Message::MIME::Charset::make_charset ('euc-jisx0213' => alias_of => 'euc-jp');
|
| 154 |
|
|
Message::MIME::Charset::make_charset ('x-euc-jisx0213' => alias_of => 'euc-jisx0213');
|
| 155 |
|
|
Message::MIME::Charset::make_charset ('euc-jisx0213-plane1' => alias_of => 'euc-jisx0213');
|
| 156 |
|
|
Message::MIME::Charset::make_charset (sjis => alias_of => 'shift_jis');
|
| 157 |
|
|
Message::MIME::Charset::make_charset ('shift-jis' => alias_of => 'shift_jis');
|
| 158 |
|
|
Message::MIME::Charset::make_charset ('x-sjis' => alias_of => 'shift_jis');
|
| 159 |
|
|
Message::MIME::Charset::make_charset (shift_jisx0213 => alias_of => 'shift_jis');
|
| 160 |
|
|
Message::MIME::Charset::make_charset ('shift-jisx0213' => alias_of => 'shift_jisx0213');
|
| 161 |
|
|
Message::MIME::Charset::make_charset ('x-shift_jisx0213' => alias_of => 'shift_jisx0213');
|
| 162 |
|
|
Message::MIME::Charset::make_charset ('x-shift-jisx0213' => alias_of => 'shift_jisx0213');
|
| 163 |
|
|
Message::MIME::Charset::make_charset ('shift_jisx0213-plane1' => alias_of => 'shift_jisx0213');
|
| 164 |
|
|
}
|
| 165 |
|
|
}
|
| 166 |
|
|
|
| 167 |
|
|
=head1 EXAMPLE
|
| 168 |
|
|
|
| 169 |
|
|
## Uses jcode.pl. Input is euc-japan, output is junet.
|
| 170 |
|
|
use Message::MIME::Charset::Jcode 'jcode.pl';
|
| 171 |
|
|
## You don't have to do {require 'jcode.pl'}.
|
| 172 |
|
|
$Message::MIME::Charset::Jcode::CODE{input} = 'euc';
|
| 173 |
|
|
$Message::MIME::Charset::Jcode::CODE{output} = 'jis';
|
| 174 |
|
|
require Message::Entity;
|
| 175 |
|
|
#...
|
| 176 |
|
|
|
| 177 |
|
|
## Uses Jcode.pm.
|
| 178 |
|
|
use Message::MIME::Charset::Jcode 'Jcode';
|
| 179 |
|
|
require Message::Entity;
|
| 180 |
|
|
#...
|
| 181 |
|
|
|
| 182 |
|
|
## Uses jcode.pl, but also Jcode.pm for Unicode encodings.
|
| 183 |
|
|
## Internal code is UTF-8.
|
| 184 |
|
|
use Message::MIME::Charset::Jcode 'Jcode';
|
| 185 |
|
|
use Message::MIME::Charset::Jcode 'jcode.pl';
|
| 186 |
|
|
$Message::MIME::Charset::Jcode::CODE{internal} = 'utf-8';
|
| 187 |
|
|
require Message::Entity;
|
| 188 |
|
|
#...
|
| 189 |
|
|
|
| 190 |
|
|
=head1 SEE ALSO
|
| 191 |
|
|
|
| 192 |
|
|
Message::MIME::Charset
|
| 193 |
|
|
|
| 194 |
|
|
Message::Entity
|
| 195 |
|
|
|
| 196 |
|
|
jcode.pl
|
| 197 |
|
|
|
| 198 |
|
|
Jcode.pm
|
| 199 |
|
|
|
| 200 |
|
|
=head1 LICENSE
|
| 201 |
|
|
|
| 202 |
|
|
Copyright 2002 wakaba E<lt>[email protected]<gt>.
|
| 203 |
|
|
|
| 204 |
|
|
This program is free software; you can redistribute it and/or modify
|
| 205 |
|
|
it under the terms of the GNU General Public License as published by
|
| 206 |
|
|
the Free Software Foundation; either version 2 of the License, or
|
| 207 |
|
|
(at your option) any later version.
|
| 208 |
|
|
|
| 209 |
|
|
This program is distributed in the hope that it will be useful,
|
| 210 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 211 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 212 |
|
|
GNU General Public License for more details.
|
| 213 |
|
|
|
| 214 |
|
|
You should have received a copy of the GNU General Public License
|
| 215 |
|
|
along with this program; see the file COPYING. If not, write to
|
| 216 |
|
|
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
| 217 |
|
|
Boston, MA 02111-1307, USA.
|
| 218 |
|
|
|
| 219 |
|
|
=head1 CHANGE
|
| 220 |
|
|
|
| 221 |
|
|
See F<ChangeLog>.
|
| 222 |
|
|
$Date: 2002/03/21 04:33:44 $
|
| 223 |
|
|
|
| 224 |
|
|
=cut
|
| 225 |
|
|
|
| 226 |
|
|
1;
|