PureBasic
PureBasic
Set or Clear a Flag on a MessageSet
See more IMAP Examples
Demonstrates the Chilkat Imap.SetFlags method, which sets or clears a flag on every message in a MessageSet. The first argument is the MessageSet, the second is the flag name, and the third is the value (1 to set the flag, 0 to clear it). This example marks all unseen messages as Seen.
Background: IMAP flags are per-message keywords the server stores and shares across all clients. The standard system flags are
Seen, Answered, Flagged, Deleted, Draft, and Recent. Give the flag name without the leading backslash here (use "Seen", not "\Seen"). SetFlags applies the change to the whole set in one round trip, which is how a client implements "mark all as read."Chilkat PureBasic Downloads
IncludeFile "CkImap.pb"
IncludeFile "CkMessageSet.pb"
Procedure ChilkatExample()
success.i = 0
; Demonstrates the Imap.SetFlags method, which sets or clears a flag on every message in a
; MessageSet. The 1st argument is the MessageSet, the 2nd is the flag name, and the 3rd is
; the value (1 to set the flag, 0 to clear it).
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
success = CkImap::ckSelectMailbox(imap,"Inbox")
If success = 0
Debug CkImap::ckLastErrorText(imap)
CkImap::ckDispose(imap)
ProcedureReturn
EndIf
; Find the messages to flag (here, all unseen messages, by UID).
msgSet.i = CkMessageSet::ckCreate()
If msgSet.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkImap::ckQueryMbx(imap,"UNSEEN",1,msgSet)
If success = 0
Debug CkImap::ckLastErrorText(imap)
CkImap::ckDispose(imap)
CkMessageSet::ckDispose(msgSet)
ProcedureReturn
EndIf
; Mark all of them as seen. A value of 1 sets the flag; 0 would clear it.
success = CkImap::ckSetFlags(imap,msgSet,"Seen",1)
If success = 0
Debug CkImap::ckLastErrorText(imap)
CkImap::ckDispose(imap)
CkMessageSet::ckDispose(msgSet)
ProcedureReturn
EndIf
Debug "Marked " + Str(CkMessageSet::ckCount(msgSet)) + " messages as Seen."
success = CkImap::ckDisconnect(imap)
If success = 0
Debug CkImap::ckLastErrorText(imap)
CkImap::ckDispose(imap)
CkMessageSet::ckDispose(msgSet)
ProcedureReturn
EndIf
CkImap::ckDispose(imap)
CkMessageSet::ckDispose(msgSet)
ProcedureReturn
EndProcedure