AutoIt
AutoIt
Expunge Deleted Messages and Close the Mailbox
See more IMAP Examples
Demonstrates the Chilkat Imap.ExpungeAndClose method, which permanently removes all messages marked with \Deleted from the selected mailbox and then closes the mailbox. This example marks a message deleted and then expunges-and-closes.
Background: This combines two actions into one call: the permanent removal of
\Deleted messages (see Expunge) followed by closing the mailbox (see CloseMailbox), returning the session to the authenticated-but-no-mailbox-selected state while staying connected. It's the natural way to finish working with a mailbox after cleaning it up, before selecting another or logging out.Chilkat AutoIt Downloads
Local $bSuccess = False
; Demonstrates the Imap.ExpungeAndClose method, which permanently removes all messages
; marked with \Deleted from the selected mailbox and then closes the mailbox.
$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
; Mark message (sequence number 1) with the \Deleted flag.
$bSuccess = $oImap.SetFlag(1,False,"\Deleted",1)
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf
; Remove the \Deleted messages and close the mailbox in one step.
$bSuccess = $oImap.ExpungeAndClose()
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf
ConsoleWrite("Expunged and closed the mailbox." & @CRLF)
$bSuccess = $oImap.Disconnect()
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf