Sample code for 30+ languages & platforms
PowerBuilder

Get IMAP Mailbox Status

See more IMAP Examples

Demonstrates the Chilkat Imap.GetMailboxStatus method, which sends the IMAP STATUS command for a mailbox and returns the reported values as XML attributes — including messages (total count), recent, uidnext, uidvalidity, and unseen. This example gets the Inbox status.

Tip: XML parsing code for this result can be generated at Chilkat Tools.

Background: STATUS queries a mailbox's summary counts without selecting it — ideal for showing unread counts across many folders in a UI, or checking whether a folder has new mail before deciding to open it. Two values are especially useful for sync: uidvalidity (if it changes, previously stored UIDs are no longer valid) and uidnext (the UID the next new message will get, so anything at or above a remembered value is new).

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Imap
string ls_StatusXml

li_Success = 0

//  Demonstrates the Imap.GetMailboxStatus method, which sends the IMAP STATUS command for a
//  mailbox and returns the reported values as XML attributes (such as messages, recent,
//  uidnext, uidvalidity, and unseen).

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

//  Get the status of a mailbox (without selecting it).
ls_StatusXml = loo_Imap.GetMailboxStatus("Inbox")
if loo_Imap.LastMethodSuccess = 0 then
    Write-Debug loo_Imap.LastErrorText
    destroy loo_Imap
    return
end if

Write-Debug ls_StatusXml

//  XML parsing code for this result can be generated at Chilkat's online tool:
//  https://tools.chilkat.io/xmlParse

li_Success = loo_Imap.Disconnect()
if li_Success = 0 then
    Write-Debug loo_Imap.LastErrorText
    destroy loo_Imap
    return
end if



destroy loo_Imap