Contents · Forum Home · StreamSec Tools 4.1.5.363 documentation

StreamSec.Mail.POP3Server

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)

Classes, interfaces and records

classTsmCustomPOP3Server

(no public members)

classtPop3AsyncChannel

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)

classtPop3ServerSession

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;
What every transport does on the way in and on the way out, under whatever name its own interface gives it.
procedure SessionFinished;

classtPop3PlainSession

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);
FOUR resolution clauses, not two: Opened and Closed are DECLARED on the neutral base interface, and a clause does not carry from one interface to its relative.
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;
iMailSessionPhase. Past the AUTHORIZATION state.

classtPop3AsyncSession

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;
Returns the object itself (Self).
function Nudged(aReason: tNudgeReason; var aRearmMs: Cardinal): tNudgeVerdict;
iAppSessionNudge. The port's limits, and no reply on the way out: RFC 1939 sec.3 has the server close "without removing any messages or sending any response".

classtPop3AsyncChannel

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;

classtPop3AppProtocol

inherits from TInterfacedObject

implements iAppProtocol

constructor Create(aOwner: TsmCustomPOP3Server); destructor Destroy; override; procedure Detach; function CreateSession(const aTransport: iAppTransport): iAppSession;

classTsmCustomPOP3Server

constructor Create(AOwner: TComponent); override; destructor Destroy; override; function AppProtocol: iAppProtocol;
Register this with TsmAsyncTLSServer.Protocols.AddProtocol when the plugin is wired from code rather than by assigning Server. Full description »
property Plain: tPop3ListenerOptions read fPlain write SetPlain;
THE CLEARTEXT PORT, conventionally 110, with STLS. Disabled by default. Its TLSMode defaults to mtmRequired, and the engine refuses every password mechanism on a cleartext channel whatever it says. » member page
property Limits: tPop3Limits read fLimits write SetLimits;
Per-session bounds - line lengths and the two error budgets. » member page
property AuthMechanisms: tPop3ServerAuths read fAuthMechanisms write fAuthMechanisms;
Which mechanisms are offered. psaUserPass is RFC 1939's USER/PASS and the other two are SASL (RFC 5034); [] means nothing authenticates, which is the family's fail-closed idiom. NONE of them is offered or accepted on a cleartext channel, whatever this says. » member page
property Server: TsmAsyncTLSServer read fServer write SetServer;
THE ASYNC TLS SERVER THAT SERVES 995. Assigning it registers this plugin with that server's protocol registry (clearing it unregisters), so the association is declared in the Object Inspector rather than from code. Full description »
property AlpnToken: string read fAlpnToken write SetAlpnToken;
THE ALPN IDENTIFIER, AND HERE IT IS A REAL ONE. IANA has registered 'pop3' (RFC 8314), unlike SMTP, whose plugin has to invent a private-use string. Settable only until the protocol has been handed to a registry, exactly as TsnipTLSServer.AlpnToken is - after that the token IS a live registry key read on reactor threads. » member page
property AlpnPriority: Integer read fAlpnPriority write SetAlpnPriority default cAlpnPriorityDefault;
Where this protocol sits in the server's ALPN preference list; higher is preferred. Not settable while the server is active. » member page
property IsFallback: Boolean read fIsFallback write SetIsFallback default False;
THE PROTOCOL THAT ANSWERS A CONNECTION WHICH NEGOTIATED NOTHING. A real ALPN token does not make this optional: no POP3 client in the field offers ALPN at all, so without a fallback the port appears dead. The server's own FallbackPolicy must be fbpUseFallback (or fbpFirstRegistered) as well - setting this alone is half the wiring. » member page

classTsmPOP3Server — component reference

inherits from TsmCustomPOP3Server

(no public members)