Sample code for 30+ languages & platforms
C

Open an IMAP Mailbox Read-Only

See more IMAP Examples

Demonstrates the Chilkat Imap.ExamineMailbox method, which opens a mailbox as read-only. Use it instead of SelectMailbox when the application must not change message state, such as the \Seen flag. This example examines the Inbox.

Background: Reading a message can have a side effect: fetching its body normally sets the \Seen flag, marking it as read. ExamineMailbox corresponds to IMAP's EXAMINE command, which opens the mailbox in a read-only mode where no such changes are made — ideal for scanning, indexing, or backup tools that must leave the user's mailbox exactly as they left it.

Chilkat C Downloads

C
#include <C_CkImap.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkImap imap;

    success = FALSE;

    //  Demonstrates the Imap.ExamineMailbox method, which opens a mailbox as read-only.  Use this
    //  instead of SelectMailbox when the application must not change message state (such as the
    //  \Seen flag).

    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;
    }

    //  Open the Inbox as read-only.
    success = CkImap_ExamineMailbox(imap,"Inbox");
    if (success == FALSE) {
        printf("%s\n",CkImap_lastErrorText(imap));
        CkImap_Dispose(imap);
        return;
    }

    printf("Inbox opened read-only.\n");

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



    CkImap_Dispose(imap);

    }