Visual FoxPro
Visual FoxPro
Store One or More Flags on a Single Message
See more IMAP Examples
Demonstrates the Chilkat Imap.StoreFlags method, which sets or clears one or more flags on a single message identified by ID. The first argument is the message ID, the second (bUid) selects UID vs sequence number, the third is a space-separated list of flag names, and the fourth is the value (1 to set, 0 to clear). This example applies the Seen and Flagged flags to one message by UID.
Background:
StoreFlags is the single-message counterpart to SetFlags and lets you change several flags at once by listing them space-separated (without leading backslashes). Because the ID can be either a UID or a sequence number, the bUid argument must match how you obtained it — a UID from a UID search, or a sequence number from a sequence-based operation. UIDs are the safer choice since they remain valid as the mailbox changes.Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loImap
LOCAL loMsgSet
LOCAL lnUid
lnSuccess = 0
* Demonstrates the Imap.StoreFlags method, which sets or clears one or more flags on a single
* message identified by ID. The 1st argument is the message ID, the 2nd (bUid) selects UID
* vs sequence number, the 3rd is a space-separated list of flag names, and the 4th is the
* value (1 to set, 0 to clear).
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
* Get the UIDs of all messages.
loMsgSet = CreateObject('Chilkat.MessageSet')
lnSuccess = loImap.QueryMbx("ALL",1,loMsgSet)
IF (lnSuccess = 0) THEN
? loImap.LastErrorText
RELEASE loImap
RELEASE loMsgSet
CANCEL
ENDIF
IF (loMsgSet.Count > 0) THEN
* Apply the Seen and Flagged flags to the first message. bUid is 1 because the ID
* came from a UID search.
lnUid = loMsgSet.GetId(0)
lnSuccess = loImap.StoreFlags(lnUid,1,"Seen Flagged",1)
IF (lnSuccess = 0) THEN
? loImap.LastErrorText
RELEASE loImap
RELEASE loMsgSet
CANCEL
ENDIF
? "Updated flags on UID " + STR(lnUid)
ENDIF
lnSuccess = loImap.Disconnect()
IF (lnSuccess = 0) THEN
? loImap.LastErrorText
RELEASE loImap
RELEASE loMsgSet
CANCEL
ENDIF
RELEASE loImap
RELEASE loMsgSet