When processing the multipart of a MIME message having Content-Type as
we observed that MimeBodyPart.isMimeType("multipart/*") is returning false.
Then we changed the condition to message.getContentType.startsWith("multipart/") to continue further processing.
Then we got the ParseException as shown below from MimeBodyPart.getCount( ..)
javax.mail.internet.ParseException: Expected ';', got "/"
After referring to rfc 2387 (http://www.ietf.org/rfc/rfc2387.txt) we found that the Content-Type parameter 'type' value should be
enclosed within quotes as it contains the '/' which is a special character.
After enclosing the type value in quotes ( type="text/html"),
the MIME message was processed successfully.
We don't have control on the MIME contents that we get, how we can resolve these kind of issues?
And also one more question the Content-Type value 'multipart/related' has also special character which is not enclosed in double quotes,
but error was not thrown. Why the error is throwing for 'type' parameter value.
See the package javadocs for the javax.mail.internet package for all the properties you can set to control things like this.
In particular, the System property mail.mime.parameters.strict can be set to false to better handle incorrectly formatted
And of course when you discover such an incorrectly formatted message, you should always report the bug to the owner
of the software that created the message.
To determine what needs to be quoted where and how, you need to read the detailed syntax requirements in the specs.
Guessing the rules by inference or analogy doesn't work.
Hi bshannon ,
Thanks for your reply.
I set the system property "mail.mime.parameters.strict" to false as below in our code.
But still I see the same error "javax.mail.internet.ParseException: Expected ';', got "/""
I tried to log the System property 'mail.mime.parameters.strict' before setting to false as below
But this was returning null, but this should return true by default, which means that property not exists.
Can you let me know in which java Mail API this property is introduced.
I tried even with latest 1.4.4 API, still the same issue.
You have to be sure to set the System property before the JavaMail classes that use it are loaded.
If you're running in an application server, for instance, you may need to set it when the application
server starts up, not when your application starts.
The property was introduced in JavaMail 1.4.2.
You can test the use of this property by saving the message to a file and using the msgshow.java
demo program to read the file. Set the property on the command line when running the program.
If that still doesn't work, send me a copy of the message that isn't parsed correctly at firstname.lastname@example.org.