I have a javax.mail.Part and need to modify the content, so I have code like this:
System.out.println(part.getContentType());
String content = (String) part.getContent();
content = content.replace("a", "b");
part.setContent(content, part.getContentType());
System.out.println(part.getContentType());
This prints out text/html then text/plain. I've also tried creating a javax.activation.DataHandler with type text/html and calling part.setDataHandler(dh), but part.getContentType() still returns text/plain after that.
I can set the content and then call part.setHeader("Content-Type", "text/html"). After this part.getContentType() returns "text/html", but this seems like a hack.
Has anyone seen this? What's the best way to handle it?