ListFolder() returns wrong msg count

Hi guys, I have been running your product through some paces to see if I’m interested in purchasing it. I am experiencing a bug where if I write the following code to list the total messages for the folder I get the wrong number:


// Get all folders
Aspose.Email.Imap.ImapFolderInfoCollection folderInfoColl = imap.ListFolders();
// Iterate through the collection to get folder info one by one
foreach (Aspose.Email.Imap.ImapFolderInfo folderInfo in folderInfoColl)
{
if (folderInfo.Selectable == true)
{
// Send status command to get folder info
Aspose.Email.Imap.ImapFolderInfo folderInfoStatus = imap.ListFolder(folderInfo.Name);
Console.WriteLine(folderInfoStatus.Name + " folder - Total messages: " + folderInfoStatus.TotalMessageCount);
}
try
{
// If this folder has sub-folders, call this method to get messages
Aspose.Email.Imap.ImapFolderInfoCollection subfolderInfoCollection = imap.ListFolders(folderInfo.Name);
foreach (Aspose.Email.Imap.ImapFolderInfo subfolderInfo in subfolderInfoCollection)
{
if(subfolderInfo.Selectable == true)
{
Aspose.Email.Imap.ImapFolderInfo subfolderInfoStatus = imap.ListFolder(subfolderInfo.Name);
Console.WriteLine(subfolderInfoStatus.Name + " - Total messages: " + subfolderInfoStatus.TotalMessageCount);
}
}
}
catch (Exception) { }
}

I should note that if I select the folder I can get the total message count with

Aspose.Email.Imap.ImapMessageInfoCollection listMsgs = imap.ListMessages();

and

listMsgs.Count;

I’ve written a version of this script that I know works in Python. I’ve attached a picture of them running side by side to demonstrate the problem. I can only verify that this problem exists with gmail accounts.

Hi Jamaal,

Thanks for writing to Aspose.Email support team.

I tried to re-produce the issue here by using Aspose.Email and another commercial library Limilabs. I am afraid to inform that I got similar results for “Inbox” and “All Mail” count for my test Gmail account.

For further investigation, we request you to please share credentials of some sample Gmail account which can be used to re-produce the issue here. It will help us to provide assistance as soon as possible.

For your reference, sample code is given below using above mentioned commercial library.

using System;
using System.Collections.Generic;
using Limilabs.Client.IMAP;

namespace TestLimilab
{
class Program
{
static void Main(string[] args)
{
EMAIL_TestMailCounterLimilabs();
Console.ReadKey();
}
static void EMAIL_TestMailCounterLimilabs()
{
using (Imap imap = new Imap())
{
imap.ConnectSSL(“[imap.gmail.com](http://imap.gmail.com/)”,993); // or ConnectSSL for SSL
imap.UseBestLogin("username@gmail.com", “password”);
imap.Select("[Gmail]/All Mail");
List<long> uidList1 = imap.Search(Flag.All);
Console.WriteLine("All Mail List count = " + uidList1.Count);
imap.SelectInbox();
List<long> uidList2 = imap.Search(Flag.All);
Console.WriteLine("Inbox List count = " + uidList2.Count);
imap.Close();
}
}
}
}

Hmmm… Well I was testing on my personal account and I wouldn’t want to give you that info :wink: I will try to set up a demo account and recreate the issue.


I noticed in your Limilab sample code you selected the folder before getting the msg count. That method works as well in Aspose’s library. It is only when I use the ListFolder(someFolder) function without explicitly selecting the folder and requesting the messages that I get a miscount. Could you please provide the code that you used for the ListFolder function? I’m pretty sure I didn’t use it incorrectly, but I’d like to be sure.

Hi Jamaal,


I used your sample code without any changes for this comparison.