i’m facing a problem decoding a mail with the following subject:
Subject: =?ISO-8859-1?Q?Re: Re: Re:
Fwd: (GI ?=
=?ISO-8859-1?Q?Support-Id:11729)?=
javamail decodes it as:
=?ISO-8859-1?Q?Re: Re: Re: Fwd: (GI ?= Support-Id:11729)
is this a valid subject at all?
or should javamail be able to read this?
regards
It’s malformed. You’re not permitted to have whitespace characters in the middle of an RFC 2047 encoded-word, and thus JavaMail stops trying to decode the Subject when it hits a space before it hits the terminal
?=. Most parsers will be flexible about things like this, given that so many messages are malformed in this manner, but JavaMail is a little too strict in this regard. It’s not wrong, but it’s definitely not "being liberal in what it accepts". This is what the RFC has to say:You could replace all the spaces in there with the underscore character, but that can get messy because you’d essentially have to write your own parser in order to know when to do that.
You could also try setting the system property
mail.mime.decodetext.stricttofalse, but a cursory look at the JavaMail code looks like that won’t help. (Still worth trying, though.)