Sample code for 30+ languages & platforms
Visual FoxPro

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 Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loImap
LOCAL lnTimeoutMs
LOCAL lcUpdates

lnSuccess = 0

*  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('Chilkat.Imap')

loImap.Ssl = 1
loImap.Port = 993

lnSuccess = loImap.Connect("imap.example.com")
IF (lnSuccess = 0) THEN
    ? loImap.LastErrorText
    RELEASE loImap
    CANCEL
ENDIF

lnSuccess = loImap.Login("user@example.com","myPassword")
IF (lnSuccess = 0) THEN
    ? loImap.LastErrorText
    RELEASE loImap
    CANCEL
ENDIF

lnSuccess = loImap.SelectMailbox("Inbox")
IF (lnSuccess = 0) THEN
    ? loImap.LastErrorText
    RELEASE loImap
    CANCEL
ENDIF

lnSuccess = loImap.IdleStart()
IF (lnSuccess = 0) THEN
    ? loImap.LastErrorText
    RELEASE loImap
    CANCEL
ENDIF

*  Check once for any updates that arrived.
lnTimeoutMs = 5000
lcUpdates = loImap.IdleCheck(lnTimeoutMs)
IF (loImap.LastMethodSuccess = 0) THEN
    ? loImap.LastErrorText
    RELEASE loImap
    CANCEL
ENDIF

? lcUpdates

*  End IDLE so that ordinary IMAP commands can be sent again on the same connection.
lnSuccess = loImap.IdleDone()
IF (lnSuccess = 0) THEN
    ? loImap.LastErrorText
    RELEASE loImap
    CANCEL
ENDIF

? "IDLE mode ended."

lnSuccess = loImap.Disconnect()
IF (lnSuccess = 0) THEN
    ? loImap.LastErrorText
    RELEASE loImap
    CANCEL
ENDIF

RELEASE loImap