DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoImap
Variant vMsgSet
Handle hoMsgSet
String sTemp1
Integer iTemp1
Move False To iSuccess
// 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).
Get Create (RefClass(cComChilkatImap)) To hoImap
If (Not(IsComObjectCreated(hoImap))) Begin
Send CreateComObject of hoImap
End
Set ComSsl Of hoImap To True
Set ComPort Of hoImap To 993
Get ComConnect Of hoImap "imap.example.com" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoImap To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComLogin Of hoImap "user@example.com" "myPassword" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoImap To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComSelectMailbox Of hoImap "Inbox" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoImap To sTemp1
Showln sTemp1
Procedure_Return
End
// Find the messages to flag (here, all unseen messages, by UID).
Get Create (RefClass(cComChilkatMessageSet)) To hoMsgSet
If (Not(IsComObjectCreated(hoMsgSet))) Begin
Send CreateComObject of hoMsgSet
End
Get pvComObject of hoMsgSet to vMsgSet
Get ComQueryMbx Of hoImap "UNSEEN" True vMsgSet To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoImap To sTemp1
Showln sTemp1
Procedure_Return
End
// Mark all of them as seen. A value of 1 sets the flag; 0 would clear it.
Get pvComObject of hoMsgSet to vMsgSet
Get ComSetFlags Of hoImap vMsgSet "Seen" 1 To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoImap To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComCount Of hoMsgSet To iTemp1
Showln "Marked " iTemp1 " messages as Seen."
Get ComDisconnect Of hoImap To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoImap To sTemp1
Showln sTemp1
Procedure_Return
End
End_Procedure