Sample code for 30+ languages & platforms
Xbase++

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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oImap

nSuccess := 0

//  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).

oImap := CreateObject("Chilkat.Imap")

oImap:Ssl := 1
oImap:Port := 993

nSuccess := oImap:Connect("imap.example.com")
IF (nSuccess == 0)
    ? oImap:LastErrorText
    oImap:destroy()
    RETURN
ENDIF

nSuccess := oImap:Login("user@example.com", "myPassword")
IF (nSuccess == 0)
    ? oImap:LastErrorText
    oImap:destroy()
    RETURN
ENDIF

//  Open the Inbox as read-only.
nSuccess := oImap:ExamineMailbox("Inbox")
IF (nSuccess == 0)
    ? oImap:LastErrorText
    oImap:destroy()
    RETURN
ENDIF

? "Inbox opened read-only."

nSuccess := oImap:Disconnect()
IF (nSuccess == 0)
    ? oImap:LastErrorText
    oImap:destroy()
    RETURN
ENDIF

oImap:destroy()