Processing message after Folder.Search method executed

May 9, 2013 at 9:48 AM
Hi. Thanks for your library, we are considering to use it for large project which will connect to lot of IMAP servers.

I found one issue, which I was able to fix locally by changing source codes of your library.

What we need:

We need to call Folder.Search method with bool makeProcess set to false;
And then later process each message returned by calling message.Process() method

But that doesnt work, and I think it is because after Folder.Search is done - Client returns to previous selected folder.

So what I did
  1. I added new field to Message class
internal Folder Folder; 
  1. In Folder.Search method - i added code to initialize Folder field of Message instance
foreach (var current in messageCollection)
                current.Client = Client;
                __current.Folder = this;__
                if (makeProcess)
  1. Then in Message.Process method I wrapped entire code into try catch; then in beginning I added this code
if (Client.SelectedFolder != Folder.FolderPath)
                    returnToFolder = Client.SelectedFolder;
and in finally part of try catch I added code to return to original folder
if (!string.IsNullOrEmpty(returnToFolder))
returnToFolder is variable defined before try catch in Process method.

Please review this and if you think this is correct way to resolve issue, I guess you can include these changes into your library?

May 9, 2013 at 10:55 AM
Hi axlns,

thank you for the code snippets! I will review it and include in the source code, so we have same code base.

Best regards,

Pavel Azanov
May 9, 2013 at 11:02 AM
Hi Pavel.

Sounds great. Thanks
May 10, 2013 at 8:54 AM
Good day,

I reviewed your suggestion and the code is now part of ImapX, you can update to the latest code from the repository.

Best regards,

Pavel Azanov
May 13, 2013 at 3:17 PM
I made another update to support your code, there was a small bug which caused an object reference not set to an instance error. You can update to the latest code from the repository.
May 13, 2013 at 3:31 PM
OK. Thanks for your help.