Xbase++
Xbase++
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 Xbase++ Downloads
LOCAL nSuccess
LOCAL oImap
nSuccess := 0
// Demonstrates the Imap.ExpungeAndClose method, which permanently removes all messages
// marked with \Deleted from the selected mailbox and then closes the mailbox.
oImap := CreateObject("Chilkat.Imap")
oImap:Ssl := 1
oImap:Port := 993
nSuccess := oImap:Connect("imap.example.com")
IF (nSuccess == 0)
? oImap:LastErrorText
oImap:destroy()
RETURN
ENDIF
nSuccess := oImap:Login("user@example.com", "myPassword")
IF (nSuccess == 0)
? oImap:LastErrorText
oImap:destroy()
RETURN
ENDIF
nSuccess := oImap:SelectMailbox("Inbox")
IF (nSuccess == 0)
? oImap:LastErrorText
oImap:destroy()
RETURN
ENDIF
// Mark message (sequence number 1) with the \Deleted flag.
nSuccess := oImap:SetFlag(1, 0, "\Deleted", 1)
IF (nSuccess == 0)
? oImap:LastErrorText
oImap:destroy()
RETURN
ENDIF
// Remove the \Deleted messages and close the mailbox in one step.
nSuccess := oImap:ExpungeAndClose()
IF (nSuccess == 0)
? oImap:LastErrorText
oImap:destroy()
RETURN
ENDIF
? "Expunged and closed the mailbox."
nSuccess := oImap:Disconnect()
IF (nSuccess == 0)
? oImap:LastErrorText
oImap:destroy()
RETURN
ENDIF
oImap:destroy()