Tcl
Tcl
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 Tcl Downloads
load ./chilkat.dll
set success 0
# Demonstrates the Imap.ExpungeAndClose method, which permanently removes all messages
# marked with \Deleted from the selected mailbox and then closes the mailbox.
set imap [new_CkImap]
CkImap_put_Ssl $imap 1
CkImap_put_Port $imap 993
set success [CkImap_Connect $imap "imap.example.com"]
if {$success == 0} then {
puts [CkImap_lastErrorText $imap]
delete_CkImap $imap
exit
}
set success [CkImap_Login $imap "user@example.com" "myPassword"]
if {$success == 0} then {
puts [CkImap_lastErrorText $imap]
delete_CkImap $imap
exit
}
set success [CkImap_SelectMailbox $imap "Inbox"]
if {$success == 0} then {
puts [CkImap_lastErrorText $imap]
delete_CkImap $imap
exit
}
# Mark message (sequence number 1) with the \Deleted flag.
set success [CkImap_SetFlag $imap 1 0 "\Deleted" 1]
if {$success == 0} then {
puts [CkImap_lastErrorText $imap]
delete_CkImap $imap
exit
}
# Remove the \Deleted messages and close the mailbox in one step.
set success [CkImap_ExpungeAndClose $imap]
if {$success == 0} then {
puts [CkImap_lastErrorText $imap]
delete_CkImap $imap
exit
}
puts "Expunged and closed the mailbox."
set success [CkImap_Disconnect $imap]
if {$success == 0} then {
puts [CkImap_lastErrorText $imap]
delete_CkImap $imap
exit
}
delete_CkImap $imap