/[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.15 - (hide annotations) (download)
Fri Jul 26 12:42:00 2002 UTC (22 years, 4 months ago) by wakaba
Branch: MAIN
Changes since 1.14: +3 -2 lines
2002-07-25  Wakaba <w@suika.fam.cx>

	* Tool.pm: New module.

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 wakaba 1.10 ## NOTE: You should not require/use other module (even it
13     ## is part of Message::* Perl Modules) as far as possible,
14     ## to be able to use this module (M::M::Charset) from
15     ## other (non-Message::*) modules.
16    
17 wakaba 1.1 package Message::MIME::Charset;
18     use strict;
19 wakaba 1.12 use vars qw(%CHARSET %MSNAME2IANANAME %REG $VERSION);
20 wakaba 1.15 $VERSION=do{my @r=(q$Revision: 1.14 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
21 wakaba 1.1
22 wakaba 1.9 &_builtin_charset;
23     sub _builtin_charset () {
24 wakaba 1.4
25     $CHARSET{'*DEFAULT'} = {
26     preferred_name => '',
27    
28     encoder => sub { $_[1] },
29     decoder => sub { $_[1] },
30    
31     mime_text => 1, ## Suitability in use as MIME text/* charset
32     #accept_cte => [qw/7bit .../],
33     cte_7bit_preferred => 'quoted-printable',
34     };
35     $CHARSET{'*default'} = $CHARSET{'*DEFAULT'};
36    
37     $CHARSET{'us-ascii'} = {
38     preferred_name => 'us-ascii',
39    
40     encoder => sub { $_[1] },
41     decoder => sub { $_[1] },
42 wakaba 1.5
43     mime_text => 1,
44 wakaba 1.13 cte_7bit_preferred => 'quoted-printable',
45 wakaba 1.4 };
46    
47     $CHARSET{'iso-2022-int-1'} = {
48     preferred_name => 'iso-2022-int-1',
49    
50     encoder => sub { $_[1] },
51     decoder => sub { $_[1] },
52 wakaba 1.5
53     mime_text => 1,
54 wakaba 1.4 };
55    
56     $CHARSET{'unknown-8bit'} = {
57     preferred_name => 'unknown-8bit',
58    
59     encoder => sub { $_[1] },
60     decoder => sub { $_[1] },
61    
62 wakaba 1.13 mime_text => 1,
63     cte_7bit_preferred => 'base64',
64     };
65    
66     $CHARSET{'x-unknown'} = {
67     preferred_name => 'x-unknown',
68    
69     encoder => sub { $_[1] },
70     decoder => sub { $_[1] },
71    
72     mime_text => 0,
73     cte_7bit_preferred => 'base64',
74     };
75    
76     $CHARSET{'*undef'} = {
77     preferred_name => '',
78    
79     #encoder => sub { $_[1] },
80     #decoder => sub { $_[1] },
81    
82 wakaba 1.4 mime_text => 0,
83 wakaba 1.6 cte_7bit_preferred => 'base64',
84 wakaba 1.4 };
85    
86 wakaba 1.9 } # /builtin_charset
87    
88     my %_MINIMUMIZER = (
89     'euc-jp' => \&_name_euc_japan,
90     'euc-jisx0213' => \&_name_euc_japan,
91     'euc-jisx0213-plane1' => \&_name_euc_japan,
92     'x-euc-jisx0213-packed' => \&_name_euc_japan,
93 wakaba 1.11 'x-iso-2022' => \&_name_8bit_iso2022,
94     'iso-2022-cn' => \&_name_8bit_iso2022,
95     'iso-2022-cn-ext' => \&_name_8bit_iso2022,
96 wakaba 1.9 'iso-2022-int-1' => \&_name_net_ascii_8bit,
97 wakaba 1.11 'iso-2022-jp' => \&_name_8bit_iso2022,
98     'iso-2022-jp-1' => \&_name_8bit_iso2022,
99     'iso-2022-jp-2' => \&_name_8bit_iso2022,
100     'iso-2022-jp-3' => \&_name_8bit_iso2022,
101     'iso-2022-jp-3-plane1' => \&_name_8bit_iso2022,
102     'iso-2022-kr' => \&_name_8bit_iso2022,
103     'iso-8859-1' => \&_name_8bit_iso2022,
104 wakaba 1.9 'iso-10646-j-1' => \&_name_utf16be,
105     'iso-10646-ucs-2' => \&_name_utf16be,
106     'iso-10646-ucs-4' => \&_name_utf32be,
107     'iso-10646-ucs-basic' => \&_name_utf16be,
108     'iso-10646-unicode-latin1' => \&_name_utf16be,
109     jis_x0201 => \&_name_shift_jis,
110 wakaba 1.11 junet => \&_name_8bit_iso2022,
111 wakaba 1.9 'x-junet8' => \&_name_net_ascii_8bit,
112     shift_jis => \&_name_shift_jis,
113     shift_jisx0213 => \&_name_shift_jis,
114     'shift_jisx0213-plane1' => \&_name_shift_jis,
115     'x-sjis' => \&_name_shift_jis,
116     'us-ascii' => \&_name_net_ascii_8bit,
117     'utf-8' => \&_name_net_ascii_8bit,
118     'utf-16be' => \&_name_utf16be,
119     'utf-32be' => \&_name_utf32be,
120     );
121    
122 wakaba 1.14 my %_IsMimeText;
123     for (qw(
124     adobe-standard-encoding adobe-symbol-encoding
125     big5 big5-eten big5-hkscs
126     cp950
127     gbk gb18030
128     euc-jp euc-jisx0213 euc-kr euc-tw
129     hp-roman8
130     hz-gb-2312
131     ibm437
132     iso-2022-cn iso-2022-cn-ext
133     iso-2022-int-1
134     iso-2022-jp iso-2022-jp-1 iso-2022-jp-2 iso-2022-jp-3
135 wakaba 1.15 x-iso2022jp-cp932
136 wakaba 1.14 iso-2022-kr
137     iso-8859-1 iso-8859-2 iso-8859-3
138     iso-8859-4 iso-8859-5 iso-8859-6
139     iso-8859-7 iso-8859-8 iso-8859-9
140     iso-8859-10 iso-8859-12 iso-8859-13
141     iso-8859-14 iso-8859-15 iso-8859-16
142     jis_encoding
143     koi8-r koi8-u
144     x-mac-arabic x-mac-centralroman x-mac-cyrillic x-mac-greek
145     x-mac-hebrew x-mac-icelandic macintosh x-mac-turkish
146     x-mac-ukrainian x-mac-chinesesimp x-mac-japanese x-mac-korean
147     shift_jis shift_jisx0213 x-sjis
148     tis-620
149     unicode-1-1-utf-7 unicode-1-1-utf-8
150     unicode-2-0-utf-7 unicode-2-0-utf-8
151     utf-7 utf-8 utf-9
152     viscii
153     windows-1250 windows-1251 windows-1252 windows-1253
154     windows-1254 windows-1255 windows-1256 windows-1257
155     windows-1258 windows-31j windows-949
156     )) { $_IsMimeText{$_} = 1 }
157    
158 wakaba 1.12 %MSNAME2IANANAME = (
159     'iso-2022-jp' => 'x-iso2022jp-cp932',
160     'ks_c_5601-1987' => 'windows-949',
161     );
162    
163 wakaba 1.4 sub make_charset ($%) {
164     my $name = shift;
165     return unless $name; ## Note: charset "0" is not supported.
166     my %definition = @_;
167 wakaba 1.6
168     $definition{preferred_name} ||= $name;
169 wakaba 1.4 if ($definition{preferred_name} ne $name
170     && ref $CHARSET{$definition{preferred_name}}) {
171     ## New charset is an alias of defined charset,
172     $CHARSET{$name} = $CHARSET{$definition{preferred_name}};
173     return;
174     } elsif ($definition{alias_of} && ref $CHARSET{$definition{alias_of}}) {
175     ## New charset is an alias of defined charset,
176     $CHARSET{$name} = $CHARSET{$definition{alias_of}};
177     return;
178     }
179     $CHARSET{$name} = \%definition;
180    
181     ## Set default values
182 wakaba 1.6 #$definition{encoder} ||= sub { $_[1] };
183     #$definition{decoder} ||= sub { $_[1] };
184 wakaba 1.4
185     $definition{mime_text} = 0 unless defined $definition{mime_text};
186     $definition{cte_7bit_preferred} = 'base64'
187     unless defined $definition{cte_7bit_preferred};
188     }
189 wakaba 1.1
190     sub encode ($$) {
191     my ($charset, $s) = (lc shift, shift);
192 wakaba 1.13 my $c = ref $CHARSET{$charset}->{encoder}? $charset: '*undef';
193     if (ref $CHARSET{$c}->{encoder}) {
194     my ($t, %r) = &{$CHARSET{$c}->{encoder}} ($charset, $s);
195     unless (defined $r{success}) {
196     $r{success} = 1;
197     }
198     return ($t, %r);
199 wakaba 1.1 }
200 wakaba 1.5 ($s, success => 0);
201 wakaba 1.1 }
202    
203     sub decode ($$) {
204     my ($charset, $s) = (lc shift, shift);
205 wakaba 1.13 my $c = ref $CHARSET{$charset}->{decoder}? $charset: '*undef';
206     if (ref $CHARSET{$c}->{decoder}) {
207     my ($t, %r) = &{$CHARSET{$c}->{decoder}} ($charset, $s);
208     unless (defined $r{success}) {
209     $r{success} = 1;
210     }
211     return ($t, %r);
212 wakaba 1.1 }
213 wakaba 1.13 ($s, success => 0);
214 wakaba 1.1 }
215    
216     sub name_normalize ($) {
217     my $name = lc shift;
218 wakaba 1.14 if (ref $CHARSET{$name}->{preferred_name} eq 'CODE') {
219     return &{ $CHARSET{$name}->{preferred_name} } ($name);
220     } elsif ($CHARSET{$name}->{preferred_name}) {
221     return $CHARSET{$name}->{preferred_name};
222     } elsif (ref $CHARSET{'*undef'}->{preferred_name} eq 'CODE') {
223     return &{ $CHARSET{'*undef'}->{preferred_name} } ($name);
224     }
225     $name;
226 wakaba 1.1 }
227    
228 wakaba 1.6 sub name_minimumize ($$) {
229     my ($charset, $s) = (lc shift, shift);
230 wakaba 1.9 if (ref $CHARSET{$charset}->{name_minimumizer} eq 'CODE') {
231 wakaba 1.6 return &{$CHARSET{$charset}->{name_minimumizer}} ($charset, $s);
232 wakaba 1.9 } elsif (ref $_MINIMUMIZER{$charset}) {
233     return &{$_MINIMUMIZER{$charset}} ($charset, $s);
234 wakaba 1.13 } elsif (ref $CHARSET{'*undef'}->{name_minimumizer} eq 'CODE') {
235     return &{$CHARSET{'*undef'}->{name_minimumizer}} ($charset, $s);
236 wakaba 1.9 }
237     (charset => $charset);
238     }
239    
240 wakaba 1.12 sub msname2iananame ($) {
241     my $mscharset = shift;
242     $MSNAME2IANANAME{$mscharset} || $mscharset;
243     }
244    
245 wakaba 1.9 sub _name_7bit_iso2022 ($$) {shift;
246     my $s = shift;
247     if ($s =~ /[\x0E\x0F\x1B]/) {
248     return (charset => 'iso-2022-jp')
249     unless $s =~ /\x1B[^\x24\x28]
250     |\x1B\x24[^\x40B]
251     |\x1B\x28[^BJ]
252     |\x0E|\x0F/x;
253     return (charset => 'iso-2022-jp-1')
254     unless $s =~ /\x1B[^\x24\x28]
255     |\x1B\x24[^\x40B\x28]
256     |\x1B\x24\x28[^D]
257     |\x1B\x28[^BJ]
258     |\x0E|\x0F/x;
259     return (charset => 'iso-2022-jp-3-plane1')
260     unless $s =~ /\x1B[^\x24\x28]
261     |\x1B\x24[^\x28] #[^B\x28]
262     |\x1B\x24\x28[^O]
263     |\x1B\x28[^B]
264     |\x0E|\x0F/x;
265     return (charset => 'iso-2022-jp-3')
266     unless $s =~ /\x1B[^\x24\x28]
267     |\x1B\x24[^\x28] #[^B\x28]
268     |\x1B\x24\x28[^OP]
269     |\x1B\x28[^B]
270     |\x0E|\x0F/x;
271     return (charset => 'iso-2022-kr')
272     unless $s =~ /\x1B[^\x24]
273     |\x1B\x24[^\x29]
274     |\x1B\x24\x29[^C]/x;
275     return (charset => 'iso-2022-jp-2')
276     unless $s =~ /\x1B[^\x24\x28\x2E\x4E]
277     |\x1B\x24[^\x40AB\x28]
278     |\x1B\x24\x28[^CD]
279     |\x1B\x28[^BJ]
280     |\x1B\x2E[^AF]
281     |\x0E|\x0F/x;
282     return (charset => 'iso-2022-cn')
283     unless $s =~ /\x1B[^\x4E\x24]
284     |\x1B\x24[^\x29\x2A]
285     |\x1B\x24\x29[^AG]
286     |\x1B\x24\x2A[^H]/x;
287     return (charset => 'iso-2022-cn-ext')
288     unless $s =~ /\x1B[^\x4E\x4F\x24]
289     |\x1B\x24[^\x29\x2A]
290     |\x1B\x24\x29[^AEG]
291     |\x1B\x24\x2A[^HIJKLM]/x;
292     return (charset => 'iso-2022-int-1')
293     unless $s =~ /\x1B[^\x24\x28\x2D]
294     |\x1B\x24[^\x40AB\x28\x29]
295     |\x1B\x24\x28[^DGH]
296     |\x1B\x24\x29[^C]
297     |\x1B\x28[^BJ]
298     |\x1B\x2D[^AF]/x;
299     return (charset => 'junet')
300     unless $s =~ /\x1B[^\x24\x28\x2C]
301     |\x1B\x24[^\x28\x2C\x40-\x42]
302     |\x1B\x24[\x28\x2C][^\x20-\x7E]
303     |\x1B\x24[\x28\x2C][\x20-\x2F]+[^\x30-\x7E]
304     |\x1B[\x28\x2C][^\x20-\x7E]
305     |\x1B[\x28\x2C][\x20-\x2F]+[^\x30-\x7E]
306     |\x0E|\x0F/x;
307     return (charset => 'x-iso-2022');
308     } else {
309     return (charset => 'us-ascii');
310 wakaba 1.6 }
311     }
312    
313 wakaba 1.9 sub _name_net_ascii_8bit ($) {
314     my $name = shift; my $s = shift;
315 wakaba 1.8 return (charset => 'us-ascii') unless $s =~ /[\x1B\x0E\x0F\x80-\xFF]/;
316     if ($s =~ /[\x80-\xFF]/) {
317     if ($s =~ /[\xC0-\xFD][\x80-\xBF]*[\x80-\x8F]/) {
318     if ($s =~ /\x1B/) {
319 wakaba 1.9 return (charset => 'x-junet8'); ## junet + UTF-8
320 wakaba 1.8 } else {
321     return (charset => 'utf-8');
322     }
323     } elsif ($s =~ /\x1B/) {
324 wakaba 1.9 return (charset => 'x-iso-2022'); ## 8bit ISO 2022
325     } else {
326     return (charset => 'iso-8859-1');
327     }
328     } else { ## 7bit ISO 2022
329     return _name_7bit_iso2022 ($name, $s);
330     }
331     }
332    
333 wakaba 1.11 sub _name_8bit_iso2022 ($$) {
334 wakaba 1.9 my $name = shift; my $s = shift;
335     return (charset => 'us-ascii') unless $s =~ /[\x1B\x0E\x0F\x80-\xFF]/;
336     if ($s =~ /[\x80-\xFF]/) {
337     if ($s =~ /\x1B/) {
338     return (charset => 'x-iso-2022'); ## 8bit ISO 2022
339 wakaba 1.8 } else {
340     return (charset => 'iso-8859-1');
341     }
342 wakaba 1.9 } else { ## 7bit ISO 2022
343     return _name_7bit_iso2022 ($name, $s);
344     }
345     }
346    
347     ## Not completed.
348     ## TODO: gb18030, cn-gb-12345
349     ## TODO: _name_euc_gbf (cn-gb-12345, gb2312)
350     sub _name_euc_gb ($$) {
351     my $name = shift; my $s = shift;
352     if ($s =~ /[\x80-\xFF]/) {
353     if ($s =~ /
354     (?:\G|[\x00-\x3F\x7F\x80\xFF])
355     (?:[\xA1-\xA9\xB0-\xFE][\xA1-\xFE]
356     |[\x40-\x7E])*
357     (?:
358     [\x81-\xA0\xAA-\xAF][\x40-\xFE]
359     |[\xA1-\xFE][\x40-\xA0]
360     )
361     /x) {
362     (charset => 'gbk');
363     } elsif ($s =~ /
364     (?:\xA2[\xA1-\xAA]
365     |\xA6[\xE0-\xF5]
366     |\xA8[\xBB-\xC0]
367     )
368     (?=(?:[\xA1-\xFE][\xA1-\xFE])*(?:[\x00-\xA0\xFF]|\z))
369     /x) {
370     (charset => 'gbk');
371     } elsif ($s =~ /
372     (?:\xA3\xE7|\xA7[\xDD-\xF2]
373     |\xA8[\xBB-\xC0]
374     |[\xAA-\xAF\xF8-\xFE][\xA1-\xFE]
375     )
376     (?=(?:[\xA1-\xFE][\xA1-\xFE])*(?:[\x00-\xA0\xFF]|\z))
377     /x) {
378     (charset => 'cn-gb-isoir165', 'charset-edition' => 1992);
379     } elsif ($s =~ /\xEF\xF1 ## Typo bug of GB 2312
380     (?=(?:[\xA1-\xFE][\xA1-\xFE])*(?:[\x00-\xA0\xFF]|\z))
381     /x) {
382     (charset => 'gb2312');
383     } else {
384     (charset => 'gb2312', 'charset-edition' => 1980);
385     }
386     } elsif ($s =~ /[\x0E\x0F]/) {
387     (charset => 'gb2312'); ## Actually, this is not "gb2312"
388     } else {
389 wakaba 1.11 _name_7bit_iso2022 ($name, $s);
390 wakaba 1.9 }
391     }
392    
393     sub _name_euc_japan ($$) {
394     my $name = shift; my $s = shift;
395     if ($s =~ /[\x80-\xFF]/) {
396     if ($s =~ /\x8F[\xA1\xA3-\xA5\xA8\xAC-\xAF\xEE-\xFE][\xA1-\xFE]/) {
397     if ($s =~ /\x8F[\xA2\xA6\xA7\xA9-\xAB\xB0-\xED][\xA1-\xFE]/) {
398     ## JIS X 0213 plane 2 + JIS X 0212
399     (charset => 'x-euc-jisx0213-packed');
400     } else {
401     (charset => 'euc-jisx0213');
402     }
403     } elsif ($s =~ m{(?<![\x8E\x8F]) ## Not G2/G3 character
404     (?: ## JIS X 0213:2000
405     [\xA9-\xAF\xF5-\xFE][\xA1-\xFE]
406     |\xA2[\xAF-\xB9\xC2-\xC9\xD1-\xDB\xE9-\xF1\xFA-\xFD]
407     |\xA3[\xA1-\xAF\xBA-\xC0\xDB-\xE0\xFB-\xFE]
408     |\xA4[\xF4-\xFE]|\xA5[\xF7-\xFE]
409     |\xA6[\xB9-\xC0\xD9-\xFE]|\xA7[\xC2-\xD0\xF2-\xFE]
410     |\xA8[\xC1-\xFE]|\xCF[\xD4-\xFE]|\xF4[\xA7-\xFE]
411     )
412     (?=(?:[\xA1-\xFE][\xA1-\xFE])*(?:[\x00-\xA0\xFF]|\z))}x) {
413     if ($s =~ /\x8F/) { ## JIS X 0213 plane 1 + JIS X 0212
414     (charset => 'x-euc-jisx0213-packed');
415     } else {
416     (charset => 'euc-jisx0213-plane1');
417     }
418     } else {
419     (charset => 'euc-jp');
420     }
421     } elsif ($s =~ /\x0E|\x0F|\x1B[\x4E\x4F]/) {
422     (charset => 'euc-jisx0213'); ## Actually, this is not euc-japan
423     } else {
424 wakaba 1.11 _name_7bit_iso2022 ($name, $s);
425 wakaba 1.9 }
426     }
427    
428     sub _name_shift_jis ($$) {
429     my $name = shift; my $s = shift;
430     if ($s =~ /[\x80-\xFF]/) {
431     if ($s =~ /[\x0E\x0F\x1B]/) {
432     (charset => 'x-sjis');
433     } elsif ($s =~ /
434     (?:\G|[\x00-\x3F\x7F])
435     (?:[\x81-\x9F\xE0-\xFC][\x40-\x7E\x80-\xFC]
436     |[\x40-\x7E\xA1-\xDF])*
437     [\xF0-\xFC][\x40-\x7E\x80-\xFC]
438     /x) {
439     (charset => 'shift_jisx0213');
440     } elsif ($s =~ /
441     (?:\G|[\x00-\x3F\x7F])
442     (?:[\x81-\x9F\xE0-\xFC][\x40-\x7E\x80-\xFC]
443     |[\x40-\x7E\xA1-\xDF])*
444     (?:
445     [\x85-\x87\xEB-\xEF][\x40-\x7E\x80-\xFC]
446     |\x81[\xAD-\xB7\xC0-\xC7\xCF-\xD9\xE9-\xEF\xF8-\xFB]
447     |\x82[\x40-\x4E\x59-\x5F\x7A-\x80\x9B-\x9E\xF2-\xFC]
448     |\x83[\x97-\x9E\xB7-\xBE\xD7-\xFC]
449     |\x84[\x61-\x6F\x72-\x9E\xBF-\xFC]
450     |\x88[\x40-\x9E]|\x98[\x73-\x9E]|\xEA[\xA5-\xFC]
451     )
452     /x) {
453     (charset => 'shift_jisx0213-plane1');
454     } else {
455     (charset => 'shift_jis');
456     }
457     } elsif ($s =~ /[\x5C\x7E]/) {
458     if ($s =~ /\x1B\x0E\x0F/) {
459     (charset => 'x-sjis'); ## ISO 2022 with implied "ESC ( J"
460     ## BUG: "ESC ( B foobar\aaa ESC ( J aiueo" also matchs this
461     } else {
462     (charset => 'jis_x0201');
463     }
464     } else {
465 wakaba 1.11 _name_7bit_iso2022 ($name, $s);
466 wakaba 1.9 }
467     }
468    
469     sub _name_utf16be ($$) {
470     shift; my $s = shift;
471     if ($s =~ /[\xD8-\xDB][\x00-\xFF][\xDC-\xDF][\x00-\xFF]
472     (?=(?:[\x00-\xFF][\x00-\xFF])*\z)/sx) {
473     (charset => 'utf-16be');
474     } elsif ($s =~ /[\x01-\xFF][\x00-\xFF]
475     (?=(?:[\x00-\xFF][\x00-\xFF])*\z)/sx) {
476     if ($s =~ /([^\x00\x03\x04\x23\x25\x30\xFE\xFF]
477     [\x00-\xFF] # ^\x20\x22\x4E-\x9F\xF9\xFA
478     |\x03[^\x00-\x6F\xD0-\xFF]
479     #|\x20[^\x00-\x6F]
480     |\x25[^\x00-\x7F]
481     |\xFE[^\x30-\x4F]
482     |\xFF[^\x00-\xEF]
483     ## note 1 of RFC 1816 is ambitious, so block entire
484     ## is excepted
485     |\x30[\x00-\x3F]
486     )
487     (?=(?:[\x00-\xFF][\x00-\xFF])*\z)/sx) {
488     (charset => 'iso-10646-ucs-2');
489     } else {
490     (charset => 'iso-10646-j-1');
491     }
492     } elsif ($s =~ /\x00[\x80-\xFF]
493     (?=(?:[\x00-\xFF][\x00-\xFF])*\z)/sx) {
494     (charset => 'iso-10646-unicode-latin1');
495     } else {
496     (charset => 'iso-10646-ucs-basic');
497     }
498     }
499    
500     sub _name_utf32be ($$) {
501     shift; my $s = shift;
502     if ($s =~ /
503     ([\x01-\x7F][\x00-\xFF]{3}
504     |\x00[\x11-\xFF][\x00-\xFF][\x00-\xFF])
505     (?=(?:[\x00-\xFF]{4})*\z)/sx) {
506     (charset => 'iso-10646-ucs-4');
507     } else {
508     (charset => 'utf-32be');
509 wakaba 1.8 }
510     }
511    
512 wakaba 1.13 sub _utf8_on ($) {
513     Encode::_utf8_on ($_[0]) if $Encode::VERSION;
514     }
515     sub _utf8_off ($) {
516     Encode::_utf8_off ($_[0]) if $Encode::VERSION;
517     }
518    
519 wakaba 1.14 sub is_mime_text ($) {
520     my $name = lc shift;
521     if (ref $CHARSET{$name}->{mime_text} eq 'CODE') {
522     return &{ $CHARSET{$name}->{mime_text} } ($name);
523     } elsif (defined $CHARSET{$name}->{mime_text}) {
524     return $CHARSET{$name}->{mime_text};
525     } elsif (defined $_IsMimeText{$name}) {
526     return $_IsMimeText{$name};
527     } elsif (ref $CHARSET{'*undef'}->{mime_text} eq 'CODE') {
528     return &{ $CHARSET{'*undef'}->{mime_text} } ($name);
529     }
530     0;
531     }
532    
533 wakaba 1.1 =head1 LICENSE
534    
535     Copyright 2002 wakaba E<lt>w@suika.fam.cxE<gt>.
536    
537     This program is free software; you can redistribute it and/or modify
538     it under the terms of the GNU General Public License as published by
539     the Free Software Foundation; either version 2 of the License, or
540     (at your option) any later version.
541    
542     This program is distributed in the hope that it will be useful,
543     but WITHOUT ANY WARRANTY; without even the implied warranty of
544     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
545     GNU General Public License for more details.
546    
547     You should have received a copy of the GNU General Public License
548     along with this program; see the file COPYING. If not, write to
549     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
550     Boston, MA 02111-1307, USA.
551    
552     =head1 CHANGE
553    
554     See F<ChangeLog>.
555 wakaba 1.15 $Date: 2002/07/22 07:48:01 $
556 wakaba 1.1
557     =cut
558    
559     1;

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24