Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Load a MessageSet from a Compact String
See more IMAP Examples
Demonstrates the Chilkat MessageSet.FromCompactString method, which clears the set and loads message identifiers from compact IMAP message-set syntax. The only argument is the compact string: a colon specifies an inclusive ascending range, and commas separate values or ranges. This example loads 1:5,8:10 and prints the result as a comma-separated list.
Background: Compact message-set syntax is how IMAP itself expresses groups of messages —
1:5,8:10 is far more concise than listing every id. FromCompactString is the inverse of ToCompactString: it parses that text into a set you can pass to Imap methods. Duplicates are removed, identifiers are sorted ascending, and the existing HasUids setting is preserved. Note the string carries only the numbers — it does not record whether they are UIDs or sequence numbers.Chilkat Pascal (Lazarus/Delphi) Downloads
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;
csv: string;
begin
success := False;
// Demonstrates the MessageSet.FromCompactString method, which loads a set of message
// identifiers from compact IMAP message-set syntax. The only argument is the compact string.
// A colon specifies an inclusive range, and commas separate values or ranges.
msgSet := TMessageSet.Create;
// Load a compact message set. "1:5,8:10" expands to 1,2,3,4,5,8,9,10.
success := msgSet.FromCompactString('1:5,8:10');
if (success = False) then
begin
WriteLn(msgSet.LastErrorText);
Exit;
end;
WriteLn('Count: ' + msgSet.Count);
// Show the loaded identifiers in comma-separated form.
csv := msgSet.ToCommaSeparatedStr();
WriteLn(csv);
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.