PowerBuilder
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Imap
integer li_TimeoutMs
string ls_Updates
li_Success = 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.
loo_Imap = create oleobject
li_rc = loo_Imap.ConnectToNewObject("Chilkat.Imap")
if li_rc < 0 then
destroy loo_Imap
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_Imap.Ssl = 1
loo_Imap.Port = 993
li_Success = loo_Imap.Connect("imap.example.com")
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
return
end if
li_Success = loo_Imap.Login("user@example.com","myPassword")
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
return
end if
li_Success = loo_Imap.SelectMailbox("Inbox")
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
return
end if
li_Success = loo_Imap.IdleStart()
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
return
end if
// Wait up to 30 seconds for mailbox updates. IdleCheck returns a string, so assign it to a
// string variable and check for success.
li_TimeoutMs = 30000
ls_Updates = loo_Imap.IdleCheck(li_TimeoutMs)
if loo_Imap.LastMethodSuccess = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
return
end if
Write-Debug ls_Updates
li_Success = loo_Imap.IdleDone()
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
return
end if
li_Success = loo_Imap.Disconnect()
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
return
end if
destroy loo_Imap