Last active
August 8, 2018 06:51
-
-
Save PShuvaev/c4b093cff8aaa58e597784ba7b1955a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
///<summary> | |
/// This example shows the paging support of ImapClient for listing messages from the server | |
/// Available in Aspose.Email for .NET 6.4.0 and onwards | |
///</summary> | |
using (ImapClient client = new ImapClient("host.domain.com", 993, "username", "password")) | |
{ | |
try | |
{ | |
int messagesNum = 12; | |
int itemsPerPage = 5; | |
MailMessage message = null; | |
// Create some test messages and append these to server's inbox | |
for (int i = 0; i < messagesNum; i++) | |
{ | |
message = new MailMessage( | |
"[email protected]", | |
"[email protected]", | |
"EMAILNET-35157 - " + Guid.NewGuid(), | |
"EMAILNET-35157 Move paging parameters to separate class"); | |
client.AppendMessage(ImapFolderInfo.InBox, message); | |
} | |
// List messages from inbox | |
client.SelectFolder(ImapFolderInfo.InBox); | |
ImapMessageInfoCollection totalMessageInfoCol = client.ListMessages(); | |
// Verify the number of messages added | |
Console.WriteLine(totalMessageInfoCol.Count); | |
////////////////// RETREIVE THE MESSAGES USING PAGING SUPPORT//////////////////////////////////// | |
List<ImapPageInfo> pages = new List<ImapPageInfo>(); | |
PageSettings pageSettings = new PageSettings(); | |
ImapPageInfo pageInfo = client.ListMessagesByPage(itemsPerPage, 0, pageSettings); | |
Console.WriteLine(pageInfo.TotalCount); | |
pages.Add(pageInfo); | |
while (!pageInfo.LastPage) | |
{ | |
pageInfo = client.ListMessagesByPage(itemsPerPage, pageInfo.NextPage.PageOffset, pageSettings); | |
pages.Add(pageInfo); | |
} | |
int retrievedItems = 0; | |
foreach (ImapPageInfo folderCol in pages) | |
retrievedItems += folderCol.Items.Count; | |
Console.WriteLine(retrievedItems); | |
} | |
finally | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment