AutoIt
AutoIt
Refresh an Email Object's IMAP Flags
See more IMAP Examples
Demonstrates the Chilkat Imap.RefetchMailFlags method, which updates the flags stored on an Email object to the current values on the server. The only argument is the Email object. This example re-reads the flags for a previously fetched message and then checks its Seen state.
Background: Flags are shared mailbox state, so between the time you fetch a message and the time you act on it, another client (a phone, a webmail tab) may have marked it read, flagged, or deleted.
RefetchMailFlags pulls just the flags — not the whole message — so a long-running job can cheaply re-check the live state before deciding what to do, avoiding acting on stale information.Chilkat AutoIt Downloads
Local $bSuccess = False
; Demonstrates the Imap.RefetchMailFlags method, which updates the flags stored on an Email
; object to the current values on the server. The only argument is the Email object.
$oImap = ObjCreate("Chilkat.Imap")
$oImap.Ssl = True
$oImap.Port = 993
$bSuccess = $oImap.Connect("imap.example.com")
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf
$bSuccess = $oImap.Login("user@example.com","myPassword")
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf
$bSuccess = $oImap.SelectMailbox("Inbox")
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf
$oMsgSet = ObjCreate("Chilkat.MessageSet")
$bSuccess = $oImap.QueryMbx("ALL",True,$oMsgSet)
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf
$oBundle = ObjCreate("Chilkat.EmailBundle")
$bSuccess = $oImap.FetchMsgSet(True,$oMsgSet,$oBundle)
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf
$oEmail = ObjCreate("Chilkat.Email")
If ($oBundle.MessageCount > 0) Then
$bSuccess = $oBundle.EmailAt(0,$oEmail)
; Re-read the flags from the server, in case another client changed them since the fetch.
$bSuccess = $oImap.RefetchMailFlags($oEmail)
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf
Local $iSeen = $oImap.GetMailFlag($oEmail,"Seen")
ConsoleWrite("Current Seen state: " & $iSeen & @CRLF)
EndIf
$bSuccess = $oImap.Disconnect()
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf