| 1 |  | 
| 2 | =head1 NAME | 
| 3 |  | 
| 4 | Message::MIME::Charset Perl module | 
| 5 |  | 
| 6 | =head1 DESCRIPTION | 
| 7 |  | 
| 8 | Perl module for MIME charset. | 
| 9 |  | 
| 10 | =cut | 
| 11 |  | 
| 12 | package Message::MIME::Charset; | 
| 13 | use strict; | 
| 14 | use vars qw(%ENCODER %DECODER %N11NTABLE %REG $VERSION); | 
| 15 | $VERSION=do{my @r=(q$Revision: 1.1 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; | 
| 16 |  | 
| 17 | %ENCODER = ( | 
| 18 | '*DEFAULT'    => sub {$_[1]}, | 
| 19 | 'us-ascii'    => sub {$_[1]}, | 
| 20 | ); | 
| 21 |  | 
| 22 | %DECODER = ( | 
| 23 | '*DEFAULT'    => sub {$_[1]}, | 
| 24 | 'us-ascii'    => sub {$_[1]}, | 
| 25 | ); | 
| 26 |  | 
| 27 | ## Charset name normalization | 
| 28 | %N11NTABLE = ( | 
| 29 | 'euc' => 'euc-jp',    ## ... | 
| 30 | 'jis' => 'iso-2022-jp',       ## Really? | 
| 31 | 'shift-jis'   => 'shift_jis', | 
| 32 | 'shift-jisx0213'      => 'shift_jisx0213', | 
| 33 | 'x-big5'      => 'big5', | 
| 34 | 'x-x-big5'    => 'big5', | 
| 35 | 'x-euc'       => 'euc-jp',    ## ... | 
| 36 | 'x-euc-jp'    => 'euc-jp', | 
| 37 | 'x-gbk'       => 'gbk', | 
| 38 | 'x-gbk2k'     => 'gb18030', | 
| 39 | 'x-x-gbk'     => 'gbk', | 
| 40 | 'x-sjis'      => 'shift_jis', | 
| 41 | ); | 
| 42 |  | 
| 43 | sub encode ($$) { | 
| 44 | my ($charset, $s) = (lc shift, shift); | 
| 45 | if (ref $ENCODER{$charset}) { | 
| 46 | return (&{$ENCODER{$charset}} ($charset, $s), 1); | 
| 47 | } | 
| 48 | ($s, -1); | 
| 49 | } | 
| 50 |  | 
| 51 | sub decode ($$) { | 
| 52 | my ($charset, $s) = (lc shift, shift); | 
| 53 | if (ref $DECODER{$charset}) { | 
| 54 | return (&{$DECODER{$charset}} ($charset, $s), 1); | 
| 55 | } | 
| 56 | ($s, -1); | 
| 57 | } | 
| 58 |  | 
| 59 | sub name_normalize ($) { | 
| 60 | my $name = lc shift; | 
| 61 | $N11NTABLE{$name} || $name; | 
| 62 | } | 
| 63 |  | 
| 64 | =head1 LICENSE | 
| 65 |  | 
| 66 | Copyright 2002 wakaba E<lt>w@suika.fam.cxE<gt>. | 
| 67 |  | 
| 68 | This program is free software; you can redistribute it and/or modify | 
| 69 | it under the terms of the GNU General Public License as published by | 
| 70 | the Free Software Foundation; either version 2 of the License, or | 
| 71 | (at your option) any later version. | 
| 72 |  | 
| 73 | This program is distributed in the hope that it will be useful, | 
| 74 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| 75 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
| 76 | GNU General Public License for more details. | 
| 77 |  | 
| 78 | You should have received a copy of the GNU General Public License | 
| 79 | along with this program; see the file COPYING.  If not, write to | 
| 80 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 
| 81 | Boston, MA 02111-1307, USA. | 
| 82 |  | 
| 83 | =head1 CHANGE | 
| 84 |  | 
| 85 | See F<ChangeLog>. | 
| 86 | $Date: 2002/03/21 04:33:44 $ | 
| 87 |  | 
| 88 | =cut | 
| 89 |  | 
| 90 | 1; |