I am trying to modify an existing body part of a MimeMessage. I would like to filter out specific links. Do any of you know why, despite the fact that messages about the contents of the body part that need to be changed are sent with old content? Does caching continue? Any idea how to solve this?
Here is my code:
public void resend(InputStream data) throws Exception { Session mailSession = createMailSession(); //mailSession.setDebug(true); Transport transport = mailSession.getTransport(); MimeMessage message = new MimeMessage(mailSession, data); Object content = message.getContent(); if (content.getClass().isAssignableFrom(MimeMultipart.class)) { MimeMultipart mimeMultipart = (MimeMultipart) content; for (int i = 0; i < mimeMultipart.getCount(); i++) { BodyPart bodyPart = mimeMultipart.getBodyPart(i); if (bodyPart.getContentType().startsWith("text/plain")) { String cnt = updateContent((String) bodyPart.getContent()); System.out.println("ContentType = " + bodyPart.getContentType()); System.out.println("Content = " + cnt); bodyPart.setContent(cnt, bodyPart.getContentType()); } else if (bodyPart.getContentType().startsWith("text/html")) { String cnt = updateContent((String) bodyPart.getContent()); System.out.println("ContentType = " + bodyPart.getContentType()); System.out.println("Content = " + cnt); bodyPart.setContent(cnt, bodyPart.getContentType()); } } } else { String cnt = updateContent((String) message.getContent()); System.out.println("ContentType = " + message.getContentType()); System.out.println("Content = " + cnt); message.setContent(cnt, message.getContentType()); } transport.connect(); transport.sendMessage(message, message.getRecipients(Message.RecipientType.TO)); transport.close(); } private String updateContent(String cnt) { return cnt.replace("www.xyz.pl", "www.new-xyz.pl"); }
"Data stream data" contains an unhandled message.
Any ideas?
Thanks in advance....
source share