AutoIt
AutoIt
Fetch Full Email Given Email Header
When you fetch email headers using UIDs instead of sequence numbers, the email object (which includes only the header) will have auto-generatedckx-imap-* headers. These headers provide details like the UID and attachments. The IMAP UID is found in the ckx-imap-uid header. Additionally, the ckx-imap-isUid header indicates whether the email header was downloaded by UID, showing YES or NO. Since sequence numbers can change if emails are deleted, UIDs are essential for downloading the correct full email.
The Chilkat Email object offers a GetImapUid method to retrieve the UID from the ckx-imap-uid header. This UID can be used to fetch the full email.
Chilkat AutoIt Downloads
Local $bSuccess = False
; This example requires 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
$bSuccess = $oImap.Connect("imap.example.com")
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf
; Login
$bSuccess = $oImap.Login("***","***")
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf
; Select an IMAP mailbox
$bSuccess = $oImap.SelectMailbox("Inbox")
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf
$oEmailHeader = ObjCreate("Chilkat.Email")
$oEmailFull = ObjCreate("Chilkat.Email")
Local $iUid = 2014
Local $bIsUid = True
; Fetch only the email header
$bSuccess = $oImap.FetchEmail(True,$iUid,$bIsUid,$oEmailHeader)
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf
; Now fetch the full email
Local $iUidFromCkxHeader = $oEmailHeader.GetImapUid()
If ($iUidFromCkxHeader < 0) Then
; Failed.
ConsoleWrite("No ckx-imap-uid header was found." & @CRLF)
Exit
EndIf
$bSuccess = $oImap.FetchEmail(False,$iUid,$bIsUid,$oEmailFull)
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf
; OK, we have the full email, do whatever we want...
; Disconnect from the IMAP server.
$bSuccess = $oImap.Disconnect()