Sample code for 30+ languages & platforms
Pascal (Lazarus/Delphi)

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 Pascal (Lazarus/Delphi) Downloads

Pascal (Lazarus/Delphi)
program ChilkatDemo;

// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}

uses
  {$IFDEF UNIX}
  cthreads,
  {$ENDIF}
  SysUtils,
  CkDllLoader,
  Chilkat.MessageSet;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  success: Boolean;
  msgSet: TMessageSet;
  compact: string;

begin
  success := False;

  //  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.

  msgSet := TMessageSet.Create;

  //  Load a set of individual identifiers.
  success := msgSet.FromCompactString('1,2,3,4,5,8,9,10');
  if (success = False) then
    begin
      WriteLn(msgSet.LastErrorText);
      Exit;
    end;

  //  Get the canonical compact representation.
  compact := msgSet.ToCompactString();
  WriteLn(compact);
  //  Output: 1:5,8:10


  msgSet.Free;

end;

// ---------------------------------------------------------------------------

begin

  try
    RunDemo;
  except
    on E: Exception do
      WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
  end;

  WriteLn;
  {$IFDEF MSWINDOWS}
  WriteLn('Press Enter to exit...');
  ReadLn;
  {$ENDIF}
end.