Get message id after StoreMessage

0 votes
asked Mar 23, 2011 by martin (990 points)
edited Mar 25, 2011

Hello there, I always get an error if i call GetMessageInfo directly after StoreMessage-Method with returned UniqueID as parameter. Here's my code snippet.

Dim sMessageUniqueID As String = oImap.StoreMessage(oImap.CurrentFolder.Name, oMailMessage)

' now we want to get the "new" message id from stored message

Dim oImapMessageInfo As ImapMessageInfo = oImap.GetMessageInfo(sMessageUniqueID, ImapListFields.Fast)

-> Exception: "Message not found."

thank you in advance and have a nice day

Applies to: Rebex Secure Mail
commented Mar 24, 2011 by Lukas Pokorny (110,970 points)
It looks like your code is OK, the message should have been found. Please use Imap object's LogWriter property to create a log of communication (as described at http://www.rebex.net/kb/logging.aspx) and either mail it to us (support@rebex.net) for analysis or edit your question to include it. We should be able to tell what is going on then.

1 Answer

+1 vote
answered Mar 25, 2011 by Lukas Pokorny (110,970 points)
edited Mar 25, 2011
 
Best answer

According to the log you sent us, you are using Courier IMAP server and we have been able to reproduce the same issue on it. Calling Imap object's CheckForUpdates method after StoreMessage appears to solve it:

Dim sMessageUniqueID As String = oImap.StoreMessage(oImap.CurrentFolder.Name, oMailMessage)

' force the server to send message status updates
oImap.CheckForUpdates();

' now we want to get the "new" message id from stored message
Dim oImapMessageInfo As ImapMessageInfo = oImap.GetMessageInfo(sMessageUniqueID, ImapListFields.Fast)

This is not needed on most IMAP servers which send the message status updates before the APPEND command (used by StoreMessage method) completes.

We will consider doing this automatically in one of the future releases of Rebex Mail.

commented Mar 25, 2011 by martin (990 points)
ok, that works. thank you very much. but which ImapListFields-option is the minimum to get the message id?
commented Mar 25, 2011 by Lukas Pokorny (110,970 points)
What do you mean by message ID, exactly? ImapListFields.SequenceNumber is all you need to get message's sequence number, ImapListFields.UniqueID is all you need to get its unique ID (but you already have that one in sMessageUniqueID. If you would rather have the protocol-level ID instead of its Rebex-only string representation, use ImapMessageSet.ParseUniqueId to parse the sMessageUniqueID into its two parts.
commented Mar 25, 2011 by martin (990 points)
o sorry. i mean the ImapMessageInfo.MessageId.Id, like <4D7B56BF.8060902@arcor.de> if i use ImapListFields.Fast I did not get it
commented Mar 25, 2011 by Lukas Pokorny (110,970 points)
I forgot that one, sorry! You need ImapListFields.Envelope to get this MessageId.
...