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

Free Support Forum - aspose.com

Hashing of mailmessage stream should not always be unique

Hello,

I'm trying to get a unique hashcode for each MailMessage.
Though if i use it on the same mail again the hashcode should be the same.
I get a unique hashcode everytime now, even if it is the same mail again. That should not happen.

i'm saving the mailmessage to msg format in a memorystream.
The memorystream is then placed under a streamreader and read as a string and converted to a hashstring.

Is it possible that the Save function of MailMessage builds the boundary of the mail from the ground up, thus making it different everytime ?
Or is there something else i have missed and can use to get the hashcode of the whole MailMessage ?


private static string EmailMessageToSha256(MailMessage mail) {
_ms = new MemoryStream(); mail.Save(_ms,MessageFormat.Msg); string imsha256 = null; if (_ms != new MemoryStream()) { _ms.Position = 0; _sr = new StreamReader(_ms); imsha256 = GeneralHelper.CalculateSHA256(_sr.ReadToEnd(), Encoding.Default); } return imsha256;
}

public static string CalculateSHA256(string text, Encoding enc) { var buffer = enc.GetBytes(text); var cryptoTransformSha256 = new SHA256CryptoServiceProvider(); return BitConverter.ToString(cryptoTransformSha256.ComputeHash(buffer)).Replace("-", String.Empty); }


Thanks,

Jitte Dooper

Hi Jitte,


Sorry for the delayed response on this.

We have verified that when loaded into an instance of MailMessage, the hash code generated is always different for same message. Whereas if we create the hash code from the message file on disk, it is always unique for a message file. Attached to my reply is a sample console application for you reference.

We were trying to present a work around for your situation but I am afraid that we couldn’t come up with a better solution. We will discuss this with our development team and get back to you with some solution.

Apologies for your inconvenience.