Subject: | Support for other character sets |
When using other charactersets than us-ascii or latin-1, for example
UTF-8, PGP::Mail didn't translate the $pgp->{data} to the correct
character set. I do this in this provided patch using Encode::decode.
Please add to the distribution, since I really need support for UTF-8.
Subject: | Mail.pm.utf8.patch |
--- ../PGP-Mail-1.7.orig/Mail.pm 2004-01-26 15:46:09.000000000 +0100
+++ Mail.pm 2006-06-26 15:10:48.000000000 +0200
@@ -6,6 +6,7 @@
use IO::Handle;
use GnuPG::Interface;
use MIME::Parser;
+use Encode;
=head1 NAME
@@ -115,6 +116,9 @@
}
}
+ # our default charset
+ $self->{charset}='us-ascii';
+
# we should now have the header in @header and the body
# in @lines
@@ -128,6 +132,12 @@
}
}
}
+ if($header=~/^content-type:\s+(\S+\/\S+)(;.*)?$/si) {
+ if ($header=~/charset=([a-z0-9-]+)/si)
+ {
+ $self->{charset}=$1;
+ }
+ }
}
if(!$self->{PGPMIME}) {
@@ -183,6 +193,7 @@
close $input;
$self->{data}=join "",<$output>;
+ $self->{data}=decode($self->{charset},$self->{data});
close $output;
$self->get_status($status);
@@ -202,6 +213,9 @@
$self->{status}="bad";
$self->{keyid}="0x$1";
}
+ elsif ($line =~ /^\[GNUPG:\] VALIDSIG (\w+) /) {
+ $self->{status}="good";
+ }
}
}
@@ -214,6 +228,12 @@
my $sigdata="";
my $signature="";
for my $line (@$data) {
+ if($line=~/^content-type:\s+(\S+\/\S+)(;.*)?$/si) {
+ if ($line=~/charset=([a-z0-9-]+)/si)
+ {
+ $self->{charset} = $1;
+ }
+ }
if($state eq "before" &&
$line eq "--$bound\n") {
$state="data";
@@ -282,6 +302,7 @@
$parser=new MIME::Parser;
$parser->output_to_core(1);
$self->{data}=$parser->parse_data($sigdata)->bodyhandle->as_string;
+ $self->{data}=decode($self->{charset},$self->{data});
$self->get_status($status);