Subject: | Mail::Message::Body::Encode: charset conversion is not implemented |
The charset conversion is not implemeted in Mail::Message::Body::Encode.
Here is a small patch that use Text::Iconv to implement it. It doesn't
seem to work for all messages (I might investigate this later) and error
handling is inadequate but it's still better than nothing.
Subject: | Encode.patch |
diff -urp Body.old/Encode.pm Body/Encode.pm
--- Body.old/Encode.pm 2006-07-05 16:17:16.544229952 +0200
+++ Body/Encode.pm 2006-07-05 16:27:01.960233192 +0200
@@ -11,6 +11,7 @@ use Carp;
use MIME::Types;
use File::Basename 'basename';
+use Text::Iconv;
my MIME::Types $mime_types;
@@ -39,14 +40,15 @@ sub encode(@)
# my $mime_to = lc $type_to;
# If possible, update unify() too.
-# my $char_was = $type_from->attribute('charset');
-# my $char_to = $type_to->attribute('charset');
+ my $char_was = lc $type_from->attribute('charset');
+ my $char_to = lc $type_to->attribute('charset');
my $trans_was = lc $self->transferEncoding;
my $trans_to = lc $transfer;
#
- # The only translations implemented now is content transfer encoding.
+ # The only translations implemented now are content transfer encoding
+ # and charset.
#
#warn "Translate ($trans_was) -> ($trans_to)\n";
@@ -64,6 +66,16 @@ sub encode(@)
return $self;
}
+ # charset conversion
+ if (defined $decoded and $char_was ne $char_to) {
+ my $iconv = Text::Iconv->new($char_was, $char_to);
+ my $converted = $iconv->convert($decoded);
+ if (defined $converted) {
+ $decoded = $converted;
+ }
+ # else just ignore error and keep it unconverted
+ }
+
my $encoded;
if($trans_to eq 'none') {$encoded = $decoded}
elsif(my $encoder = $self->getTransferEncHandler($trans_to))
diff -urp Body.old/Encode.pod Body/Encode.pod
--- Body.old/Encode.pod 2006-07-05 16:17:16.000000000 +0200
+++ Body/Encode.pod 2006-07-05 16:17:53.000000000 +0200
@@ -50,7 +50,8 @@ NOT IMPLEMENTED YET
=item * charset conversion
-NOT IMPLEMENTED YET
+The (buggy) implementation use Text::Iconv. For some reasons,
+conversion will not always work. If it fails, it will keep the original text.
=back