It is not right. You are not allowed to have whitespace in the middle of the RFC 2047 encoded word , and therefore JavaMail stops trying to decode the subject when it enters the space before it enters the terminal ?= . Most parsers will be flexible in such things, given that so many messages are garbled this way, but JavaMail is too strict in this regard. It is not, but it is definitely not "liberal in what it accepts." This is what the RFC has to say:
IMPORTANT: "the encoded word is intended to recognize the" atom "using the RFC 822 analyzer. As a result, unencrypted white space characters (such as SPACE and HTAB) are FORBIDDEN within the" encoded words ". For example, a sequence of characters
=?iso-8859-1?q?this is some text?=
will be parsed as four “atoms”, and not as one “atom” (according to RFC 822 parser) or “encoded word” (parser that understands 'coded-words'). The correct way to encode the string "this is some text" also encodes SPACE characters, for example
=?iso-8859-1?q?this=20is=20some=20text?=
You can replace all the spaces there with an underscore, but this can become messy, because you will essentially need to write your own parser to know when to do it.
You can also try setting the mail.mime.decodetext.strict system property to false , but a quick glance at the JavaMail code looks like it won't help. (Still worth a try, though.)
dkarp
source share