PureBasic
PureBasic
Subtract One MessageSet from Another
See more IMAP Examples
Demonstrates the Chilkat MessageSet.Subtract method, which removes from this set every identifier whose numeric value is also present in another MessageSet. The only argument is the other set. This example starts with ids 1:10, subtracts 2,4,6, and prints what remains.
Background: A common IMAP pattern is "process everything except what I've already handled."
Subtract makes that a single call: remove the already-processed ids from a working set. The comparison is numeric only and this object's HasUids is preserved, so for meaningful results both sets should hold the same id type from the same mailbox. Passing the same object clears the set; passing an empty set changes nothing.Chilkat PureBasic Downloads
IncludeFile "CkMessageSet.pb"
Procedure ChilkatExample()
success.i = 0
; Demonstrates the MessageSet.Subtract method, which removes from this set every identifier
; that is also present in another MessageSet. The only argument is the other MessageSet.
msgSet.i = CkMessageSet::ckCreate()
If msgSet.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
; Start with messages 1 through 10.
success = CkMessageSet::ckFromCompactString(msgSet,"1:10")
If success = 0
Debug CkMessageSet::ckLastErrorText(msgSet)
CkMessageSet::ckDispose(msgSet)
ProcedureReturn
EndIf
; The identifiers that have already been processed and should be excluded.
processed.i = CkMessageSet::ckCreate()
If processed.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkMessageSet::ckFromCompactString(processed,"2,4,6")
If success = 0
Debug CkMessageSet::ckLastErrorText(processed)
CkMessageSet::ckDispose(msgSet)
CkMessageSet::ckDispose(processed)
ProcedureReturn
EndIf
; Remove the already-processed identifiers from msgSet.
CkMessageSet::ckSubtract(msgSet,processed)
; Show what remains.
remaining.s = CkMessageSet::ckToCompactString(msgSet)
Debug remaining
; Output: 1,3,5,7:10
CkMessageSet::ckDispose(msgSet)
CkMessageSet::ckDispose(processed)
ProcedureReturn
EndProcedure