Xbase++
Xbase++
Check for IMAP IDLE Mailbox Updates
See more IMAP Examples
Demonstrates the Chilkat Imap.IdleCheck method, which waits for mailbox updates after IdleStart has entered IDLE mode. The only argument is a timeout in milliseconds; 0 performs a non-blocking poll of notifications already received. This example waits up to 30 seconds.
Background:
IdleCheck consumes the notifications already waiting on the connection rather than sending a new polling command. A typical monitoring loop repeatedly calls IdleCheck with a timeout and reacts when updates arrive. Because servers usually drop an idle connection after about 29 minutes, long-lived monitors periodically call IdleDone and then IdleStart again to refresh it.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oImap
LOCAL nTimeoutMs
LOCAL cUpdates
nSuccess := 0
// Demonstrates the Imap.IdleCheck method, which waits for IMAP IDLE mailbox updates and returns
// them. The only argument is a timeout in milliseconds. Use 0 for a non-blocking poll.
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
nSuccess := oImap:SelectMailbox("Inbox")
IF (nSuccess == 0)
? oImap:LastErrorText
oImap:destroy()
RETURN
ENDIF
nSuccess := oImap:IdleStart()
IF (nSuccess == 0)
? oImap:LastErrorText
oImap:destroy()
RETURN
ENDIF
// Wait up to 30 seconds for mailbox updates. IdleCheck returns a string, so assign it to a
// string variable and check for success.
nTimeoutMs := 30000
cUpdates := oImap:IdleCheck(nTimeoutMs)
IF (oImap:LastMethodSuccess == 0)
? oImap:LastErrorText
oImap:destroy()
RETURN
ENDIF
? cUpdates
nSuccess := oImap:IdleDone()
IF (nSuccess == 0)
? oImap:LastErrorText
oImap:destroy()
RETURN
ENDIF
nSuccess := oImap:Disconnect()
IF (nSuccess == 0)
? oImap:LastErrorText
oImap:destroy()
RETURN
ENDIF
oImap:destroy()