Lianja
Lianja
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 Lianja Downloads
llSuccess = .F.
// Demonstrates the Imap.ExpungeAndClose method, which permanently removes all messages
// marked with \Deleted from the selected mailbox and then closes the mailbox.
loImap = createobject("CkImap")
loImap.Ssl = .T.
loImap.Port = 993
llSuccess = loImap.Connect("imap.example.com")
if (llSuccess = .F.) then
? loImap.LastErrorText
release loImap
return
endif
llSuccess = loImap.Login("user@example.com","myPassword")
if (llSuccess = .F.) then
? loImap.LastErrorText
release loImap
return
endif
llSuccess = loImap.SelectMailbox("Inbox")
if (llSuccess = .F.) then
? loImap.LastErrorText
release loImap
return
endif
// Mark message (sequence number 1) with the \Deleted flag.
llSuccess = loImap.SetFlag(1,.F.,"\Deleted",1)
if (llSuccess = .F.) then
? loImap.LastErrorText
release loImap
return
endif
// Remove the \Deleted messages and close the mailbox in one step.
llSuccess = loImap.ExpungeAndClose()
if (llSuccess = .F.) then
? loImap.LastErrorText
release loImap
return
endif
? "Expunged and closed the mailbox."
llSuccess = loImap.Disconnect()
if (llSuccess = .F.) then
? loImap.LastErrorText
release loImap
return
endif
release loImap