0 votes

When forwarding a message I display all attachments in a checkbox list. A user may remove/uncheck attachments before sendin. On submit I would like to identify the checked attachments. But e.g. ContentId is empty/null for all regular attachments and filename doesn't necessary have to be unique. So how can I identify a single attachment? There doesn't seem to be a property for this on the MimeData class.

by

1 Answer

0 votes

You could probably use MimeData.GetHashCode for that.

[Edit]
From Mail.dll's perspective, if you are recreating MaimeData object, this is a new object - there is no need for it to store some kind of id internally.

It is your scenario that, makes this object somehow equal to the previous one. Please note, that the problem you are facing is not at all Mail.dll related.

Consider computing hash from the raw data, if you believe same file name is not enough.

by (301k points)
edited by
MimeData.GetHashCode() seems to keep changing. At least it does when I postback an (re)call GetHashCode on the attachments.
It will change if you are recreating object instance.
Of course I'm recreating the instance. When displaying the page and after postback to find out what attachments were checked. I'm currently using FileName to find the checked attachment again. But this is not safe, because I can very simply add two attachments with the same name. It would be nice to have a Uid property on MimeData. IMAP must have a unique id/content id for each attachment, internally, not?
I'm not sure what you mean. You are not interacting with IMAP at this point. From Mail.dll's perspective this is a new object, there is no need for it to store some kind of id internally.
...