PowerBuilder
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Imap
li_Success = 0
// Demonstrates the Imap.Expunge method, which permanently removes all messages marked with
// the \Deleted flag from the currently selected mailbox. The mailbox remains selected.
loo_Imap = create oleobject
li_rc = loo_Imap.ConnectToNewObject("Chilkat.Imap")
if li_rc < 0 then
destroy loo_Imap
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_Imap.Ssl = 1
loo_Imap.Port = 993
li_Success = loo_Imap.Connect("imap.example.com")
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
return
end if
li_Success = loo_Imap.Login("user@example.com","myPassword")
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
return
end if
// Select the mailbox to operate on.
li_Success = loo_Imap.SelectMailbox("Inbox")
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
return
end if
// Mark message (sequence number 1) with the \Deleted flag. The 4th argument (1) sets the
// flag; the 2nd argument (0) means the id is a sequence number, not a UID.
li_Success = loo_Imap.SetFlag(1,0,"\Deleted",1)
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
return
end if
// Permanently remove all \Deleted messages from the selected mailbox.
li_Success = loo_Imap.Expunge()
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
return
end if
Write-Debug "Expunged the deleted messages."
li_Success = loo_Imap.Disconnect()
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
return
end if
destroy loo_Imap