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