Sample code for 30+ languages & platforms
PowerBuilder

Get MessageSet IDs as a Compact String

See more IMAP Examples

Demonstrates the Chilkat MessageSet.ToCompactString method, which returns the unique identifiers in ascending order using compact IMAP message-set syntax, collapsing consecutive runs into inclusive ranges. It takes no arguments. This example loads 1,2,3,4,5,8,9,10 and prints the compact form 1:5,8:10.

Background: The result is canonical for the current set — unique, sorted, and range-compacted — which is the compact notation IMAP servers expect for message-set arguments. It is the inverse of FromCompactString, so the two round-trip: a set emitted here can be reloaded later. The string contains only numbers and omits the HasUids setting, so track UID-vs-sequence separately.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_MsgSet
string ls_Compact

li_Success = 0

//  Demonstrates the MessageSet.ToCompactString method, which returns the unique identifiers in
//  ascending order using compact IMAP message-set syntax, with consecutive runs collapsed into
//  inclusive ranges.  It takes no arguments.

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

//  Load a set of individual identifiers.
li_Success = loo_MsgSet.FromCompactString("1,2,3,4,5,8,9,10")
if li_Success = 0 then
    Write-Debug loo_MsgSet.LastErrorText
    destroy loo_MsgSet
    return
end if

//  Get the canonical compact representation.
ls_Compact = loo_MsgSet.ToCompactString()
Write-Debug ls_Compact
//  Output: 1:5,8:10


destroy loo_MsgSet