From: Josef Moellers on
Rainer Weikusat wrote:
> Josef Moellers <josef_u._gabriele-moellers(a)t-online.de> writes:
>
> [...]
>
>> I need something that will allow me to decode this:
>>
>> From: =?ISO-8859-1?Q?Josef_M=F6llers?= <josef.moellers(a)gmx.de>
>> into
>> From: Josef M�llers <josef.moellers(a)gmx.de>
>>
>> and this
>>
>> Subject: =?ISO-8859-1?Q?L=E4_l=F6_l=FC_sa=DFen_auf_der_Stra=DF?=
>> =?ISO-8859-1?Q?e?=
>> into
>> Subject: L� l� l� sa�en auf der Stra�e
>>
>> I had hoped that there was some function in some library that I might
>> peruse ...
>
> http://packages.debian.org/lenny/libuu0
> http://cpan.uwinnipeg.ca/htdocs/MIME-Base64/MIME/QuotedPrint.html

Thanks, also to Holger Petersen who sent me a few PMs to help.
I've now implemented it as a small Perl script using MIME::QuotedPrint:

#! /usr/bin/perl

use warnings;
use strict;
use MIME::QuotedPrint;

my $quoted_printable;

# Read header
my @header;
while (my $line = <>) {
chomp $line;
last if length($line) == 0;
if ($line =~ /^ /)
{
$header[-1] .= substr($line, 1);
next;
}
push @header, $line;
}
# We have the entire header, now process
foreach (@header) {
if (/^From:\s/ || /^Subject:\s/) {
s/_/ /g;
1 while (s/=\?ISO-8859-1\?Q\?(.*?)\?=/decode_qp($1)/e);
} elsif (/^Content-Transfer-Encoding:\s.*quoted-printable/i) {
$quoted_printable = 1;
}

print "$_\n";
}
print "\n";
# Now copy mail body

if ($quoted_printable) {
while (<>) {
s/_/ /g;
print decode_qp($_);
}
} else {
while (<>) {
print $_;
}
}

Josef
From: sln on
On Thu, 01 Apr 2010 18:52:41 +0200, Josef Moellers <josef_u._gabriele-moellers(a)t-online.de> wrote:

>Rainer Weikusat wrote:
>> Josef Moellers <josef_u._gabriele-moellers(a)t-online.de> writes:
>>
>> [...]
>>
>>> I need something that will allow me to decode this:
>>>
>>> From: =?ISO-8859-1?Q?Josef_M=F6llers?= <josef.moellers(a)gmx.de>
>>> into
>>> From: Josef M�llers <josef.moellers(a)gmx.de>
>>>
>>> and this
>>>
>>> Subject: =?ISO-8859-1?Q?L=E4_l=F6_l=FC_sa=DFen_auf_der_Stra=DF?=
>>> =?ISO-8859-1?Q?e?=
>>> into
>>> Subject: L� l� l� sa�en auf der Stra�e
>>>
>>> I had hoped that there was some function in some library that I might
>>> peruse ...
>>
>> http://packages.debian.org/lenny/libuu0
>> http://cpan.uwinnipeg.ca/htdocs/MIME-Base64/MIME/QuotedPrint.html
>
>Thanks, also to Holger Petersen who sent me a few PMs to help.
>I've now implemented it as a small Perl script using MIME::QuotedPrint:
>
>#! /usr/bin/perl
>
>use warnings;
>use strict;
>use MIME::QuotedPrint;
>
>my $quoted_printable;
>
># Read header
>my @header;
>while (my $line = <>) {
> chomp $line;
> last if length($line) == 0;
if ($line =~ s{^[ \t]+}{ ,,, })
{
$header[-1] .= $line;
next;
}
> push @header, $line;
>}
># We have the entire header, now process
>foreach (@header) {
> if (/^From:\s/ || /^Subject:\s/) {
my $decoded = '';
1 while (s{=\?ISO-8859-1\?Q\?(.*?)\?=}
{$decoded = decode_qp($1);
$decoded =~ s/_/ /g;
$decoded
}e);
> } elsif (/^Content-Transfer-Encoding:\s.*quoted-printable/i) {
> $quoted_printable = 1;
> }
>
> print "$_\n";
>}
>print "\n";
># Now copy mail body
>
>if ($quoted_printable) {
> while (<>) {
> s/_/ /g;
> print decode_qp($_);
> }
>} else {
> while (<>) {
> print $_;
> }
>}
>
>Josef

But, in this context, decode_qp($_) is irrelavent
if 'This is a multi-part message in MIME format.'
In which case each part is not examined for
/^Content-Transfer-Encoding:\s.*quoted-printable/.

-sln
From: Alan Curry on
In article <hp2j0p$rkq$02$1(a)news.t-online.com>,
Josef Moellers <josef_u._gabriele-moellers(a)t-online.de> wrote:
| if (/^From:\s/ || /^Subject:\s/) {
| s/_/ /g;
| 1 while (s/=\?ISO-8859-1\?Q\?(.*?)\?=/decode_qp($1)/e);

Youch. If you want to do this correctly, the magic word is RFC2047.

And the other magic word is Encode::MIME::Header

--
Alan Curry