PureBasic
PureBasic
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 PureBasic Downloads
IncludeFile "CkImap.pb"
Procedure ChilkatExample()
success.i = 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).
imap.i = CkImap::ckCreate()
If imap.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkImap::setCkSsl(imap, 1)
CkImap::setCkPort(imap, 993)
success = CkImap::ckConnect(imap,"imap.example.com")
If success = 0
Debug CkImap::ckLastErrorText(imap)
CkImap::ckDispose(imap)
ProcedureReturn
EndIf
success = CkImap::ckLogin(imap,"user@example.com","myPassword")
If success = 0
Debug CkImap::ckLastErrorText(imap)
CkImap::ckDispose(imap)
ProcedureReturn
EndIf
; Get the status of a mailbox (without selecting it).
statusXml.s = CkImap::ckGetMailboxStatus(imap,"Inbox")
If CkImap::ckLastMethodSuccess(imap) = 0
Debug CkImap::ckLastErrorText(imap)
CkImap::ckDispose(imap)
ProcedureReturn
EndIf
Debug statusXml
; XML parsing code for this result can be generated at Chilkat's online tool:
; https://tools.chilkat.io/xmlParse
success = CkImap::ckDisconnect(imap)
If success = 0
Debug CkImap::ckLastErrorText(imap)
CkImap::ckDispose(imap)
ProcedureReturn
EndIf
CkImap::ckDispose(imap)
ProcedureReturn
EndProcedure