Sample code for 30+ languages & platforms
PowerBuilder

Check the Last Known IMAP Connection State

See more IMAP Examples

Demonstrates the Chilkat Imap.IsConnected method, which returns the last known connection state without sending any data to the IMAP server. A true result does not prove that an idle connection is still usable. This example connects and reads the state.

Background: IsConnected is a cheap, cached check — it reports what Chilkat last observed without touching the network. That makes it fast, but it can be stale: a server or firewall may have silently dropped an idle connection. When you need to be sure the connection is actually alive, send a lightweight round trip such as Noop, or use CheckConnection for a low-level socket probe.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Imap
integer li_Connected

li_Success = 0

//  Demonstrates the Imap.IsConnected method, which returns the last known connection state
//  without sending data to the IMAP server.  A true result does not prove that an idle
//  connection is still usable.

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

//  Check the last known connection state (no data is sent to the server).
li_Connected = loo_Imap.IsConnected()
if li_Connected = 1 then
    Write-Debug "The IMAP object believes it is connected."
else
    Write-Debug "The IMAP object is not connected."
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