Sample code for 30+ languages & platforms
Lua

End IMAP IDLE Mode

See more IMAP Examples

Demonstrates the Chilkat Imap.IdleDone method, which ends IDLE mode by sending the protocol's DONE continuation. It takes no arguments. The authenticated connection remains open and usable afterward.

Background: While IDLE is active the connection is dedicated to receiving push notifications, so any command that needs to talk to the server — fetching a message, setting a flag — must wait until IDLE ends. IdleDone cleanly exits IDLE without dropping the login, so the same connection can immediately be reused. Calling it when IDLE is not active fails.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

-- Demonstrates the Imap.IdleDone method, which ends IMAP IDLE mode by sending the DONE
-- continuation.  It takes no arguments.  The authenticated connection remains open and usable.

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

success = imap:select_mailbox("Inbox")
if not success then
    print(imap.last_error_text)
    return
end

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

-- Check once for any updates that arrived.
local timeoutMs = 5000
local updates = imap:idle_check(timeoutMs)
if not imap.last_method_success then
    print(imap.last_error_text)
    return
end

print(updates)

-- End IDLE so that ordinary IMAP commands can be sent again on the same connection.
success = imap:idle_done()
if not success then
    print(imap.last_error_text)
    return
end

print("IDLE mode ended.")

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