I figured I would think aloud on the list since I have not found an answer
after extensively searching both the source code and the Internet:

The use case is that I want to clean up the HTML part of a message before
letting it go through to a blog (classic blog-post-by-email).  I am able to
change the content of the MimePart, but after doing so the content type
changes to "text/plain" from its original and desired "text/html"  This is
contrary to what I ask it to do in the call:
part.setContent(clean_html.getBytes("UTF-8"),
"text/html");

I have tried various variants including: part.setContent(clean_html,
"text/html"); and part.setContent(clean_html.getBytes("UTF-8"),
"text/html");  I also tried to create a brand new MimeBodyPart and try all
the variants above:  part_new.setContent(clean_html, "text/html");

I even tried to get the OutputStream from the part so I could modify the
data in-place but this threw an exception saying writing was not allowed:
part.getDataHandler().getDataSource().getOutputStream();

The best I could come up in my search of the Internet was to so something
like: part.setDataHandler(new DataHandler(new
HTMLDataSource(clean_html)));where I would have to write a custom
class
HTMLDataSource (as per this link: http://www.vipan.com/htdocs/javamail.html).
 The custom class is reasonably simple but I really want to avoid doing so
because it just seems like I would be duplicating standard functionality
available elsewhere.

I tried looking for the standard example mailets such as AddFooter but they
don't seem to be in the source any more.

Questions:
  (a) is there something available in James that would do the same?
  (b) is there something standard in Java or Java EE that would do the same?
 I do have activation.jar and mail.jar on my classpath.
  (c) how would you do this?
  (d) any other way of implementing my use case?

Thanks for reading!  Here is a simple, standalone class that demonstrates my
problem (need activation.jar and mail.jar on classpath):

public class Main {
  public static void main(String[] args) throws
javax.mail.MessagingException, java.io.IOException {
    javax.mail.internet.MimeBodyPart mime_body_part = new
javax.mail.internet.MimeBodyPart();
    mime_body_part.setContent("<h1>foo</h1>", "text/html");
    System.out.println(mime_body_part.getContent()); // OK
    System.out.println(mime_body_part.getContentType());  // NOT OK
  }
}

Reply via email to