Contents · Forum Home · StreamSec Tools 4.1.5.363 documentation

StreamSec.Mail.IMAPClient

The client counterpart of StreamSec.Mail.IMAPServer, on TsmCustomTLSClient
  exactly as StreamSec.Mail.POP3Client is - implicit TLS on 993, or cleartext on
  143 upgraded with STARTTLS inside the base's upgrade window and nothing else
  passing in the clear.

  THE LITERAL IS THE FRAMING PROBLEM ON THIS SIDE TOO, and it is the same
  problem: a response line ending in a braced octet count says that exactly that
  many octets follow, whatever they contain - CRLF, a tagged line, a complete
  second response. A reader that keeps scanning for CRLF while a literal is
  outstanding can be made to treat a message body as protocol, which is how a
  hostile server drives a client. So there are two read modes here, a line and a
  byte countdown, and the countdown never looks for a delimiter.

  EVERYTHING IS ADDRESSED BY UID, not by message number. Sequence numbers are
  renumbered by any EXPUNGE - including one another client caused between two of
  this client's own commands - so an API built on them is a race by
  construction. The UID commands cost nothing extra and cannot be raced.

  ONE TAG PER COMMAND, generated here and matched on the way back. An untagged
  line is DATA and is collected; only the tagged line completes the command, and
  its status decides. A client that acts on an untagged OK is acting on
  something the server may have sent about an entirely different command.

Feature notes: Mail subsystem notes (SMTP / POP3 / IMAP)

Classes, interfaces and records

classeIMAPClientError

inherits from eTLSClientError

constructor CreateFail(const aCommand, aText: string); property Command: string read fCommand;

recordtIMAPMailboxInfo

What SELECT learned. Everything a client needs to decide whether its cached view is still valid - and UidValidity is the one that decides it: a change means every UID the client remembers is meaningless.

Name: string; Exists: Integer; Recent: Integer; Unseen: Integer; UidValidity: Cardinal; UidNext: Cardinal; ReadOnly: Boolean;

classTsmCustomIMAPClient

inherits from TsmCustomTLSClient

constructor Create(AOwner: TComponent); override; destructor Destroy; override; procedure Open;
Connect, greet, upgrade if this is the cleartext port, and sign in when UserName is set. » member page
procedure Close;
LOGOUT and disconnect. Safe to call on a session that never opened. » member page
function SelectMailbox(const aName: string; aReadOnly: Boolean = False): tIMAPMailboxInfo; procedure CloseMailbox; procedure ListMailboxes(aDest: TStrings; const aPattern: string = '*'; aSubscribedOnly: Boolean = False); procedure CreateMailbox(const aName: string); procedure DeleteMailbox(const aName: string); procedure RenameMailbox(const aFrom, aTo: string); procedure SubscribeMailbox(const aName: string; aSubscribe: Boolean = True); function StatusOf(const aName: string): tIMAPMailboxInfo; function Search(const aCriteria: string = 'ALL'): TArray<Cardinal>;
The UIDs in the selected mailbox matching aCriteria ('ALL', 'UNSEEN', 'SINCE 1-Jan-2026', ...). » member page
function FetchMessage(aUid: Cardinal): tBytes; overload; procedure FetchMessage(aUid: Cardinal; aDest: TStream); overload; procedure FetchMessage(aUid: Cardinal; aMessage: TsmEmail); overload; function FetchHeaders(aUid: Cardinal): tBytes;
The header block alone - what a client shows in a list without paying for the bodies. » member page
function FetchFlags(aUid: Cardinal): tMailFlags; procedure StoreFlags(aUid: Cardinal; aFlags: tMailFlags; aMode: tMailFlagMode = mfmAdd); procedure MarkDeleted(aUid: Cardinal);
\Deleted is a MARK. Nothing leaves the mailbox until Expunge. » member page
procedure Expunge; function AppendMessage(const aMailbox: string; const aData: tBytes; aFlags: tMailFlags = []): Cardinal; overload;
Answers the new UID when the server reported one (UIDPLUS), else 0. » member page
function AppendMessage(const aMailbox: string; aMessage: TsmEmail; aFlags: tMailFlags = []): Cardinal; overload; function CopyMessage(aUid: Cardinal; const aMailbox: string): Cardinal; procedure Noop; procedure SetPassword(const aValue: string); property Password: iSecretKey read fPassword write fPassword; property Capabilities: TStrings read GetCapabilities; function SupportsCapability(const aName: string): Boolean; property LastReplyStatus: string read fLastStatus; property LastReplyText: string read fLastText; property Authenticated: Boolean read fAuthenticated; property SessionOpen: Boolean read fSessionOpen; property Selected: tIMAPMailboxInfo read fSelected; property UserName: string read fUserName write fUserName; property AuthMechanism: tIMAPAuthMechanism read fAuthMechanism write fAuthMechanism default iamAuto; property ReplyTimeout: Cardinal read fReplyTimeout write fReplyTimeout default cIMAPDefaultReplyTimeout; property DataTimeout: Cardinal read fDataTimeout write fDataTimeout default cIMAPDefaultDataTimeout; property MaxResponse: Integer read fMaxResponse write fMaxResponse default cIMAPDefaultMaxResponse;

classTsmIMAPClient — component reference

inherits from TsmCustomIMAPClient

THE ORDINARY TIER: it owns its TLS engine, so a form needs one component.

property TLSServer: TsmSimpleTLSInternalServer read GetTLSServer write SetOwnTLSServer;

classTsmAdvancedIMAPClient — component reference

inherits from TsmCustomIMAPClient

THE ADVANCED TIER: it is GIVEN an engine, which is what lets a deployment put one trust domain behind several clients - see the note in StreamSec.Mail.SMTPClient's own pair.

property TLSServer;

Types (enumerations, sets, aliases)

enumtIMAPAuthMechanism

iamAuto prefers a SASL mechanism when the server advertises one and falls back to the LOGIN command; the rest name one and fail if it is unavailable, which is what a deployment that has decided wants.

  tIMAPAuthMechanism = (iamAuto, iamLogin, iamPlain, iamSaslLogin);

Routines