Visual FoxPro
Visual FoxPro
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 Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loImap
LOCAL loMsgSet
LOCAL loBundle
LOCAL loEmail
LOCAL lnSeen
lnSuccess = 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.
loImap = CreateObject('Chilkat.Imap')
loImap.Ssl = 1
loImap.Port = 993
lnSuccess = loImap.Connect("imap.example.com")
IF (lnSuccess = 0) THEN
? loImap.LastErrorText
RELEASE loImap
CANCEL
ENDIF
lnSuccess = loImap.Login("user@example.com","myPassword")
IF (lnSuccess = 0) THEN
? loImap.LastErrorText
RELEASE loImap
CANCEL
ENDIF
lnSuccess = loImap.SelectMailbox("Inbox")
IF (lnSuccess = 0) THEN
? loImap.LastErrorText
RELEASE loImap
CANCEL
ENDIF
loMsgSet = CreateObject('Chilkat.MessageSet')
lnSuccess = loImap.QueryMbx("ALL",1,loMsgSet)
IF (lnSuccess = 0) THEN
? loImap.LastErrorText
RELEASE loImap
RELEASE loMsgSet
CANCEL
ENDIF
loBundle = CreateObject('Chilkat.EmailBundle')
lnSuccess = loImap.FetchMsgSet(1,loMsgSet,loBundle)
IF (lnSuccess = 0) THEN
? loImap.LastErrorText
RELEASE loImap
RELEASE loMsgSet
RELEASE loBundle
CANCEL
ENDIF
loEmail = CreateObject('Chilkat.Email')
IF (loBundle.MessageCount > 0) THEN
lnSuccess = loBundle.EmailAt(0,loEmail)
* Re-read the flags from the server, in case another client changed them since the fetch.
lnSuccess = loImap.RefetchMailFlags(loEmail)
IF (lnSuccess = 0) THEN
? loImap.LastErrorText
RELEASE loImap
RELEASE loMsgSet
RELEASE loBundle
RELEASE loEmail
CANCEL
ENDIF
lnSeen = loImap.GetMailFlag(loEmail,"Seen")
? "Current Seen state: " + STR(lnSeen)
ENDIF
lnSuccess = loImap.Disconnect()
IF (lnSuccess = 0) THEN
? loImap.LastErrorText
RELEASE loImap
RELEASE loMsgSet
RELEASE loBundle
RELEASE loEmail
CANCEL
ENDIF
RELEASE loImap
RELEASE loMsgSet
RELEASE loBundle
RELEASE loEmail