Sample code for 30+ languages & platforms
C

Get an IMAP Mailbox Quota

See more IMAP Examples

Demonstrates the Chilkat Imap.GetQuota method, which sends the IMAP GETQUOTA command for a quota root and returns the server response as JSON. The server must advertise the IMAP QUOTA extension. This example queries the default quota root.

Tip: JSON parsing code for this result can be generated at Chilkat Tools.

Background: Mail servers often cap how much storage an account may use. The IMAP QUOTA extension reports the current usage and limit for a quota root — a scope that may cover one mailbox or a whole account. Reading it lets an application warn a user who is nearing their limit, or refuse to append large messages that would exceed it. Check HasCapability for QUOTA first, since not all servers support it.

Chilkat C Downloads

C
#include <C_CkImap.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkImap imap;
    const char *quotaJson;

    success = FALSE;

    //  Demonstrates the Imap.GetQuota method, which sends the IMAP GETQUOTA command for a quota
    //  root and returns the server response as JSON.  The server must advertise the IMAP QUOTA
    //  extension.

    imap = CkImap_Create();

    CkImap_putSsl(imap,TRUE);
    CkImap_putPort(imap,993);

    success = CkImap_Connect(imap,"imap.example.com");
    if (success == FALSE) {
        printf("%s\n",CkImap_lastErrorText(imap));
        CkImap_Dispose(imap);
        return;
    }

    success = CkImap_Login(imap,"user@example.com","myPassword");
    if (success == FALSE) {
        printf("%s\n",CkImap_lastErrorText(imap));
        CkImap_Dispose(imap);
        return;
    }

    //  Get the quota for a quota root (an empty string queries the default quota root).
    quotaJson = CkImap_getQuota(imap,"");
    if (CkImap_getLastMethodSuccess(imap) == FALSE) {
        printf("%s\n",CkImap_lastErrorText(imap));
        CkImap_Dispose(imap);
        return;
    }

    printf("%s\n",quotaJson);

    //  JSON parsing code for this result can be generated at Chilkat's online tool:
    //  https://tools.chilkat.io/jsonParse

    success = CkImap_Disconnect(imap);
    if (success == FALSE) {
        printf("%s\n",CkImap_lastErrorText(imap));
        CkImap_Dispose(imap);
        return;
    }



    CkImap_Dispose(imap);

    }