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:
IMPORTANT: 'encoded-word's are designed to be recognized as 'atom's
by an RFC 822 parser. As a consequence, unencoded white space
characters (such as SPACE and HTAB) are FORBIDDEN within an
'encoded-word'. For example, the character sequence
=?iso-8859-1?q?this is some text?=
would be parsed as four 'atom's, rather than as a single 'atom' (by
an RFC 822 parser) or 'encoded-word' (by a parser which understands
'encoded-words'). The correct way to encode the string "this is some
text" is to encode the SPACE characters as well, e.g.
=?iso-8859-1?q?this=20is=20some=20text?=
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.strict
to false
, but a cursory look at the JavaMail code looks like that won't help. (Still worth trying, though.)