Unicode C++
Unicode C++
Test for an IMAP Server Capability
See more IMAP Examples
Demonstrates the Chilkat Imap.HasCapability method, which tests whether a named capability appears in a raw capability response. The second argument is typically the string returned by the Capability method. This example checks whether the server supports the IDLE extension.
Background: Rather than scanning the raw
CAPABILITY text yourself, HasCapability parses it for a specific token. This is the right guard before using any optional feature — for example, only entering an IDLE wait loop, or using the MOVE command, when the server actually advertises it. Fetch the capability string once and test it as many times as needed.Chilkat Unicode C++ Downloads
#include <CkImapW.h>
void ChilkatSample(void)
{
bool success = false;
// Demonstrates the Imap.HasCapability method, which tests whether a named capability appears
// in a raw capability response. The 2nd argument is typically the string returned by the
// Capability method.
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;
}
// Get the raw capability response.
const wchar_t *capabilities = imap.capability();
if (imap.get_LastMethodSuccess() == false) {
wprintf(L"%s\n",imap.lastErrorText());
return;
}
// Test whether the server supports the IDLE extension.
bool hasIdle = imap.HasCapability(L"IDLE",capabilities);
if (hasIdle == true) {
wprintf(L"The server supports IDLE.\n");
}
else {
wprintf(L"The server does not support IDLE.\n");
}
success = imap.Disconnect();
if (success == false) {
wprintf(L"%s\n",imap.lastErrorText());
return;
}
}