nochmal ich:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
sub keep_7bit
{
local $_ = shift;
tr/\x00-\x7F/#/c;
$_;
}
sub decode_qp
{
my $res = shift;
$res =~ s/\r\n/\n/g; # normalize newlines
$res =~ s/[ \t]+\n/\n/g; # rule #3 (trailing space must be deleted)
$res =~ s/=\n//g; # rule #5 (soft line breaks)
if (ord('A') == 193) { # EBCDIC style machine
if (ord('[') == 173) {
$res =~ s/=([\da-fA-F]{2})/Encode::encode('cp1047',Encode::decode('iso-8859-1',pack("C", hex($1))))/ge;
}
elsif (ord('[') == 187) {
$res =~ s/=([\da-fA-F]{2})/Encode::encode('posix-bc',Encode::decode('iso-8859-1',pack("C", hex($1))))/ge;
}
elsif (ord('[') == 186) {
$res =~ s/=([\da-fA-F]{2})/Encode::encode('cp37',Encode::decode('iso-8859-1',pack("C", hex($1))))/ge;
}
}
else { # ASCII style machine
$res =~ s/=([\da-fA-F]{2})/pack("C", hex($1))/ge;
}
$res;
}
sub decode_words
{
my $value = shift || "";
my $wd = default MIME::WordDecoder;
eval "require Encode; $value = Encode::decode('MIME-Header', $value)";
$wd->handler("BIG5" => "KEEP");
$wd->handler("WINDOWS-1250" => "KEEP");
$wd->handler("WINDOWS-1251" => "KEEP");
$wd->handler("WINDOWS-1252" => "KEEP");
$wd->handler("WINDOWS-1253" => "KEEP");
$wd->handler("WINDOWS-1254" => "KEEP");
$wd->handler("WINDOWS-1255" => "KEEP");
$wd->handler("WINDOWS-1256" => "KEEP");
$wd->handler("WINDOWS-1257" => "KEEP");
$wd->handler("WINDOWS-1258" => "KEEP");
$wd->handler("ISO-8859-1" => \&decode_qp);
$wd->handler("ISO-8859-2" => \&decode_qp);
my $retval = $value ? $wd->decode($value) : "";
return ($retval == 1 ? $value : $retval);
}
rufe jetzt decode_words auf:
decode_words('=?iso-8859-1?Q?1=261_Internet_AG_=2D_Ihre_Rechnung_105232829_vom_22.08.2004?=')
ich bekomme dann den original-codierten String zurück
anstatt \&decode_qp hab ich auch \&keep_7bit probiert; und hab auch die zeilen
$wd->handler("ISO-8859-1" => \&decode_qp);
$wd->handler("ISO-8859-2" => \&decode_qp);
zuerst ganz weggelassen gehabt... irgendwas scheint an diesem encoding nicht zu stimmen nicht zu stimmen; ich seh es leider nicht; andere ISO's funzen;
z.b.
decode_words('=?iso-8859-1?Q Rechnungsstelle_1=261_Internet_AG?= <rechnungsstelle@einsundeins.com>');