I have two pipelines use the same byte[] content as input.
- One output the content to Mbox file, then use mboxreader to read it in MailMessage and add to a pst file. Then read the MailMessage from the pst file and print its body
code:
//read from inputstream the mbox file which contains the content
MboxrdStorageReader mboxReader = new MboxrdStorageReader(new FileInputStream("/tmp/content.mbox", true)
MailMessage message = mboxReader.readNextMessage()
PersonalStorage pst = PersonalStorage.create(new FileOutputStream("/tmp/test.pst"), 0)
pst.addSubFolder(“inbox”);
pst.addMessage(mailMessage, “inbox”);
pst.close();
// read the message
pst = PersonalStorage.fromStream(new FileInputStream("/tmp/test.pst"), false)
FolderInfo folder = pst.getRootFolder().getSubFolder(“inbox”);
for (MessageInfo messageInfo : folder.getContents()) {
MapiMessage mapiMessage = pst.extractMessage(messageInfo);
MailConversionOptions conversionOptions = new MailConversionOptions();
conversionOptions.setKeepOriginalEmailAddresses(true);
conversionOptions.setPreserveEmbeddedMessageFormat(true);
MailMessage mailMessage = mapiMessage.toMailMessage(conversionOptions);
System.out.println(mailMessage.getBody());
}
- the second loads the byte[] content into pst directly and then read its message and print the body
MailMessage mailMessage = MailMessage.load(new ByteArrayInputStream(contents));
PersonalStorage pst = PersonalStorage.create(new FileOutputStream("/tmp/test.pst"), 0)
pst.addSubFolder(“inbox”);
pst.addMessage(mailMessage, “inbox”);
pst.close();
…
rest read logic is the same as one
However, the output message body in 1 and 2 are different, 1 is text body, 2 is html body.
I suppose MailMessage.getBody will internally call MailMessage.getHtmlBody as a condition and I want to know in what condition it returns html body , and in what condition it returns text body. The message content byte[] input is the same.