/[suikacvs]/messaging/manakai/lib/Message/MIME/Charset.pm
Suika

Contents of /messaging/manakai/lib/Message/MIME/Charset.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (hide annotations) (download)
Sat Jun 1 05:37:18 2002 UTC (22 years, 5 months ago) by wakaba
Branch: MAIN
Changes since 1.4: +8 -4 lines
2002-06-01  wakaba <w@suika.fam.cx>

	* Charset.pm:
	- (encode): Returns minimum charset name if possible.
	- (definition of iso-2022-int-1, us-ascii): mime_text = 1.
	* Encoding.pm (decide_coderange): Returns 'binary'
	when there are lines consist of more than 998 octets.

1 wakaba 1.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 wakaba 1.5 $VERSION=do{my @r=(q$Revision: 1.4 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
16 wakaba 1.1
17 wakaba 1.4 our %CHARSET;
18    
19     $CHARSET{'*DEFAULT'} = {
20     preferred_name => '',
21    
22     encoder => sub { $_[1] },
23     decoder => sub { $_[1] },
24    
25     mime_text => 1, ## Suitability in use as MIME text/* charset
26     #accept_cte => [qw/7bit .../],
27     cte_7bit_preferred => 'quoted-printable',
28     };
29     $CHARSET{'*default'} = $CHARSET{'*DEFAULT'};
30    
31     $CHARSET{'us-ascii'} = {
32     preferred_name => 'us-ascii',
33    
34     encoder => sub { $_[1] },
35     decoder => sub { $_[1] },
36 wakaba 1.5
37     mime_text => 1,
38 wakaba 1.4 };
39    
40     $CHARSET{'iso-2022-int-1'} = {
41     preferred_name => 'iso-2022-int-1',
42    
43     encoder => sub { $_[1] },
44     decoder => sub { $_[1] },
45 wakaba 1.5
46     mime_text => 1,
47 wakaba 1.4 };
48    
49     $CHARSET{'unknown-8bit'} = {
50     preferred_name => 'unknown-8bit',
51    
52     encoder => sub { $_[1] },
53     decoder => sub { $_[1] },
54    
55     mime_text => 0,
56     cte_7bit_preferred => 'quoted-printable',
57     };
58     $CHARSET{'x-unknown'} = $CHARSET{'unknown-8bit'};
59    
60     sub make_charset ($%) {
61     my $name = shift;
62     return unless $name; ## Note: charset "0" is not supported.
63     my %definition = @_;
64     if ($definition{preferred_name} ne $name
65     && ref $CHARSET{$definition{preferred_name}}) {
66     ## New charset is an alias of defined charset,
67     $CHARSET{$name} = $CHARSET{$definition{preferred_name}};
68     return;
69     } elsif ($definition{alias_of} && ref $CHARSET{$definition{alias_of}}) {
70     ## New charset is an alias of defined charset,
71     $CHARSET{$name} = $CHARSET{$definition{alias_of}};
72     return;
73     }
74     $CHARSET{$name} = \%definition;
75    
76     ## Set default values
77     $definition{preferred_name} ||= $name;
78    
79     $definition{encoder} ||= sub { $_[1] };
80     $definition{decoder} ||= sub { $_[1] };
81    
82     $definition{mime_text} = 0 unless defined $definition{mime_text};
83     $definition{cte_7bit_preferred} = 'base64'
84     unless defined $definition{cte_7bit_preferred};
85     }
86 wakaba 1.1
87     sub encode ($$) {
88     my ($charset, $s) = (lc shift, shift);
89 wakaba 1.4 if (ref $CHARSET{$charset}->{encoder}) {
90 wakaba 1.5 return (&{$CHARSET{$charset}->{encoder}} ($charset, $s), success => 1);
91 wakaba 1.1 }
92 wakaba 1.5 ($s, success => 0);
93 wakaba 1.1 }
94    
95     sub decode ($$) {
96     my ($charset, $s) = (lc shift, shift);
97 wakaba 1.4 if (ref $CHARSET{$charset}->{decoder}) {
98     return (&{$CHARSET{$charset}->{decoder}} ($charset, $s), 1);
99 wakaba 1.1 }
100 wakaba 1.2 ($s, 0);
101 wakaba 1.1 }
102    
103     sub name_normalize ($) {
104     my $name = lc shift;
105 wakaba 1.4 $CHARSET{$name}->{preferred_name} || $name;
106 wakaba 1.1 }
107    
108     =head1 LICENSE
109    
110     Copyright 2002 wakaba E<lt>w@suika.fam.cxE<gt>.
111    
112     This program is free software; you can redistribute it and/or modify
113     it under the terms of the GNU General Public License as published by
114     the Free Software Foundation; either version 2 of the License, or
115     (at your option) any later version.
116    
117     This program is distributed in the hope that it will be useful,
118     but WITHOUT ANY WARRANTY; without even the implied warranty of
119     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
120     GNU General Public License for more details.
121    
122     You should have received a copy of the GNU General Public License
123     along with this program; see the file COPYING. If not, write to
124     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
125     Boston, MA 02111-1307, USA.
126    
127     =head1 CHANGE
128    
129     See F<ChangeLog>.
130 wakaba 1.5 $Date: 2002/05/30 12:51:05 $
131 wakaba 1.1
132     =cut
133    
134     1;

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24