Fetching specific message (by UID) + Thread safety

Oct 30, 2013 at 5:22 PM
Hi,

I have a couple of questions related to the latest version:
  1. If I fetched only message UIDs (with MessageFetchMode.None) and now I want to fetch one specific message by its UID, how do I do that? can you show a quick example of searching for one specific message by UID?
  2. As far as you know, is the ImapX library thread-safe? Are there any shared or static variables that could be problematic (e.g. a shared socket or something)?
    I want to use this library from a multi-threaded code, where I will access the same mailbox from multiple threads and also multiple mailboxes from multiple threads - do you see any reason this could be problematic? Did you test for thread-safety somehow?
Thanks a lot!
--Muly
Coordinator
Oct 30, 2013 at 5:54 PM
Hi Muly,

When you search for messages using MessageFetchMode.None, there will be a Message object created for every message and stored in Folder.Messages. To fetch a single message, you can make a call to Message.Download, supplying the needed download mode for this message:
// Init client, authenticate

client.Behavior.MessageFetchMode = MessageFetchMode.None;

var messages = client.Folders.Inbox.Search(/* add a query if needed */);

foreach(var msg in messages)
{
     // Download the message using given mode
     msg.Download(MessageFetchMode.Full); 
}
Coming to thread-safety of ImapX,
at the moment I must say you will experience some issues accessing a single ImapClient from different threads. However, this problem should be resolved soon.
I'm working on implementing IDLE support and asynchronious methods now, so making the library thread-safe is on high priority.
I hope to release the first update in around one to two weeks.

Best regards,

Pavel