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
(AutoIt) 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.
; This example assumes the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. $oImap = ObjCreate("Chilkat.Imap") ; Connect to an IMAP server. ; Use TLS $oImap.Ssl = True $oImap.Port = 993 Local $bSuccess = $oImap.Connect("imap.someMailServer.com") If ($bSuccess <> True) Then ConsoleWrite($oImap.LastErrorText & @CRLF) Exit EndIf ; Login $bSuccess = $oImap.Login("****","****") If ($bSuccess <> True) Then ConsoleWrite($oImap.LastErrorText & @CRLF) Exit EndIf ; Select an IMAP mailbox $bSuccess = $oImap.SelectMailbox("Inbox") If ($bSuccess <> True) Then ConsoleWrite($oImap.LastErrorText & @CRLF) Exit EndIf Local $oMessageSet ; We can choose to fetch UIDs or sequence numbers. Local $bFetchUids = True ; Get the message IDs of all the emails in the mailbox $oMessageSet = $oImap.Search("ALL",$bFetchUids) If ($oImap.LastMethodSuccess = False) Then ConsoleWrite($oImap.LastErrorText & @CRLF) Exit EndIf Local $iNumFound = $oMessageSet.Count If ($iNumFound = 0) Then ConsoleWrite("No messages found." & @CRLF) Exit EndIf ; Get the 1st 10 messages in messageSet. Local $iUpperBound = 10 If ($iNumFound < $iUpperBound) Then $iUpperBound = $iNumFound EndIf Local $i = 0 Local $bUid = $oMessageSet.HasUids While $i < $iUpperBound Local $oEmail = $oImap.FetchSingleHeader($oMessageSet.GetId($i),$bUid) If ($oImap.LastMethodSuccess = False) Then ConsoleWrite($oImap.LastErrorText & @CRLF) Exit Else ; Do whatever is needed with the 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: $oFirstTen = ObjCreate("Chilkat.MessageSet") For $i = 0 To $iUpperBound - 1 $oFirstTen.InsertId $oMessageSet.GetId($i) Next ; Download the 1st ten headers: Local $oBundle $oBundle = $oImap.FetchHeaders($oFirstTen) If ($oImap.LastMethodSuccess = False) Then ConsoleWrite($oImap.LastErrorText & @CRLF) Exit EndIf ; Other examples show how to iterate over the emails contained within the bundle... ; Disconnect from the IMAP server. $bSuccess = $oImap.Disconnect() |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.