Unicode C++
Unicode C++
End IMAP IDLE Mode
See more IMAP Examples
Demonstrates the Chilkat Imap.IdleDone method, which ends IDLE mode by sending the protocol's DONE continuation. It takes no arguments. The authenticated connection remains open and usable afterward.
Background: While IDLE is active the connection is dedicated to receiving push notifications, so any command that needs to talk to the server — fetching a message, setting a flag — must wait until IDLE ends.
IdleDone cleanly exits IDLE without dropping the login, so the same connection can immediately be reused. Calling it when IDLE is not active fails.Chilkat Unicode C++ Downloads
#include <CkImapW.h>
void ChilkatSample(void)
{
bool success = false;
// Demonstrates the Imap.IdleDone method, which ends IMAP IDLE mode by sending the DONE
// continuation. It takes no arguments. The authenticated connection remains open and usable.
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;
}
success = imap.SelectMailbox(L"Inbox");
if (success == false) {
wprintf(L"%s\n",imap.lastErrorText());
return;
}
success = imap.IdleStart();
if (success == false) {
wprintf(L"%s\n",imap.lastErrorText());
return;
}
// Check once for any updates that arrived.
int timeoutMs = 5000;
const wchar_t *updates = imap.idleCheck(timeoutMs);
if (imap.get_LastMethodSuccess() == false) {
wprintf(L"%s\n",imap.lastErrorText());
return;
}
wprintf(L"%s\n",updates);
// End IDLE so that ordinary IMAP commands can be sent again on the same connection.
success = imap.IdleDone();
if (success == false) {
wprintf(L"%s\n",imap.lastErrorText());
return;
}
wprintf(L"IDLE mode ended.\n");
success = imap.Disconnect();
if (success == false) {
wprintf(L"%s\n",imap.lastErrorText());
return;
}
}