Sample code for 30+ languages & platforms
PowerBuilder

Delete a Bundle of POP3 Messages

See more POP3 Examples

Demonstrates the Chilkat MailMan.DeleteBundle method, which deletes POP3 messages using the UIDLs stored in the X-UIDL headers of the Email objects in an EmailBundle. An email without an X-UIDL header is skipped. This example fetches all messages and deletes them.

Background: DeleteBundle is the batch version of DeleteEmail: it marks every message in a downloaded bundle for deletion in one call. A typical "download and clear the mailbox" workflow is to fetch all messages, process them, then delete the whole bundle. Because a bundle can be filtered or built selectively, you can also delete just the subset you no longer need. The deletions commit when the POP3 session ends.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Mailman
oleobject loo_Bundle

li_Success = 0

//  Demonstrates the MailMan.DeleteBundle method, which deletes POP3 messages using the UIDLs
//  stored in the X-UIDL headers of the Email objects in an EmailBundle.  An email without an
//  X-UIDL header is skipped.

loo_Mailman = create oleobject
li_rc = loo_Mailman.ConnectToNewObject("Chilkat.MailMan")
if li_rc < 0 then
    destroy loo_Mailman
    MessageBox("Error","Connecting to COM object failed")
    return
end if

//  Configure the POP3 server connection.
loo_Mailman.MailHost = "pop.example.com"
loo_Mailman.MailPort = 995
loo_Mailman.PopSsl = 1
loo_Mailman.PopUsername = "user@example.com"
loo_Mailman.PopPassword = "myPassword"

//  Fetch all messages (headers are enough; each carries an X-UIDL header).
loo_Bundle = create oleobject
li_rc = loo_Bundle.ConnectToNewObject("Chilkat.EmailBundle")

li_Success = loo_Mailman.FetchAll(1,1,0,loo_Bundle)
if li_Success = 0 then
    Write-Debug loo_Mailman.LastErrorText
    destroy loo_Mailman
    destroy loo_Bundle
    return
end if

//  Delete every message in the bundle.
li_Success = loo_Mailman.DeleteBundle(loo_Bundle)
if li_Success = 0 then
    Write-Debug loo_Mailman.LastErrorText
    destroy loo_Mailman
    destroy loo_Bundle
    return
end if

//  Unless the ImmediateDelete property is set to 1, the messages are only marked for
//  deletion.  End the POP3 session (which sends the QUIT command) to commit the deletions.
li_Success = loo_Mailman.Pop3EndSession()
if li_Success = 0 then
    Write-Debug loo_Mailman.LastErrorText
    destroy loo_Mailman
    destroy loo_Bundle
    return
end if

Write-Debug "Deleted " + string(loo_Bundle.MessageCount) + " messages from the POP3 server."

//  Note: Explicitly connecting/authenticating is optional.  Chilkat MailMan automatically
//  connects and authenticates -- using the property settings above -- whenever a server
//  operation requires it.  Calling the explicit connect/authenticate methods can still be
//  helpful to determine whether a failure occurs while connecting or while authenticating.


destroy loo_Mailman
destroy loo_Bundle