* Dmitry Bigunyak via RT (bug-Mail-Box@rt.cpan.org) [091209 09:59]:
Show quoted text> Wed Dec 09 04:59:05 2009: Request 52600 was acted upon.
> Subject: Mail::Message::Field::Full->decode removes blanks between an
> encoded and an unencoded words
> Ticket <URL:
https://rt.cpan.org/Ticket/Display.html?id=52600 >
>
> use Mail::Message::Field::Full;
> my $encoded = '=?utf-8?B?0JLQtdGB0LXQu9Cw0Y8g0KDQsNCx0L7RgtCw?=
> <dima@adriver.ru>';
> print Mail::Message::Field::Full->decode($encoded);
I had a trick in this decoding implementation which has bitten me more
than once. Now, I have replaced it by a more straight-forward (and
probably even not slower) algorithm.
The chaned part follows.
Regards,
MarkOv
------ 8< ---- Mail::Message::Field::Full
sub _decoder($$$)
{ my ($charset, $encoding, $encoded) = @_;
$charset =~ s/\*[^*]+$//; # language component not used
my $to_utf8 = Encode::find_encoding($charset || 'us-ascii');
$to_utf8 or return $encoded;
my $decoded;
if($encoding !~ /\S/)
{ $decoded = $encoded;
}
elsif(lc($encoding) eq 'q')
{ # Quoted-printable encoded
$encoded =~ s/_/ /g; # specific to mime-fields
$decoded = MIME::QuotedPrint::decode_qp($encoded);
}
elsif(lc($encoding) eq 'b')
{ # Base64 encoded
require MIME::Base64;
$decoded = MIME::Base64::decode_base64($encoded);
}
else
{ # unknown encodings ignored
return $encoded;
}
$to_utf8->decode($decoded, Encode::FB_DEFAULT); # error-chars -> '?'
}
sub decode($@)
{ my $self = shift;
my @encoded = split /(\=\?[^?]*\?[bqBQ]?\?[^?]*\?\=)/, shift;
my %args = @_;
my $is_text = defined $args{is_text} ? $args{is_text} : 1;
my @decoded = shift @encoded;
while(@encoded)
{ shift(@encoded) =~ /\=\?([^?\s]*)\?([^?\s]*)\?([^?\s]*)\?\=/;
push @decoded, _decoder $1, $2, $3;
@encoded or last;
# in text, blanks between encoding must be removed, but otherwise kept
if($is_text && $encoded[0] !~ m/\S/) { shift @encoded }
else { push @decoded, shift @encoded }
}
join '', @decoded;
}