Sample code for 30+ languages & platforms
PowerBuilder

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 PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_MsgSet
oleobject loo_Processed
string ls_Remaining

li_Success = 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.

loo_MsgSet = create oleobject
li_rc = loo_MsgSet.ConnectToNewObject("Chilkat.MessageSet")
if li_rc < 0 then
    destroy loo_MsgSet
    MessageBox("Error","Connecting to COM object failed")
    return
end if

//  Start with messages 1 through 10.
li_Success = loo_MsgSet.FromCompactString("1:10")
if li_Success = 0 then
    Write-Debug loo_MsgSet.LastErrorText
    destroy loo_MsgSet
    return
end if

//  The identifiers that have already been processed and should be excluded.
loo_Processed = create oleobject
li_rc = loo_Processed.ConnectToNewObject("Chilkat.MessageSet")

li_Success = loo_Processed.FromCompactString("2,4,6")
if li_Success = 0 then
    Write-Debug loo_Processed.LastErrorText
    destroy loo_MsgSet
    destroy loo_Processed
    return
end if

//  Remove the already-processed identifiers from msgSet.
loo_MsgSet.Subtract(loo_Processed)

//  Show what remains.
ls_Remaining = loo_MsgSet.ToCompactString()
Write-Debug ls_Remaining
//  Output: 1,3,5,7:10


destroy loo_MsgSet
destroy loo_Processed