Sample code for 30+ languages & platforms
C++

Get the IMAP Server Capabilities

See more IMAP Examples

Demonstrates the Chilkat Imap.Capability method, which sends the IMAP CAPABILITY command and returns the server's raw capability response. This example connects and prints the capability list. Use HasCapability to test for a specific one.

Background: Not all IMAP servers support the same features. The CAPABILITY response is the server's advertised menu — a space-separated list of extensions such as IDLE (push notifications of new mail), MOVE, UIDPLUS, QUOTA, and the supported AUTH= mechanisms. A well-behaved client checks capabilities before relying on an optional feature, falling back gracefully when it is absent.

Chilkat C++ Downloads

C++
#include <CkImap.h>

void ChilkatSample(void)
    {
    bool success = false;

    //  Demonstrates the Imap.Capability method, which sends the IMAP CAPABILITY command and
    //  returns the server's raw capability response.

    CkImap imap;

    imap.put_Ssl(true);
    imap.put_Port(993);

    success = imap.Connect("imap.example.com");
    if (success == false) {
        std::cout << imap.lastErrorText() << "\r\n";
        return;
    }

    //  Ask the server for its capability list.
    const char *capabilities = imap.capability();
    if (imap.get_LastMethodSuccess() == false) {
        std::cout << imap.lastErrorText() << "\r\n";
        return;
    }

    std::cout << "Server capabilities: " << capabilities << "\r\n";

    success = imap.Disconnect();
    if (success == false) {
        std::cout << imap.lastErrorText() << "\r\n";
        return;
    }
    }