I’m using ASPOSE Java library to recreate old emails. i.e., I get the from, to subject, etc from another system in a text file and I create the .msg.
Then I consume the .msg in tika parser to ingest into solr. The .msg file when parsed by solr shows the creation date as the current date when the .msg was created. It is ignoring the date passed in message.setDate()
Need this to be addressed urgently. Please help.
Here’s the code:
////////// - Using ASPOSE
// Create the message with the data from the txt file.
String msgFileName = null;
boolean isHTML = false;
try {
MailMessage message = new MailMessage();
if (subject != null)
message.setSubject(subject);
if (body != null) {
Pattern p = Pattern.compile(REGEX_HTML);
Matcher m = p.matcher(body.toLowerCase());
if (m.find())
isHTML = true;
if (isHTML) {
message.isBodyHtml(true);
// Remove the text before the HTML content.
if(body.toLowerCase().contains("<html"))
body = body.substring(body.toLowerCase().indexOf("<html"));
// sometimes, there is no tags. it starts off with tag…
if(!body.toLowerCase().contains("<html")) {
if(body.toLowerCase().contains("<font “))
body = body.substring(body.toLowerCase().indexOf(”<font “));
}
// sometimes the content is duplicated. i.e., there are tow sections of
// …
// so, just get the content till the first
if(body.toLowerCase().contains(”"))
body = body.substring(0, body.toLowerCase().indexOf("")) + “”;
message.setHtmlBody(body);
}
else
message.setBody(body);
}
if (from != null && from.indexOf(’,’) < 0)
message.setFrom(new MailAddress(from));
//if(to == null || to.length() == 0)
// to = "psemailbox@bell.com";
if (to != null && to.length() > 0) {
// split the address at the semi-colon and add each one
String[] toarray = to.split("[;,]");
for(String aTo:toarray) {
if(aTo != null && aTo.contains("@"))
message.getTo().addMailAddress(new MailAddress(aTo));
}
}
if (cc != null && cc.length() > 0 && cc.contains("@")) {
String[] ccarray = cc.split("[;,]");
for(String aCC:ccarray) {
if(aCC != null && aCC.contains("@"))
message.getCC().addMailAddress(new MailAddress(aCC));
}
}
if (bcc != null && bcc.length() > 0 && bcc.contains("@")) {
String[] bccarray = bcc.split("[;,]");
for(String aBCC:bccarray)
if(aBCC != null && aBCC.contains("@"))
message.getBcc().addMailAddress(new MailAddress(aBCC));
}
if (parsedDate != null)
message.setDate(parsedDate);
msgFileName = txtFile.substring(0, txtFile.lastIndexOf(’.’)) + “.msg”;
// Add the attachmetns
String emailNumber = txtFile.substring(txtFile.lastIndexOf(’_’), txtFile.lastIndexOf(’.’));
String attmStr = emailNumber + “attm”;
for (File file : soFolder.listFiles()) {
if (file.toString().contains(attmStr)) {
message.addAttachment(new Attachment(file.toString()));
}
}
message.save(msgFileName, SaveOptions.getDefaultMsgUnicode());
////////// - Using ASPOSE
Thanks,
Magesh
Magesh