Unicode C++
Unicode C++
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 Unicode C++ Downloads
#include <CkImapW.h>
void ChilkatSample(void)
{
bool success = false;
// Demonstrates the Imap.CloseMailbox method, which closes the currently selected mailbox
// while keeping the authenticated IMAP connection open.
CkImapW imap;
imap.put_Ssl(true);
imap.put_Port(993);
success = imap.Connect(L"imap.example.com");
if (success == false) {
wprintf(L"%s\n",imap.lastErrorText());
return;
}
success = imap.Login(L"user@example.com",L"myPassword");
if (success == false) {
wprintf(L"%s\n",imap.lastErrorText());
return;
}
// Select a mailbox and work with its messages.
success = imap.SelectMailbox(L"Inbox");
if (success == false) {
wprintf(L"%s\n",imap.lastErrorText());
return;
}
// Close the selected mailbox (the connection stays open and authenticated).
success = imap.CloseMailbox(L"Inbox");
if (success == false) {
wprintf(L"%s\n",imap.lastErrorText());
return;
}
wprintf(L"Mailbox closed; still connected.\n");
success = imap.Disconnect();
if (success == false) {
wprintf(L"%s\n",imap.lastErrorText());
return;
}
}