This project is read-only.

Syntax to download no more than X number of messages at a time?

Topics: Help requests
Apr 16, 2014 at 9:40 PM
Hi,

What would the syntax be to have Messages.Download() to only download 10 messages at a time? I can make it download one at a time, or all of the messages at once, but nothing in between.


Thanks,

~S
Apr 17, 2014 at 8:32 AM
Hi slsumner,

the Messages.Download method has a third parameter which allows you to limit the number of messages:
var messageCount = 10;
client.Folders.Inbox.Messages.Download("ALL", MessageFetchMode.ClientDefault, messageCount);
If you give more information on how you imagine the fetching to be done and what information about the messages you need, I can show you the fastest way to do this.

Greets,

Pavel
Apr 17, 2014 at 3:07 PM
Thanks Pavel,

I was calling it incorrectly. I've been having memory issues and was hoping that grabbing a few at a time would help, but that doesn't seem to have done much good in the long run.

My project involves looking at the subject line of each email and if it is a bounced message, parse through the body to collect the bad email address and the actual error message to determine what kind of bounce it is. Once I have scanned an email, it is moved out of the inbox and into a subfolder. Sometimes our host will generate a list of bounces in a single email if they they come back within a certain time frame so it's important that I parse the actual subject and body.


I'm open to any suggestions that you might have. The current behavior of the script is that it will run smoothly for a few emails and then lock up as if it's stuck in an infinite loop. Yesterday I was able to sort through about 300 emails, but this morning I could only do 34. This behavior is also accompanied with a sudden memory spike that goes over 1G. There doesn't appear to be anything odd about the emails. I'm using .Net 4.5 and Outlook 2010.

Thanks!

~S
Apr 17, 2014 at 5:29 PM
Edited Apr 17, 2014 at 5:30 PM
Hi slsumner,

thank you for the explanation! First of all, a note about the high memory usage. There was an issue in the BodyStructureParser which often resulted in memory leaks, and it's been fixed some time ago. You can download the latest source from the repository and test if you still have problems with this issue.

Next, I have an idea about how to optimize the fetching of messages for your task, but first need to ask you a question: Do you need to download the messages in order to check the subject or can the filtering be done on the server by supplying a specific subject part in the search query?
Apr 17, 2014 at 7:58 PM
Edited Apr 18, 2014 at 4:32 PM
Using the latest version (source from the repository) I am getting an out of memory exception thrown on line 317 in BodyStructureParser on sb.append(currentchar). If it helps at all, the line that is trying to parse is: {___BoUnDaRy_1397703572642.781.1193795501738) NIL NIL) UID 1036)???????????????????????????????????????????????????????????????????????????????} This line seems to just not end.
Apr 19, 2014 at 11:56 AM
Hi slsumner,

I will make some more tests and provide a fix for this.

Greets,

Pavel
Apr 25, 2014 at 4:10 PM
Thanks Pavel,

Have you had any luck replicating this issue? Also, in what order would the download script download the messages (oldest first, newest first)? I wonder if there is a particular message that is causing this. If I can narrow it down to a particular email type/structure, that might help both of us.

~S
Apr 28, 2014 at 2:00 PM
Hi slsummer,

yes, I have a few body structures that do not pass the tests now, and updating the code to fix it. An update is coming out tomorrow.

Greets,

Pavel
Apr 30, 2014 at 2:42 PM
Awesome. Looking forward to the update!
May 15, 2014 at 10:48 PM
Hi Pavel,

Has this fix been released? I've downloaded the latest code ad something is still not passing with the same kind of out of memory error. (Visual Studio 2013, VB) is there something I can do to generate a better error for you?

~S
May 16, 2014 at 8:11 PM
Hi slsumner,

yes, but seems that it didn't fix the issue for everyone. I'm working on an update now which is coming next Friday.

Greets,

Pavel
May 28, 2014 at 8:45 PM
Hi pavel,

I've done a bit more testing and it seems that emails with attachments are the most common offender when it comes to breaking the parser. Same line (317) of the BodyStructureParser.