Xbase++
Xbase++
Refresh an Email Object's IMAP Flags
See more IMAP Examples
Demonstrates the Chilkat Imap.RefetchMailFlags method, which updates the flags stored on an Email object to the current values on the server. The only argument is the Email object. This example re-reads the flags for a previously fetched message and then checks its Seen state.
Background: Flags are shared mailbox state, so between the time you fetch a message and the time you act on it, another client (a phone, a webmail tab) may have marked it read, flagged, or deleted.
RefetchMailFlags pulls just the flags — not the whole message — so a long-running job can cheaply re-check the live state before deciding what to do, avoiding acting on stale information.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oImap
LOCAL oMsgSet
LOCAL oBundle
LOCAL oEmail
LOCAL nSeen
nSuccess := 0
// Demonstrates the Imap.RefetchMailFlags method, which updates the flags stored on an Email
// object to the current values on the server. The only argument is the Email object.
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
oMsgSet := CreateObject("Chilkat.MessageSet")
nSuccess := oImap:QueryMbx("ALL", 1, oMsgSet)
IF (nSuccess == 0)
? oImap:LastErrorText
oImap:destroy()
oMsgSet:destroy()
RETURN
ENDIF
oBundle := CreateObject("Chilkat.EmailBundle")
nSuccess := oImap:FetchMsgSet(1, oMsgSet, oBundle)
IF (nSuccess == 0)
? oImap:LastErrorText
oImap:destroy()
oMsgSet:destroy()
oBundle:destroy()
RETURN
ENDIF
oEmail := CreateObject("Chilkat.Email")
IF (oBundle:MessageCount > 0)
nSuccess := oBundle:EmailAt(0, oEmail)
// Re-read the flags from the server, in case another client changed them since the fetch.
nSuccess := oImap:RefetchMailFlags(oEmail)
IF (nSuccess == 0)
? oImap:LastErrorText
oImap:destroy()
oMsgSet:destroy()
oBundle:destroy()
oEmail:destroy()
RETURN
ENDIF
nSeen := oImap:GetMailFlag(oEmail, "Seen")
? "Current Seen state: " + Str(nSeen)
ENDIF
nSuccess := oImap:Disconnect()
IF (nSuccess == 0)
? oImap:LastErrorText
oImap:destroy()
oMsgSet:destroy()
oBundle:destroy()
oEmail:destroy()
RETURN
ENDIF
oImap:destroy()
oMsgSet:destroy()
oBundle:destroy()
oEmail:destroy()