Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PureBasic) 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.
IncludeFile "CkImap.pb" IncludeFile "CkEmailBundle.pb" IncludeFile "CkMessageSet.pb" IncludeFile "CkEmail.pb" Procedure ChilkatExample() ; This example assumes the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. imap.i = CkImap::ckCreate() If imap.i = 0 Debug "Failed to create object." ProcedureReturn EndIf ; Connect to an IMAP server. ; Use TLS CkImap::setCkSsl(imap, 1) CkImap::setCkPort(imap, 993) success.i = CkImap::ckConnect(imap,"imap.someMailServer.com") If success <> 1 Debug CkImap::ckLastErrorText(imap) CkImap::ckDispose(imap) ProcedureReturn EndIf ; Login success = CkImap::ckLogin(imap,"****","****") If success <> 1 Debug CkImap::ckLastErrorText(imap) CkImap::ckDispose(imap) ProcedureReturn EndIf ; Select an IMAP mailbox success = CkImap::ckSelectMailbox(imap,"Inbox") If success <> 1 Debug CkImap::ckLastErrorText(imap) CkImap::ckDispose(imap) ProcedureReturn EndIf messageSet.i ; We can choose to fetch UIDs or sequence numbers. fetchUids.i = 1 ; Get the message IDs of all the emails in the mailbox messageSet = CkImap::ckSearch(imap,"ALL",fetchUids) If CkImap::ckLastMethodSuccess(imap) = 0 Debug CkImap::ckLastErrorText(imap) CkImap::ckDispose(imap) ProcedureReturn EndIf numFound.i = CkMessageSet::ckCount(messageSet) If numFound = 0 Debug "No messages found." CkMessageSet::ckDispose(messageSet) CkImap::ckDispose(imap) ProcedureReturn EndIf ; Get the 1st 10 messages in messageSet. upperBound.i = 10 If numFound < upperBound upperBound = numFound EndIf i.i = 0 bUid.i = CkMessageSet::ckHasUids(messageSet) While i < upperBound email.i = CkImap::ckFetchSingleHeader(imap,CkMessageSet::ckGetId(messageSet,i),bUid) If CkImap::ckLastMethodSuccess(imap) = 0 Debug CkImap::ckLastErrorText(imap) CkMessageSet::ckDispose(messageSet) CkImap::ckDispose(imap) ProcedureReturn Else ; Do whatever is needed with the email.. ; .... CkEmail::ckDispose(email) EndIf i = i + 1 Wend ; Alternatively, create a new message set containing the 1st 10 message id's (UID's) ; from the search results message set: firstTen.i = CkMessageSet::ckCreate() If firstTen.i = 0 Debug "Failed to create object." ProcedureReturn EndIf For i = 0 To upperBound - 1 CkMessageSet::ckInsertId(firstTen,CkMessageSet::ckGetId(messageSet,i)) Next CkMessageSet::ckDispose(messageSet) ; Download the 1st ten headers: bundle.i bundle = CkImap::ckFetchHeaders(imap,firstTen) If CkImap::ckLastMethodSuccess(imap) = 0 CkMessageSet::ckDispose(firstTen) Debug CkImap::ckLastErrorText(imap) CkImap::ckDispose(imap) CkMessageSet::ckDispose(firstTen) ProcedureReturn EndIf ; Other examples show how to iterate over the emails contained within the bundle... ; Disconnect from the IMAP server. success = CkImap::ckDisconnect(imap) CkMessageSet::ckDispose(firstTen) CkEmailBundle::ckDispose(bundle) CkImap::ckDispose(imap) CkMessageSet::ckDispose(firstTen) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.