Skip to content

Instantly share code, notes, and snippets.

@PShuvaev
Created August 9, 2018 06:38
Show Gist options
  • Save PShuvaev/3904f48ae8e1cdcc91a0dfb6dcac111a to your computer and use it in GitHub Desktop.
Save PShuvaev/3904f48ae8e1cdcc91a0dfb6dcac111a to your computer and use it in GitHub Desktop.
using (ImapClient client = new ImapClient("host.domain.com", 84, "username", "password"))
{
try
{
// Append some test messages
int messagesNum = 12;
int itemsPerPage = 5;
MailMessage message = null;
for (int i = 0; i < messagesNum; i++)
{
message = new MailMessage(
"[email protected]",
"[email protected]",
"EMAILNET-35128 - " + Guid.NewGuid(),
"111111111111111");
client.AppendMessage(ImapFolderInfo.InBox, message);
}
string body = "2222222222222";
for (int i = 0; i < messagesNum; i++)
{
message = new MailMessage(
"[email protected]",
"[email protected]",
"EMAILNET-35128 - " + Guid.NewGuid(),
body);
client.AppendMessage(ImapFolderInfo.InBox, message);
}
client.SelectFolder("Inbox");
ImapQueryBuilder iqb = new ImapQueryBuilder();
iqb.Body.Contains(body);
MailQuery query = iqb.GetQuery();
client.SelectFolder(ImapFolderInfo.InBox);
ImapMessageInfoCollection totalMessageInfoCol = client.ListMessages(query);
Console.WriteLine(totalMessageInfoCol.Count);
//////////////////////////////////////////////////////
List<ImapPageInfo> pages = new List<ImapPageInfo>();
PageSettings pageSettings = new PageSettings();
pageSettings.FolderName = ImapFolderInfo.InBox;
ImapPageInfo pageInfo = client.ListMessagesByPage(query, new PageInfo(itemsPerPage, 0), pageSettings);
pages.Add(pageInfo);
while (!pageInfo.LastPage)
{
pageInfo = client.ListMessagesByPage(query, pageInfo.NextPage, pageSettings);
pages.Add(pageInfo);
}
int retrievedItems = 0;
foreach (ImapPageInfo folderCol in pages)
retrievedItems += folderCol.Items.Count;
}
finally
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment