AutoIt
AutoIt
Get IMAP UID from Email Header
See more IMAP Examples
Demonstrates how to get the IMAP UID from an email header. After fetching an email or header using IMAP, the UID is contained in the ckx-imap-uid header field.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("login","password")
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
Local $bFetchUids = True
; Get the message UIDs of all the emails in the mailbox
$oMessageSet = ObjCreate("Chilkat.MessageSet")
$bSuccess = $oImap.QueryMbx("ALL",$bFetchUids,$oMessageSet)
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf
$oBundle = ObjCreate("Chilkat.EmailBundle")
Local $bHeadersOnly = True
$bSuccess = $oImap.FetchMsgSet($bHeadersOnly,$oMessageSet,$oBundle)
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf
; The UID of each fetched email header is available
; in the ckx-imap-uid header field.
$oEmail = ObjCreate("Chilkat.Email")
$oMsgSet1 = ObjCreate("Chilkat.MessageSet")
Local $i = 0
Local $iSzBundle = $oBundle.MessageCount
While $i < $iSzBundle
$oBundle.EmailAt($i,$oEmail)
; Build a message set containing one UID
Local $sUidStr = $oEmail.GetHeaderField("ckx-imap-uid")
$oMsgSet1.FromCompactString($sUidStr)
; Move this message to some other folder.
$bSuccess = $oImap.MoveMessages($oMsgSet1,"someOtherFolder")
If ($bSuccess <> True) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
; Exit the loop...
$i = $iSzBundle
EndIf
$i = $i + 1
Wend
; Disconnect from the IMAP server.
$bSuccess = $oImap.Disconnect()