This discussion is archived
3 Replies Latest reply: Nov 20, 2013 10:27 AM by bshannon RSS

ParseException sending an email containing wrong headers - alternative solution

5add9dc7-d82a-4b35-988d-01c11aa7503d Newbie
Currently Being Moderated

Comming back to the thread

https://forums.oracle.com/thread/2449918

 

It is closed and I can not answer there, so I start a new one. It is already a year old, and I was thinking that maybe some solution could have been implemented.

I have found the property

 

mail.mime.contenttypehandlerString

In some cases JavaMail is unable to process messages with an invalid Content-Type header. The header may have incorrect syntax or other problems. This property specifies the name of a class that will be used to clean up the Content-Type header value before JavaMail uses it. The class must have a method with this signature: public static String cleanContentType(MimePart mp, String contentType) Whenever JavaMail accesses the Content-Type header of a message, it will pass the value to this method and use the returned value instead. The value may be null if the Content-Type header isn't present. Returning null will cause the default Content-Type to be used. The MimePart may be used to access other headers of the message part to determine how to correct the Content-Type. Note that the Content-Type handler doesn't affect the getHeader method, which still returns the raw header value. Note also that the handler doesn't affect the IMAP provider; the IMAP server is responsible for returning pre-parsed, syntactically correct Content-Type information.

 

Is there already a class to clean up the Content-Type? Or do you have more ideas to deal with this problem? Or ignore problematic headers?

As in the mentioned question is said, the problem is that the header comes in this way

 

 

 

Content-Type: text/rfc822-headers; Content-Transfer-Encoding: 8bit

 

and not

 

 

 

Content-Type: text/rfc822-headers;

Content-Transfer-Encoding: 8bit

 

Which would be correct.

 

Thanks

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points