+1 vote

If I execute the below code to move an email by UID from the "Inbox" to a folder called "Inbox.Testing". Then the UID does not remain the same.

IMapClient.MoveByUID(uid, targetFolder);

To test the numbers I execute a search IMapClient.Search("Inbox")... and store the UID's in a Dictionary along with the IMail. I then carry out the move operation and carry out another search in the testing folder using the same process and the UID's are not the same.

From what I understand the UID remains the same providing its the same session even across folders.

I am using hMailServer.

by (870 points)

1 Answer

+1 vote
 
Best answer

This is expected and correct IMAP protocol behavior.

UIDs don't identify emails uniquely across entire IMAP account. Two or more different emails may have exactly the same UID, as long as they are in different folders. You can read more in Unique ID in IMAP protocol article.

MOVE command (or if IMAP server doesn't support MOVE, COPY and DELE) assigns new UIDs to the moved/copied messages. Those UIDs are valid in the destination folder only.

Imap.MoveByUID method returns a single UID or UIDs assigned to the email(s) in the destination IMAP folder.

by (301k points)
selected by
...