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
|
(IOS) 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 IOS (IPhone) Objective-C Libraries NSMutableString *strOutput = [NSMutableString stringWithCapacity:1000]; CkoImap *imap = [[[CkoImap alloc] init] autorelease]; BOOL success; // Anything unlocks the component and begins a fully-functional 30-day trial. success = [imap UnlockComponent: @"Anything for 30-day trial"]; if (success != YES) { [strOutput appendString: imap.LastErrorText]; [strOutput appendString: @"\n"]; self.mainTextField.stringValue = strOutput; return; } // Connect to an IMAP server. success = [imap Connect: @"mail.chilkatsoft.com"]; if (success != YES) { [strOutput appendString: imap.LastErrorText]; [strOutput appendString: @"\n"]; self.mainTextField.stringValue = strOutput; return; } // Login success = [imap Login: @"****" password: @"****"]; if (success != YES) { [strOutput appendString: imap.LastErrorText]; [strOutput appendString: @"\n"]; self.mainTextField.stringValue = strOutput; return; } // Select an IMAP mailbox success = [imap SelectMailbox: @"Inbox"]; if (success != YES) { [strOutput appendString: imap.LastErrorText]; [strOutput appendString: @"\n"]; self.mainTextField.stringValue = strOutput; return; } CkoMessageSet *messageSet; // We can choose to fetch UIDs or sequence numbers. BOOL fetchUids; fetchUids = YES; // Get the message IDs of all the emails in the mailbox messageSet = [imap Search: @"ALL" bUid: fetchUids]; if (messageSet == nil ) { [strOutput appendString: imap.LastErrorText]; [strOutput appendString: @"\n"]; self.mainTextField.stringValue = strOutput; return; } int numFound; numFound = [messageSet.Count intValue]; if (numFound == 0) { [strOutput appendString: @"No messages found."]; [strOutput appendString: @"\n"]; self.mainTextField.stringValue = strOutput; 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++) { CkoEmail *email; email = [imap FetchSingleHeader: [messageSet GetId: [NSNumber numberWithInt: i]] bUid: bUid]; if (email == nil ) { [strOutput appendString: imap.LastErrorText]; [strOutput appendString: @"\n"]; self.mainTextField.stringValue = strOutput; 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: CkoMessageSet *firstTen = [[[CkoMessageSet alloc] init] autorelease]; for (i = 0; i <= upperBound - 1; i++) { [firstTen InsertId: [messageSet GetId: [NSNumber numberWithInt: i]](ERROR: No argument at index 1: MessageSet:InsertId); } // Download the 1st ten headers: CkoEmailBundle *bundle; bundle = [imap FetchHeaders: firstTen]; if (bundle == nil ) { [strOutput appendString: imap.LastErrorText]; [strOutput appendString: @"\n"]; self.mainTextField.stringValue = strOutput; return; } // Other examples show how to iterate over the emails contained within the bundle... // Disconnect from the IMAP server. [imap Disconnect]; self.mainTextField.stringValue = strOutput; |
© 2000-2013 Chilkat Software, Inc. All Rights Reserved.