I'm receiving inbox via pop3 using JavaMail (1.5.0). One of the servers sends the wrong-formated content-type string. There is encoding added after boundaries. It looks like:

Content-Type: multipart/mixed; 
 boundary="=_NextPart_2rfkindysadvnqw3nerasdf";koi8-r

It causes an error on parsing:

 javax.mail.internet.ParseException: Expected '=', got "null"   at
     javax.mail.internet.ParameterList.<init>(ParameterList.java:250)   at
     javax.mail.internet.ContentType.<init>(ContentType.java:114)   at
     javax.mail.internet.MimeMultipart.parse(MimeMultipart.java:580)    at
     javax.mail.internet.MimeMultipart.getCount(MimeMultipart.java:325)

Is there any possible way to correct mail stream before actual parsing? I've tried to compile sourses of the library to extend the functionality but this is not as easy as it should be (not sure where to settle bugfix).

有帮助吗?

解决方案

See the description of the mail.mime.contenttypehandler property in the javadocs for the javax.mail.internet package. That allows you to write a class that cleans up the Content-Type value before JavaMail uses it.

And of course you should report this bogus header to either the server vendor or more likely the vendor of the mailer that created the message.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top