THE COMPONENT THAT SERVES A MAILBOX OVER POP3. It joins the transport-free engine in StreamSec.Mail.POP3Engine to the store in StreamSec.Mail.Maildir, on the shared base in StreamSec.Mail.Retrieval, over the two listeners in StreamSec.Mail.POP3Transport. TWO PORTS, ONE POLICY. 110 is cleartext with STLS and 995 is implicit TLS on a TsmAsyncTLSServer, and tPop3ServerSession serves both. That is not tidiness: the maildrop lock, the authentication gate and the commit rule live in it, and a second copy of them is how one port ends up behaving differently from the other. The session talks to its transport ONLY through iPop3Channel, which is why the same class sits on a connection thread and on the reactor. THE MAILDROP LOCK IS THE SESSION'S, AND ITS LIFETIME IS THIS UNIT'S PROBLEM. RFC 1939 sec.3 wants exclusive access for the length of the session; the store gives that by opening the view mbmExclusive, and the view holds it until it is released. So the session must release it on EVERY exit - QUIT, an idle timeout, a dropped socket, an exception inside a command - or the next attempt by that user is refused until the lock goes stale. That is why the view is released in Closed, which the driver calls on every path, rather than in the QUIT handler where it would be missed by four of the five.
Feature notes: Mail subsystem notes (SMTP / POP3 / IMAP)
(no public members)
ONE POP3 CONVERSATION: the engine's policy and the transport's handler in one object, because both are per connection and the questions they ask each other are its own.
(no public members)
inherits from TInterfacedObject
implements iPop3ServerPolicy
THE POLICY AND NOTHING ABOUT ANY TRANSPORT. One implementation serves both ports - 110 cleartext with STLS, 995 implicit TLS - and that is not tidiness: the maildrop lock, the authentication gate and the commit rule live here, and a second copy of them is how one port ends up behaving differently from the other. It talks to its transport ONLY through iPop3Channel, which is why the same class sits on a connection thread and on the reactor.
constructor Create(aServer: TsmCustomPOP3Server; const aChannel: iPop3Channel; aSecure, aOfferStartTLS: Boolean);
destructor Destroy; override;
function Greeting(const aSession: tPop3Session): string;
function Authenticate(const aSession: tPop3Session; const aUser: string; const aPassword: iSecretKey; var aWhy: string): Boolean;
function OpenMaildrop(const aSession: tPop3Session; var aWhy: string): Boolean;
function MessageCount(const aSession: tPop3Session): Integer;
function MessageOctets(const aSession: tPop3Session; aIndex: Integer): Int64;
function MessageUidl(const aSession: tPop3Session; aIndex: Integer): string;
function ReadMessage(const aSession: tPop3Session; aIndex: Integer; out aData: tBytes): Boolean;
function ReadHead(const aSession: tPop3Session; aIndex, aBodyLines: Integer; out aData: tBytes): Boolean;
function Commit(const aSession: tPop3Session; const aDeleted: TArray<Integer>; var aWhy: string): Boolean;
procedure SessionClosed(const aSession: tPop3Session);
procedure SessionOpening;
procedure SessionFinished;
THE CLEARTEXT HALF: port 110, driven by a connection thread, and the only one of the two that can be asked to upgrade mid-session.
procedure HandlerOpened(const aChannel: iMailChannel);
procedure iMailConnectionHandler.Opened = HandlerOpened;
procedure iPop3ConnectionHandler.Opened = HandlerOpened;
procedure DataReceived(aData: Pointer; aLen: Integer);
function Pending: tMailHandlerPending;
procedure SecureChannelEstablished;
procedure IdleTimeout(aWholeSession: Boolean);
procedure HandlerClosed;
procedure iMailConnectionHandler.Closed = HandlerClosed;
procedure iPop3ConnectionHandler.Closed = HandlerClosed;
function PastPreamble: Boolean;
inherits from tPop3ServerSession
implements iAppSession, iAppSessionNudge
THE ASYNC-TLS HALF: implicit TLS on 995, driven by the reactor. RFC 8314 calls this the preferred deployment.
constructor Create(aServer: TsmCustomPOP3Server; const aTransport: iAppTransport); reintroduce;
procedure Opened;
procedure DataReceived(aData: Pointer; aLen: Integer);
procedure EarlyDataReceived(aData: Pointer; aLen: Integer);
procedure Closed(aGraceful: Boolean);
function Instance: tObject;
function Nudged(aReason: tNudgeReason; var aRearmMs: Cardinal): tNudgeVerdict;
iPop3Channel over the async server's transport, so the one policy class can be driven by the reactor without knowing it. It lives HERE, in the unit that already uses both, which is what keeps StreamSec.Mail.POP3Transport free of any dependency on the async server.
constructor Create(const aTransport: iAppTransport);
destructor Destroy; override;
procedure Send(aData: Pointer; aLen: Integer);
procedure Close(aGraceful: Boolean);
procedure Abort;
procedure Detach;
inherits from TInterfacedObject
implements iAppProtocol
constructor Create(aOwner: TsmCustomPOP3Server);
destructor Destroy; override;
procedure Detach;
function CreateSession(const aTransport: iAppTransport): iAppSession;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function AppProtocol: iAppProtocol;
property Plain: tPop3ListenerOptions read fPlain write SetPlain;
property Limits: tPop3Limits read fLimits write SetLimits;
property AuthMechanisms: tPop3ServerAuths read fAuthMechanisms write fAuthMechanisms;
property Server: TsmAsyncTLSServer read fServer write SetServer;
property AlpnToken: string read fAlpnToken write SetAlpnToken;
property AlpnPriority: Integer read fAlpnPriority write SetAlpnPriority default cAlpnPriorityDefault;
property IsFallback: Boolean read fIsFallback write SetIsFallback default False;
inherits from TsmCustomPOP3Server
(no public members)