I'm absolutely sure Imap.MoveByUID
works properly, especially with Gmail.
As Gmail supports UIDPLUS extension Imap.MoveByUID
returns UIDs as well.
I just wrote a simple test to double check this:
// Create test folders:
const string source = "[Gmail]/folder1";
const string destination = "[Gmail]/folder2";
client.CreateFolder(source);
client.CreateFolder(destination);
// Create sample message
MailBuilder builder = new MailBuilder();
builder.Subject = "MoveTest-20210104";
IMail email = builder.Create();
// Select source folder and upload:
client.Select(source);
long uploadedUid = (long)client.UploadMessage(email);
// Move message to destination:
long movedUid = (long)client.MoveByUID(uploadedUid, destination);
// Check message is no longer in source:
Assert.AreEqual(0, client.GetAll().Count);
// download message from destination folder:
client.Select(destination);
byte[] movedEml = client.GetMessageByUID(movedUid);
IMail moved = new MailBuilder().CreateFromEml(movedEml);
// Check if it it is the same message:
Assert.AreEqual("MoveTest-20210104", moved.Subject);
// Cleanup:
client.DeleteFolder(source);
client.DeleteFolder(destination);
And the log:
Connecting to 'imap.gmail.com:993', SSL/TLS: True.
S: * OK Gimap ready for requests from XXX
....
C: 105C0004 CREATE [Gmail]/folder1
S: 105C0004 OK Success
C: 105C0005 CREATE [Gmail]/folder2
S: 105C0005 OK Success
C: 105C0006 SELECT [Gmail]/folder1
S: * OK [UIDVALIDITY 627135710] UIDs valid.
S: * 0 EXISTS
S: * 0 RECENT
S: * OK [UIDNEXT 1] Predicted next UID.
S: * OK [HIGHESTMODSEQ 1196438]
S: 105C0006 OK [READ-WRITE] [Gmail]/folder1 selected. (Success)
C: 105C0007 APPEND [Gmail]/folder1 (\SEEN) {227}
S: + go ahead
C (229 bytes):
Content-Type: text/plain;
charset="utf-8"
Content-Transfer-Encoding: 7bit
MIME-Version: 1.0
Date: Mon, 04 Jan 2021 22:23:43 +0100
Message-ID: <bbf2247e-2d2b-409b-b840-b77d1ef90262@mail.dll>
Subject: MoveTest-20210104
S: * 1 EXISTS
S: 105C0007 OK [APPENDUID 627135710 1] (Success)
C: 105C0008 UID MOVE 1 [Gmail]/folder2
S: * 1 EXPUNGE
S: * 0 EXISTS
S: 105C0008 OK [COPYUID 627135711 1 1] (Success)
C: 105C0009 NOOP
S: 105C0009 OK Success
C: 105C000A UID SEARCH RETURN (ALL) ALL
S: * ESEARCH (TAG "105C000A") UID
S: 105C000A OK SEARCH completed (Success)
C: 105C000B SELECT [Gmail]/folder2
S: * OK [UIDVALIDITY 627135711] UIDs valid.
S: * 1 EXISTS
S: * 0 RECENT
S: * OK [UIDNEXT 2] Predicted next UID.
S: * OK [HIGHESTMODSEQ 1196459]
S: 105C000B OK [READ-WRITE] [Gmail]/folder2 selected. (Success)
C: 105C000C UID FETCH 1 (UID BODY[])
S: * 1 FETCH (UID 1 BODY[] {227}
S (227 bytes):
Content-Type: text/plain;
charset="utf-8"
Content-Transfer-Encoding: 7bit
MIME-Version: 1.0
Date: Mon, 04 Jan 2021 22:23:43 +0100
Message-ID: <bbf2247e-2d2b-409b-b840-b77d1ef90262@mail.dll>
Subject: MoveTest-20210104
S: )
S: 105C000C OK Success
C: 105C000D DELETE [Gmail]/folder1
S: 105C000D OK Success
C: 105C000E DELETE [Gmail]/folder2
S: 105C000E OK Success
Are you sure you are using UIDs (not numbers)?
Are you sure you are using MoveByUID (not MoveByNumber)?
Please also remember that UIDs are valid only within a same folder, they don't identify the message globally:
https://www.limilabs.com/blog/unique-id-in-imap-protocol