Sample code for 30+ languages & platforms
Xojo Plugin

Close the Selected IMAP Mailbox

See more IMAP Examples

Demonstrates the Chilkat Imap.CloseMailbox method, which closes the currently selected mailbox while keeping the authenticated IMAP connection open. This example selects the Inbox and then closes it. (The mailbox-name argument is retained for backward compatibility but is ignored.)

Background: IMAP's CLOSE command returns the session to the "authenticated but no mailbox selected" state without logging out — so you can move on to another mailbox on the same connection. As a side effect, CLOSE also silently expunges \Deleted messages. When you want to switch mailboxes but not expunge, simply select the next mailbox instead of closing.

Chilkat Xojo Plugin Downloads

Xojo Plugin
Dim success As Boolean
success = False

//  Demonstrates the Imap.CloseMailbox method, which closes the currently selected mailbox
//  while keeping the authenticated IMAP connection open.

Dim imap As New Chilkat.Imap

imap.Ssl = True
imap.Port = 993

success = imap.Connect("imap.example.com")
If (success = False) Then
    System.DebugLog(imap.LastErrorText)
    Return
End If

success = imap.Login("user@example.com","myPassword")
If (success = False) Then
    System.DebugLog(imap.LastErrorText)
    Return
End If

//  Select a mailbox and work with its messages.
success = imap.SelectMailbox("Inbox")
If (success = False) Then
    System.DebugLog(imap.LastErrorText)
    Return
End If

//  Close the selected mailbox (the connection stays open and authenticated).
success = imap.CloseMailbox("Inbox")
If (success = False) Then
    System.DebugLog(imap.LastErrorText)
    Return
End If

System.DebugLog("Mailbox closed; still connected.")

success = imap.Disconnect()
If (success = False) Then
    System.DebugLog(imap.LastErrorText)
    Return
End If