Sent Date on Email Returns Current Time

But why does it return current date and time instead of a null value?

@mstandfuss,
It was done for the convenience of working with email templates. I’ve added a task ticket to our tracking system with ID EMAILJAVA-34876. Our development team will consider an appropriate API to manage default values for the sent date. You will be notified when it is implemented.

I would argue that its not convenient at all. Since its a valid date there is no way to easily know that the returned date is that way cause there is actually no date vs it actually was sent at that date/time. Our clients are pushing for us to get this fixed ASAP in our code, and I really dont want to have to write code around Aspose’s lack of ability to identify this.

@mstandfuss,
I requested some ETA for this issue from our development team for you. I let you know as soon as possible.

Thanks @Andrey_Potapov I appreciate the quick responses.

@mstandfuss,
Our development team investigated the issue. When the MapiMessage object is loaded, the MailMessage object is loaded internally first. Then it is converted implicitly to the MapiMessage object. You can check the lost date as below:

MailMessage mailMessage = MailMessage.load("Email_Sent.txt");
System.out.println(mailMessage.getDate()); // <-- "zero" date
if (mailMessage.getDate().before(new Date(0))) {
    // some code...
}
MapiMessage mapiMessage = MapiMessage.fromMailMessage(mailMessage);

Is there a reason why the MapiMessage returns a now date instead of the zero date? Also is the MailMessage.getDate() synonymous with the MapiMessage.getClientSubmitTime()? Date seems to be more generic then the client submit time (sent date). I would look at the methods documentation but…

public Date getDate() {
    return zmo.a(this.f());
}

doesnt really mean much to me :confused:

@mstandfuss,

When you are loading some EML file through MapiMessage.load method, this process goes actually like this:
EML file → MailMessage object → MapiMessage object
This process happens implicitly through internal components anyway for EML files. In your case, the sent date is the “zero” date in the MailMessage object. Since the sent date cannot be zero in the MapiMessage object, it is equal to the current date.

Yes, these dates are equal entities.
API Reference: MailMessage.getDate method, MapiMessage.getClientSubmitTime method

Why can the sent date not be zero or null?

@mstandfuss,
Thank you for the question. It will take me a while to find out an answer. I will inform you about it as soon as possible.

So I went into our code to take a look at implementing the getDate instead of the getClientSubmitTime and this is the code we already had around it. Makes me think we had already ran into issues/discrepancies around the two methods in the past that we had to have such specific logic around it to get the right date. Can you give me more details on the two methods (since there is no documentation on the library for them)? You say they are synonymous, but everything I see leads me to believe thats not 100% accurate.

private Date getSentDate() {
	Date sentDate = mapiMessage.getClientSubmitTime();
	if (sentDate != null && sentDate.getTime() == ASPOSE_ZERO_DATE) {
		sentDate = null;
	}
	if (sentDate == null) {
		sentDate = mailMessage.getDate();
	}
	if (sentDate != null && sentDate.getTime() == ASPOSE_ZERO_DATE) {
		sentDate = null;
	}

	return sentDate;
}

@mstandfuss,
These methods don’t have a specific logic. The documentation doesn’t have more details. Please share your EML file if you find a problem with these methods.

Its the same email that I supplied in the initial post. The logic above is our specific code logic that uses Aspose. Yes the Aspose code has no documentation to it thats why I am posting here to understand the differences between the two methods. You stated they are the same but everything I am seeing leads me to think otherwise.

@mstandfuss,
Thank you for the feedback.

Unfortunately, I have no more information other than what I have already provided. Our development team will consider solutions for the case you described.

@mstandfuss,
A new API will be added in Aspose.Email 21.5:

// Gets or sets a value indicating whether it is necessary to keep empty dates when converting a message.
MapiConversionOptions.setPreserveEmptyDates(boolean)

Code example:

MailMessage mailMessage = MailMessage.load("Email_Sent.txt");
System.out.println(mailMessage.getDate()); // zero date

MapiConversionOptions mco = MapiConversionOptions.getUnicodeFormat();
// keep empty dates when converting a message
mco.setPreserveEmptyDates(true);

MapiMessage mapiMessage = MapiMessage.fromMailMessage(mailMessage, mco);
System.out.println(mapiMessage.getClientSubmitTime()); // zero date

// check zero date
if (mapiMessage.getClientSubmitTime().equals(JavaHelper.ZERO_DATE))
    System.out.println("ZERO DATE");

Our development team prepared a special build for you:

You can use it now.

@Andrey_Potapov really appreciate the quick turn around on that! I will give the supplied code a try and let you know.

@Andrey_Potapov I threw that provided jar into our lower environment and added the code. It worked as expected. Thank you! Will this change go into the next release of email jar?

@Andrey_Potapov Actually sorry was doing some more testing and it would appear that the developers only applied this to the sent date, this method is still returning today instead of the zero date :confused:

Date receivedDate = mapiMessage.getDeliveryTime();

@mstandfuss,
Thank you for the feedback. I reproduced the problem and logged the issue in our tracking system with ID EMAILJAVA-34883. Our development team will fix it as well.

Yes, this fix will be released in Aspose.Email 21.5.

@mstandfuss,
Our development team resolved the issue and prepared the special release for you:

This hotfix will be included in Aspose.Email 21.5 as well.