Getting "Don't know how to decode quoted-printable" from Email::MIME on Solaris

T

Terry

All:

I hope someone can help me with this. I'm really not sure what the
issue is.

I have a Perl script that processes emails on a Solaris box. I'm using
the Email::MIME package to handle most of it. However, when an email
with the Content-Transfer-Encoding of quoted-printable comes in, I'm
getting the following error message:

Don't know how to decode quoted-printable at /export/opt/clarify/perl/
lib/Email/MIME.pm line 74

I've checked the Perl lib directory, and the QuotedPrint.pm module is
indeed installed under the lib/sun4-solaris/MIME directory.

I've even tried adding the sun4-solaris directory to the PERL5LIB
variable, without effect.

We're running Perl v5.8.0 for sun4-solaris, version 1.857 of the
Email::MIME.pm, and version 3.07 of QuotedPrint.pm.

Help!
 
D

Dan Otterburn

I've checked the Perl lib directory, and the QuotedPrint.pm module is
indeed installed under the lib/sun4-solaris/MIME directory.

Email::MIME uses Email::MIME::Encodings, which in turn uses
MIME::QuotedPrint and you would, therefore, be getting a compile-time
error if it were not in @INC when you use'd Email::MIME in your
script. So I do not think the problem is related to the location of
MIME::QuotedPrint.

I believe the croak is coming from the codec sub in
Email::MIME::Encodings:

[snip]
sub codec {
my ($which, $how, $what) = @_;
$how = lc $how;
$how = "qp" if $how eq "quotedprint"
or $how eq "quoted-printable"; # <--- X
my $sub = $which."_".$how;
if (not defined &$sub) { <--- Y
require Carp;
Carp::croak("Don't know how to $which $how"); # <--- Z
}
$sub->($what);
}

sub decode { return codec("decode", @_) }
[/snip]

At point Z $which='decode' and $how='quoted-printable' according to
the error message you posted as your subject. However, at point X, the
string 'quoted-printable' should have been set to 'qp', meaning that
the string from your error message - though apparently "quoted-
printable" - does *not* eq "quoted-printable".

(...and so at point Y $sub='decode_quoted-printable', which is a non-
existent sub. It *should* be 'decode_qp', which is the name of the sub
exported by MIME::QuotedPrint.)

My guess, and it is only a guess, is that this problem is related to
how the Content-Transfer-Encoding is being parsed and is probably to
do with character sets or new lines, i.e. something "environmental"
that would make two strings that visually match not return true on
either side of "eq". Is the error message *exactly* as your subject,
or does it have anything odd in it like a new line or carriage return?

I have no experience of Solaris so cannot help you any better I'm
afraid, perhaps a more skilled purveyor of our beautiful language can
help you further?

PS: There is a more recent version (1.860) of Email::MIME available
and the change log indicates that upgrading to this version *might*
help you:

1.860 2007-07-13
tentative tweak to tests and C-T-E handling for charset
probably needs more research, testing, and fixing
 
B

Brian McCauley

At point Z $which='decode' and $how='quoted-printable' according to
the error message you posted as your subject. However, at point X, the
string 'quoted-printable' should have been set to 'qp', meaning that
the string from your error message - though apparently "quoted-
printable" - does *not* eq "quoted-printable".

Read the OP's error more closely. I think the problem may be that
"quoted-printable " does *not* eq "quoted-printable".
My guess, and it is only a guess, is that this problem is related to
how the Content-Transfer-Encoding is being parsed and is probably to
do with character sets or new lines, i.e. something "environmental"
that would make two strings that visually match not return true on
either side of "eq". Is the error message *exactly* as your subject,
or does it have anything odd in it like a new line or carriage return?

If the message is *exactly* in the OP's message body then there is a
trailing space.

I don't think whitespace is supposed to be significant so this
probably counts as a bug.

If you look at package Email::MIME::ContentType the relevant lines
are...

my $tspecials = quotemeta '()<>@,;:\\"/[]?=';

my $discrete = qr/[^$tspecials]+/;
my $composite = qr/[^$tspecials]+/;
my $params = qr/;.*/;

$ct =~ m[ ^ ($discrete) / ($composite) \s* ($params)? $ ]x;

The \s* above will never match anything because /[^$tspecials]+/ is
gready and $tspecials does not contain whitespace.
 
T

Terry

Thanks for responding, Dan.

You are correct about the code location. Your comment regarding the
inequality of the "quoted-printable" argument was right on the money.
There's a trailing space on the Content-Transfer-Encoding value;
hence, it comparing "quoted-printable" to "quoted-printable ", which
of course isn't equal. Therefore, it goes looking for a decode method
that doesn't exist.

I'll update the module code as a workaround, and send the Email::MIME
author a bug report.

Thanks!
 
D

Dan Otterburn

Read the OP's error more closely. I think the problem may be that
"quoted-printable " does *not* eq "quoted-printable".

Crikey, good eyesight! You are absolutely right.
If you look at package Email::MIME::ContentType the relevant lines
are...

But surely "quoted-printable" is in the "Content-Transfer-Encoding"
header, which is not parsed by
Email::MIME::ContentType::parse_content_type() but rather by
Email::Simple::header() unless I misunderstand the code?
 
B

Brian McCauley

Crikey, good eyesight! You are absolutely right.


But surely "quoted-printable" is in the "Content-Transfer-Encoding"
header, which is not parsed by
Email::MIME::ContentType::parse_content_type() but rather by
Email::Simple::header() unless I misunderstand the code?

Yes, my mistake:

The regex in Email::Simple::Header that reads

/^([^:]+):\s*(.*)/

should read

/^([^:]+):\s*(.*?)\s*$/

At least that's the case if I'm right in assuming that trailing w/s
should be trimmed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top