Have you tried to convert the EmbeddedPSTMessage into actual .msg format?
I am using the the library to read the pst file and the second process is I am converting the PSTMessage into javax.mail.internet.MimeMessage and save it as .eml.
The problem I have now is that whenever the attachment is embedded message (.msg format), it is getting converted to .dat extension.
Would you know how to convert the EmbeddedPSTMessage and attach it as the original msg format?
Im really desperate right now.
Below are the codes snippet:
// saving as .eml
MimeMessage mimeMessage = convertToMimeMessage(email);
fileName = getRidOfIllegalFileNameCharacters(email.getSubject());
File emlFile = new File("C:\\eml\\" + fileName + ".eml");
emlFile.createNewFile();
mimeMessage.writeTo(new FileOutputStream(emlFile));
private static MimeMessage convertToMimeMessage(PSTMessage email) throws MessagingException, IOException, PSTException {
Properties p = System.getProperties();
Session session = Session.getInstance(p);
MimeMessage mimeMessage = new MimeMessage(session);
//attachment part
MimeMultipart rootMultipart = new MimeMultipart();
for (int i = 0; i < email.getNumberOfAttachments(); i++) {
PSTAttachment attachment = email.getAttachment(i);
if (attachment != null && attachment.getFileInputStream() != null) {
MimeBodyPart attachmentBodyPart = new MimeBodyPart();
if (attachment.getMimeTag() != null && attachment.getMimeTag().length() > 0) {
DataSource source = new ByteArrayDataSource(attachment.getFileInputStream(), attachment.getMimeTag());
attachmentBodyPart.setDataHandler(new DataHandler(source));
} else {
DataSource source = new ByteArrayDataSource(attachment.getFileInputStream(), "application/octet-stream");
attachmentBodyPart.setDataHandler(new DataHandler(source));
}
attachmentBodyPart.setContentID(attachment.getContentId());
String fileName = "";
if (attachment.getLongFilename() != null && attachment.getLongFilename().length() > 0) {
fileName = attachment.getLongFilename();
} else if (attachment.getDisplayName() != null && attachment.getDisplayName().length() > 0) {
fileName = attachment.getDisplayName();
} else if (attachment.getFilename() != null && attachment.getFilename().length() > 0) {
fileName = attachment.getFilename();
}
attachmentBodyPart.setFileName(fileName);
rootMultipart.addBodyPart(attachmentBodyPart);
}
}
mimeMessage.setContent(rootMultipart);
return mimeMessage;