Outlook.MailItem: ¿hay alguna forma de determinar si dos elementos de correo (enviados a diferentes destinatarios) son iguales?

I would like to know if there is any way to compare two Outlook.MailItems to see if they are the same.

For example, If two people in our company receive the same email, is there a way to compare them for equality?

I was thinking about comparing the the folowing properties:

Subject, To, From, CC, Body

which may work 99% of the time, however as the database grows bigger and bigger this routine will become slower and slower.

Is there a better way to acheive this?

preguntado el 02 de febrero de 12 a las 10:02

Hey Simon I am also want to Compare Subject, To, From, CC, Body Which approach did you used to achieve this ? -

the mailHash method seems to be the best way, store it in the DB and put an index on the column -

2 Respuestas

If you are storing the values, then a hashcode of the properties might be the way to go, using the properties you stated. You could then make this an indexed column to improve search and retrieval performance.

So I guess in C# :

var mailHash = String.Format("{0}{1}{2}{3}{4}", mail.To, mail.From, mail.CC, mail.Subject, mail.Body).GetHashCode();

¿Eso funcionaría para ti?


Respondido 02 Feb 12, 14:02

Cheers - glad to be of service! :) - Bertie

Expanding on this, if you need to use a standard hash, you could also use SHA256. - Matty B

Rather than creating your own hash function, you should use the one really used by the system. In the case of Exchange items, you can check the item's EntryID to get the Exchange ID for the item. I think it will be unique for a local PST as well, but you should make sure of that.

Respondido 02 Feb 12, 17:02

Sorry, ive read that EntryID is not unique, whereby it can change when moving the MailItem between folders - Simon

Not between folders, between stores. It remains identical as long as it's in an Exchange mailbox - any mailbox. But if you move it to a PST file or to a public folder, it can change. But if you're comparing items in corporate folders, it can be a good indicator. - Avner Shahar-Kashtan

The String implementation of GetHashCode() should be sufficient for this. Granted, even the documentation admits that there isn't a unique hash code for all unique strings - but equally, I've yet to run into a collision for two unique strings. And, if you wanted to write your own hash function, I'm sure that wheel has already been invented! :) - Bertie

Won't the EntryID be different for two recipients though - same message, but different mailboxes?! - Bertie

I don't think so. An email sent to several recipient is only stored once in the Exchange database, and should have the same EntryID, as far as I know. - Avner Shahar-Kashtan

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.