Sample code for 30+ languages & platforms
Lua

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 Lua Downloads

Lua
local chilkat = require("chilkat")

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

local imap = chilkat.Imap.new()

imap.ssl = true
imap.port = 993

local success = imap:connect("imap.example.com")
if not success then
    print(imap.last_error_text)
    return
end

success = imap:login("user@example.com", "myPassword")
if not success then
    print(imap.last_error_text)
    return
end

-- Open the Inbox as read-only.
success = imap:examine_mailbox("Inbox")
if not success then
    print(imap.last_error_text)
    return
end

print("Inbox opened read-only.")

success = imap:disconnect()
if not success then
    print(imap.last_error_text)
    return
end