We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Date is not set correctly

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

Hi Magesh,


Thank you for posting your inquiry.

The following code sample generates a message with correct date and time at our end as can be seen by opening the message in MS Outlook. We don’t know how the tika parser is parsing this and raising issue. It might be some issue at the other end. Please share with us how to reproduce this issue at our end. We shall investigate it further and assist you.

Code:


MailMessage msg = new MailMessage();

msg.isDraft(false);


Calendar cal = Calendar.getInstance();

cal.set(2013,5, 15, 11, 45);


msg.setDate(cal.getTime());


msg.save(“1.msg”, SaveOptions.getDefaultMsgUnicode());

That works. I had to set isDraft(false).


Thanks!

Hi Magesh,


Thank you for sharing your feedback. Please feel free to write to us if you need further assistance related to API functionality.