Chilkat HOME Android™ ASP Visual Basic VB.NET C# iOS (IPhone) Objective-C C++ C Unicode C++ Unicode C MFC Delphi DLL Delphi ActiveX FoxPro Java Perl PHP Extension PHP ActiveX Python PowerShell Ruby SQL Server VBScript
(C#) Fetch 1st N Headers of Search ResultsCalls Search to get a message set, then downloads the 1st N messages in the message set. There are two equivalent ways of doing it: (1) iterate from 0 to N-1 and download each message individually, or (2) create a new message set that contains the 1st N messages and pass it to FetchHeaders. Both are demonstrated here. Download: Chilkat .NET Assemblies Chilkat.Imap imap = new Chilkat.Imap(); bool success; // Anything unlocks the component and begins a fully-functional 30-day trial. success = imap.UnlockComponent("Anything for 30-day trial"); if (success != true) { textBox1.Text += imap.LastErrorText + "\r\n"; return; } // Connect to an IMAP server. success = imap.Connect("mail.chilkatsoft.com"); if (success != true) { textBox1.Text += imap.LastErrorText + "\r\n"; return; } // Login success = imap.Login("****","****"); if (success != true) { textBox1.Text += imap.LastErrorText + "\r\n"; return; } // Select an IMAP mailbox success = imap.SelectMailbox("Inbox"); if (success != true) { textBox1.Text += imap.LastErrorText + "\r\n"; return; } Chilkat.MessageSet messageSet = null; // We can choose to fetch UIDs or sequence numbers. bool fetchUids; fetchUids = true; // Get the message IDs of all the emails in the mailbox messageSet = imap.Search("ALL",fetchUids); if (messageSet == null ) { textBox1.Text += imap.LastErrorText + "\r\n"; return; } int numFound; numFound = messageSet.Count; if (numFound == 0) { textBox1.Text += "No messages found." + "\r\n"; return; } // Get the 1st 10 messages in messageSet. int maxToGet; maxToGet = 10; int upperBound; upperBound = 10; if (numFound < upperBound) { upperBound = numFound; } int i; bool bUid; bUid = messageSet.HasUids; for (i = 0; i <= upperBound - 1; i++) { Chilkat.Email email = null; email = imap.FetchSingleHeader(messageSet.GetId(i),bUid); if (email == null ) { textBox1.Text += imap.LastErrorText + "\r\n"; return; } else { // Do whatever is needed with the email.. // .... } } // Alternatively, create a new message set containing the 1st 10 message id's (UID's) // from the search results message set: Chilkat.MessageSet firstTen = new Chilkat.MessageSet(); for (i = 0; i <= upperBound - 1; i++) { firstTen.InsertId(messageSet.GetId(i),bUid); } // Download the 1st ten headers: Chilkat.EmailBundle bundle = null; bundle = imap.FetchHeaders(firstTen); if (bundle == null ) { textBox1.Text += imap.LastErrorText + "\r\n"; return; } // Other examples show how to iterate over the emails contained within the bundle... // Disconnect from the IMAP server. imap.Disconnect(); |
© 2000-2013 Chilkat Software, Inc. All Rights Reserved.