After a call to Imap.CopyMessage I need to get the id of the copied message (not the original message).

The IMAP.CopyMessage does not return anything.

asked 07 Jan '11, 13:28

Rebex%20KB's gravatar image

Rebex KB ♦♦
258519
accept rate: 63%


Unfortunately, there is no easy way to get the new uniqueID of a copied message. The IMAP protocol's COPY command doesn't return this information, which is very unfortunate.

But the following approach usually works 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 07 Jan '11, 13:33

Rebex%20KB's gravatar image

Rebex KB ♦♦
258519
accept rate: 63%

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

Asked: 07 Jan '11, 13:28

Seen: 349 times

Last updated: 01 Apr '11, 17:22