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

asked 06 Apr '11, 17:33

martin's gravatar image

martin
745
accept rate: 0%

edited 06 Apr '11, 20:03

Martin%20Vobr's gravatar image

Martin Vobr ♦♦
335310


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).)

link

answered 06 Apr '11, 17:47

Lukas%20Pokorny's gravatar image

Lukas Pokorny ♦♦
2.4k28
accept rate: 31%

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.

link

answered 07 Apr '11, 12:36

martin's gravatar image

martin
745
accept rate: 0%

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

(07 Apr '11, 15:29) Lukas Pokorny ♦♦

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.

(07 Apr '11, 15:33) Lukas Pokorny ♦♦
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×76
×17
×13
×6

Asked: 06 Apr '11, 17:33

Seen: 805 times

Last updated: 07 Apr '11, 15:33