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)
inherits from eTLSClientError
constructor CreateFail(const aCommand, aText: string);
property Command: string read fCommand;
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;
inherits from TsmCustomTLSClient
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Open;
procedure Close;
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>;
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;
function FetchFlags(aUid: Cardinal): tMailFlags;
procedure StoreFlags(aUid: Cardinal; aFlags: tMailFlags; aMode: tMailFlagMode = mfmAdd);
procedure MarkDeleted(aUid: Cardinal);
procedure Expunge;
function AppendMessage(const aMailbox: string; const aData: tBytes; aFlags: tMailFlags = []): Cardinal; overload;
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;
inherits from TsmCustomIMAPClient
THE ORDINARY TIER: it owns its TLS engine, so a form needs one component.
property TLSServer: TsmSimpleTLSInternalServer read GetTLSServer write SetOwnTLSServer;
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;
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.