Notice: This site is now in read-only mode and will no longer be updated.
Please visit our new and improved Knowledge Base at https://kb.joget.org/ for the latest content and updates.
I am using bean shell to read the email from outlook I am getting the data in this format
I am using this code to read the multipart emails
public String getTextFromMessage(Message message) throws MessagingException, IOException { String result = ""; if (message.isMimeType("text/plain")) { result = message.getContent().toString(); } else if (message.isMimeType("multipart/*")) { MimeMultipart mimeMultipart = (MimeMultipart) message.getContent(); result = getTextFromMimeMultipart(mimeMultipart); } return result; }
public String getTextFromMimeMultipart( MimeMultipart mimeMultipart) throws MessagingException, IOException{ String result = ""; int count = mimeMultipart.getCount(); for (int i = 0; i < count; i++) { BodyPart bodyPart = mimeMultipart.getBodyPart(i); if (bodyPart.isMimeType("text/plain")) { result = result + "\n" + bodyPart.getContent(); break; // without break same text appears twice in my tests } else if (bodyPart.isMimeType("text/html")) { String html = (String) bodyPart.getContent(); result = result + "\n" + org.jsoup.Jsoup.parse(html).text(); } else if (bodyPart.getContent() instanceof MimeMultipart){ result = result + getTextFromMimeMultipart((MimeMultipart)bodyPart.getContent()); } } return result; }
Hi, from the code it appears you are specifically retrieving text from the emails, and the screenshot does show extracted text. What is wrong and what is expected?
I am using bean shell to read the email from outlook I am getting the data in this format
I am using this code to read the multipart emails
public String getTextFromMessage(Message message) throws MessagingException, IOException {
String result = "";
if (message.isMimeType("text/plain")) {
result = message.getContent().toString();
} else if (message.isMimeType("multipart/*")) {
MimeMultipart mimeMultipart = (MimeMultipart) message.getContent();
result = getTextFromMimeMultipart(mimeMultipart);
}
return result;
}
public String getTextFromMimeMultipart(
MimeMultipart mimeMultipart) throws MessagingException, IOException{
String result = "";
int count = mimeMultipart.getCount();
for (int i = 0; i < count; i++) {
BodyPart bodyPart = mimeMultipart.getBodyPart(i);
if (bodyPart.isMimeType("text/plain")) {
result = result + "\n" + bodyPart.getContent();
break; // without break same text appears twice in my tests
} else if (bodyPart.isMimeType("text/html")) {
String html = (String) bodyPart.getContent();
result = result + "\n" + org.jsoup.Jsoup.parse(html).text();
} else if (bodyPart.getContent() instanceof MimeMultipart){
result = result + getTextFromMimeMultipart((MimeMultipart)bodyPart.getContent());
}
}
return result;
}
How can I get this data in this format