Walking thrue lot of e-mails in folder

Topics: Help requests
Feb 28, 2014 at 8:03 AM
Hello, could you recommend me the best practice how to walk thrue 1000 e-mails in Inbox?

Next code seems to be very memory consuming.
  imapClient.Folders.Inbox.Messages.Download("ALL", Enums.MessageFetchMode.Full, -1)
                For Each mx In imapClient.Folders.Inbox.Messages
                    ...
                Next
Sincerely Miroslav
Coordinator
Feb 28, 2014 at 11:10 AM
Hi Miroslav,

ImapX offers various downloas modes for messages, which makes it easier to limit the amount of the data to be downloaded.

To provide you with a solution which on the one hand does all you need, and on the other hand offers good performance, I need to know exactly what you plan to do with the messages within the for..each in your code.

Greets,

Pavel
Feb 28, 2014 at 12:07 PM
Hi Pavel,

I only need to read all messages in Inbox and Sent in loop and save them as EML in local folders.

Thank you very much for your help

Miroslav
Coordinator
Feb 28, 2014 at 1:51 PM
Hi Miroslav,

in this case you can use the following approach:
' First of all, we change the global download mode of the client to write less code later
' Setting the fetch mode to None will only request the message UIds, and nothing else
imapClient.Behavior.MessageFetchMode = MessageFetchMode.None

' Next, we  perform a download, fetching only the UIds
imapClient.Inbox.Messages.Download()

'Now we can loop through the messages in the folder and request the EML data for each of them:
For Each msg In imapClient.Folders.Inbox.Messages
      
      Dim eml = msg.DownloadRawMessage()

Next
This solution should work faster than the one you are using.

The method DownloadRawMessage is now only available in the latest code in the repository. If you don't want to compile it yourself, just let me know which .Net version you're using, I'll compile the library for you.
Marked as answer by pavel_azanov on 3/4/2014 at 4:20 AM
Feb 28, 2014 at 2:00 PM
Hi Pavel,

thank you for your quick response!

I am using VB.NET 4.5.

Sincerely Miroslav
Mar 1, 2014 at 6:50 AM
Hi Pavel,
I forgot to kindly ask you for sending compiled DLL (4 or 4.5).
So be so kind - thanks.
Miroslav
Coordinator
Mar 1, 2014 at 10:49 AM
Hi Miroslav,

here you are: ImapX 2.0.0.15 for .Net 4.5, compiled on 1st March 2014

Greets,

Pavel
Mar 1, 2014 at 2:09 PM
Hi Pavel,

thanks a lot.

It seems it is working perfect!!

Miroslav