Sample code for 30+ languages & platforms
Lianja

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

Lianja
llSuccess = .F.

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

loImap = createobject("CkImap")

loImap.Ssl = .T.
loImap.Port = 993

llSuccess = loImap.Connect("imap.example.com")
if (llSuccess = .F.) then
    ? loImap.LastErrorText
    release loImap
    return
endif

llSuccess = loImap.Login("user@example.com","myPassword")
if (llSuccess = .F.) then
    ? loImap.LastErrorText
    release loImap
    return
endif

llSuccess = loImap.SelectMailbox("Inbox")
if (llSuccess = .F.) then
    ? loImap.LastErrorText
    release loImap
    return
endif

llSuccess = loImap.IdleStart()
if (llSuccess = .F.) then
    ? loImap.LastErrorText
    release loImap
    return
endif

//  Check once for any updates that arrived.
lnTimeoutMs = 5000
lcUpdates = loImap.IdleCheck(lnTimeoutMs)
if (loImap.LastMethodSuccess = .F.) then
    ? loImap.LastErrorText
    release loImap
    return
endif

? lcUpdates

//  End IDLE so that ordinary IMAP commands can be sent again on the same connection.
llSuccess = loImap.IdleDone()
if (llSuccess = .F.) then
    ? loImap.LastErrorText
    release loImap
    return
endif

? "IDLE mode ended."

llSuccess = loImap.Disconnect()
if (llSuccess = .F.) then
    ? loImap.LastErrorText
    release loImap
    return
endif



release loImap