AutoIt
AutoIt
Expunge Deleted Messages from a Mailbox
See more IMAP Examples
Demonstrates the Chilkat Imap.Expunge method, which permanently removes all messages marked with the \Deleted flag from the currently selected mailbox. The mailbox remains selected. This example marks a message deleted with SetFlag and then expunges.
Background: IMAP deletion is two-phase, much like POP3. First a message is marked with the
\Deleted flag (it still exists, just tagged); then EXPUNGE permanently removes every flagged message and renumbers the rest. Splitting the two steps lets a client mark several messages and remove them together, or unmark (undelete) before committing. Expunge keeps the mailbox selected; ExpungeAndClose does the same and then closes it.Chilkat AutoIt Downloads
Local $bSuccess = False
; Demonstrates the Imap.Expunge method, which permanently removes all messages marked with
; the \Deleted flag from the currently selected mailbox. The mailbox remains selected.
$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
; Select the mailbox to operate on.
$bSuccess = $oImap.SelectMailbox("Inbox")
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf
; Mark message (sequence number 1) with the \Deleted flag. The 4th argument (1) sets the
; flag; the 2nd argument (False) means the id is a sequence number, not a UID.
$bSuccess = $oImap.SetFlag(1,False,"\Deleted",1)
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf
; Permanently remove all \Deleted messages from the selected mailbox.
$bSuccess = $oImap.Expunge()
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf
ConsoleWrite("Expunged the deleted messages." & @CRLF)
$bSuccess = $oImap.Disconnect()
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf