+1 vote
by (990 points)
edited

hello, i've tried to copy a message from one imap folder to another, afterwards i delete the base message. The purpose is in fact a move. the copy is ok, but why doesn't the copymessage call return the new message id? how can i get the message id of the copy?

        oImap.CopyMessage(sMessageUniqueID, oDestinationFolderInfo.sProp("ImapFolderName"))

        If Not bCopyMessage Then
            oImap.DeleteMessage(sMessageUniqueID)
        End If
Applies to: Rebex Secure Mail

2 Answers

0 votes
by (147k points)
edited

Unfortunately, there is no easy way to get the new uniqueID (Rebex ID) of a copied message. The IMAP protocol's COPY command doesn't return this information, unfortunately.

But the following approach usually works fine and is simple enough:

' get the "next unique ID" of the target folder 
Dim nextUniqueId As String = imap.GetFolderInfo("Other").NextUniqueId

' select the Inbox folder and copy a set of messages to Other folder
imap.SelectFolder("Inbox")
imap.CopyMessage(messageSet, "Other")

' select the Other folder and search for all messages whose unique ID is equal to "next unique ID" or larger
imap.SelectFolder("Other")
Dim newSet As New ImapMessageSet
newSet.AddRange(nextUniqueId, ImapMessageSet.BuildUniqueId(imap.CurrentFolder.ValidityId, UInt32.MaxValue))
ImapMessageCollection list = imap.Search(ImapListFields.UniqueId, ImapSearchParameter.MessageSet(newSet))

' now, the list should contain info about the copy message including its unique ID

(You might also speed things up a bit more (depending on the server) by selecting folders in read-only mode (see SelectFolder's second argument).)

0 votes
by (990 points)
edited

I can't believe that a move from a message is so complicated. I've tried your suggestion, but I always get an "Error in IMAP command received by server (NO)." on imap.Search-command Can you please help me out there!? my code is exactly like your post.

by (147k points)
edited

Actually, the code above is in fact unnecessarily complicated because it was designed to work for multiple copied messages. If you copy/move messages one-by-one and you are the only one accessing the IMAP account, the following code alone should get the new message ID: Dim nextUniqueId As String = imap.GetFolderInfo("Other").NextUniqueId

by (147k points)
edited

However, would it be possible to create a communication log of the code in my post using Imap object's LogWriter property (as described at http://www.rebex.net/kb/logging.aspx) and mail it to us for analysis? It looks like your IMAP server doesn't like our search command, and we would really like to know why.

...