summaryrefslogtreecommitdiff
path: root/fml/lib/Mail/Message/Encode.pm
diff options
context:
space:
mode:
Diffstat (limited to 'fml/lib/Mail/Message/Encode.pm')
-rw-r--r--fml/lib/Mail/Message/Encode.pm82
1 files changed, 41 insertions, 41 deletions
diff --git a/fml/lib/Mail/Message/Encode.pm b/fml/lib/Mail/Message/Encode.pm
index 346ae3b6..7b45aadd 100644
--- a/fml/lib/Mail/Message/Encode.pm
+++ b/fml/lib/Mail/Message/Encode.pm
@@ -88,23 +88,22 @@ sub detect_code
my ($self, $str) = @_;
my $lang = $self->{ _language };
- # XXX Japanese includes English.
if ($lang eq 'japanese' || $lang eq 'english') {
- # getcode() can detect the follogin code:
- # jis, sjis, euc, utf8, ucs2, ucs4, utf16, utf16-ge, utf16-le,
- # utf32, utf32-ge, utf32-le, ascii, binary, sjis-imode,
- # sjis-doti, sjis-jsky.
- use Unicode::Japanese;
- my $obj = new Unicode::Japanese;
- return $obj->getcode($str);
+
+ my $hex = unpack('H*', $str);
+
+ use Unicode::Japanese;
+ my $obj = new Unicode::Japanese;
+ my $code = $obj->getcode($str);
+
+ return $code;
}
else {
- carp("Mail::Message::Encode: unknown language");
- return 'unknown';
+ carp("Mail::Message::Encode: unknown language");
+ return 'unknown';
}
}
-
# Unicode::Japanese
# 'jis', 'sjis', 'euc', 'utf8', 'ucs2', 'ucs4', 'utf16',
# 'utf16-ge', 'utf16-le', 'utf32', 'utf32-ge',
@@ -156,35 +155,33 @@ sub convert_str_ref
my $lang = $self->{ _language };
unless (ref($str_ref) eq 'SCALAR') {
- croak("convert_str_ref: invalid input data");
+ croak("convert_str_ref: invalid input data");
}
- # XXX Japanese includes English.
if ($lang eq 'japanese' || $lang eq 'english') {
- # 1. if the encoding for the given $str_ref is unknown, return ASAP.
- unless (defined $in_code) {
- $in_code = $self->detect_code($$str_ref);
- if ($in_code eq 'unknown') {
- return 0;
- }
- }
- else {
- # print "1 ok\n";
- }
-
- # 2. try conversion ! (converted to 'euc' by default).
- if ($in_code) {
- return $self->_jp_str_ref($str_ref, $out_code, $in_code);
- }
- }
- else {
- croak("Mail::Message::Encode: unknown language");
+
+ unless (defined $in_code) {
+ $in_code = $self->detect_code($$str_ref);
+
+ if ($in_code eq 'unknown') {
+ return 0;
+ }
+ }
+
+ if ($in_code) {
+ my $r = $self->_jp_str_ref(
+ $str_ref,
+ $out_code,
+ $in_code
+ );
+
+ return $r;
+ }
}
return 0;
}
-
# Descriptions: convert japanese string to $out_code.
# XXX $in_code must be determined here !
# Arguments: OBJ($self) STR_REF($str_ref) STR($out_code) STR($in_code)
@@ -195,25 +192,28 @@ sub _jp_str_ref
my ($self, $str_ref, $out_code, $in_code) = @_;
if ($out_code =~ /^(jis|sjis|euc)$|^(jis|sjis|euc)[-_]jp$/i) {
- my $code = $1 || $2;
- $code =~ tr/A-Z/a-z/;
- use Jcode;
- &Jcode::convert($str_ref, $code, $in_code);
+ my $code = $1 || $2;
+ $code =~ tr/A-Z/a-z/;
- return 1;
+ use Jcode;
+ &Jcode::convert($str_ref, $code, $in_code);
+
+ return 1;
}
elsif ($out_code =~ /^(iso2022jp|iso-2022-jp)$/i) {
- use Jcode;
- &Jcode::convert($str_ref, 'jis', $in_code);
- return 1;
+ use Jcode;
+ &Jcode::convert($str_ref, 'jis', $in_code);
+
+ return 1;
}
+ warn "_jp_str_ref: unsupported out_code=$out_code\n";
+
return 0;
}
-
=head2 run_in_code($proc, $s, $args, $out_code, $in_code)
run $proc($s) under $out_code environment.