I'm trying to optimize my program to run most efficiently. Right now, I have
Before I rewrite the code to try this method, I want to see if there is a way to filter the emails before they are loaded into memory.
ImapX.Folder myInbox = client.Folders.Inbox;
ImapX.Folder myArchive = client.Folders.All;
ImapX.Message[] messages = myInbox.Search("ALL", ImapX.Enums.MessageFetchMode.Basic | ImapX.Enums.MessageFetchMode.GMailExtendedData, 1000);
with some filters a bit later on doing this if (messages[i].From.DisplayName.Contains("Company A") || messages[i].From.DisplayName.Contains("Company B"))
{
if (!messages[i].Labels.Contains("Processed")
&& !messages[i].Labels.Contains("Research")
&& !messages[i].Labels.Contains("MANUAL")
&& !messages[i].Labels.Contains("Failed")
&& !messages[i].Labels.Contains("Success")
&& !messages[i].Labels.Contains("Duplicate"))
{//check email}
I am now thinking it might better/more efficient to loop through one message at a time, check it, and process it - rather than loading 100 - 1000 emails into memory. Before I rewrite the code to try this method, I want to see if there is a way to filter the emails before they are loaded into memory.