THE COMPONENT THAT SERVES A MAILBOX OVER IMAP. It joins the transport-free engine in StreamSec.Mail.IMAPEngine to the store in StreamSec.Mail.Maildir, on the shared base in StreamSec.Mail.Retrieval, over the two listeners in StreamSec.Mail.IMAPTransport. The exact counterpart of StreamSec.Mail.POP3Server, class for class. TWO PORTS, ONE POLICY. 143 is cleartext with STARTTLS and 993 is implicit TLS on a TsmAsyncTLSServer, and tImapServerSession serves both. That is not tidiness: the authentication gate, the selected-mailbox rules and the expunge semantics 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 iImapChannel, which is why the same class sits on a connection thread and on the reactor. THE VIEW IS THE SELECTED MAILBOX, and its lifetime is this unit's problem. Unlike POP3 the store is opened mbmReadWrite (or mbmReadOnly for EXAMINE) rather than mbmExclusive - IMAP explicitly allows concurrent sessions on one mailbox, and taking the maildrop lock here would make a second client's SELECT fail for a reason IMAP has no way to express. The view is still released on EVERY exit, because it holds an open index.
Feature notes: Mail subsystem notes (SMTP / POP3 / IMAP)
(no public members)
(no public members)
inherits from TInterfacedObject
implements iImapServerPolicy
THE POLICY AND NOTHING ABOUT ANY TRANSPORT.
constructor Create(aServer: TsmCustomIMAPServer; const aChannel: iImapChannel; aSecure, aOfferStartTLS: Boolean);
destructor Destroy; override;
function Greeting(const aSession: tImapSession): string;
function Authenticate(const aSession: tImapSession; const aUser: string; const aPassword: iSecretKey; var aWhy: string): Boolean;
function SelectFolder(const aSession: tImapSession; const aFolder: string; aReadOnly: Boolean; var aWhy: string): Boolean;
procedure CloseFolder(const aSession: tImapSession; aExpunge: Boolean);
function CreateFolder(const aSession: tImapSession; const aFolder: string; var aWhy: string): Boolean;
function DeleteFolder(const aSession: tImapSession; const aFolder: string; var aWhy: string): Boolean;
function RenameFolder(const aSession: tImapSession; const aFrom, aTo: string; var aWhy: string): Boolean;
function Subscribe(const aSession: tImapSession; const aFolder: string; aSubscribe: Boolean; var aWhy: string): Boolean;
function ListFolders(const aSession: tImapSession; const aReference, aPattern: string; aSubscribedOnly: Boolean): TArray<string>;
function SpecialUse(const aSession: tImapSession; const aFolder: string): string;
function FolderStatus(const aSession: tImapSession; const aFolder: string; out aCounts: tImapStatusCounts; var aWhy: string): Boolean;
function QuotaRoots(const aSession: tImapSession; const aFolder: string; out aRoots: TArray<string>; var aWhy: string): Boolean;
function QuotaResources(const aSession: tImapSession; const aRoot: string; out aResources: tImapQuotaResources; var aWhy: string): Boolean;
function MessageCount(const aSession: tImapSession): Integer;
function RecentCount(const aSession: tImapSession): Integer;
function UidValidity(const aSession: tImapSession): Cardinal;
function UidNext(const aSession: tImapSession): Cardinal;
function FirstUnseen(const aSession: tImapSession): Integer;
function ItemAt(const aSession: tImapSession; aIndex: Integer): tMailItem;
function ReadMessage(const aSession: tImapSession; aIndex: Integer; out aData: tBytes): Boolean;
function ReadHead(const aSession: tImapSession; aIndex, aBodyLines: Integer; out aData: tBytes): Boolean;
function SetFlags(const aSession: tImapSession; aIndex: Integer; aFlags: tMailFlags; const aKeywords: TArray<string>; aMode: tMailFlagMode; aExternalChanged: PBoolean = nil): tMailFlagResult;
function MailboxKeywords(const aSession: tImapSession; out aRoom: Integer): TArray<string>;
function Expunge(const aSession: tImapSession; const aRestrict: TArray<Integer>; out aRemoved: TArray<Integer>; var aWhy: string): Boolean;
function AppendMessage(const aSession: tImapSession; const aFolder: string; const aData: tBytes; aFlags: tMailFlags; const aKeywords: TArray<string>; const aArrived: TDateTime; out aUidValidity: Cardinal; out aUid: Cardinal; var aWhy: string; out aTryCreate: Boolean): Boolean;
function CopyMessages(const aSession: tImapSession; const aIndices: TArray<Integer>; const aFolder: string; out aUidValidity: Cardinal; out aSrcUids, aDstUids: TArray<Cardinal>; var aWhy: string; out aTryCreate: Boolean): Boolean;
function MoveMessages(const aSession: tImapSession; const aIndices: TArray<Integer>; const aFolder: string; out aUidValidity: Cardinal; out aSrcUids, aDstUids: TArray<Cardinal>; out aRemoved: TArray<Integer>; var aWhy: string; out aTryCreate: Boolean): Boolean;
function Refresh(const aSession: tImapSession; out aAdded: Integer): Boolean;
procedure SessionClosed(const aSession: tImapSession);
procedure SessionOpening;
procedure SessionFinished;
procedure IdleRound;
The cleartext listener's handler - one connection thread drives it.
procedure HandlerOpened(const aChannel: iMailChannel);
procedure iMailConnectionHandler.Opened = HandlerOpened;
procedure iImapConnectionHandler.Opened = HandlerOpened;
procedure DataReceived(aData: Pointer; aLen: Integer);
function Pending: tMailHandlerPending;
procedure SecureChannelEstablished;
procedure IdleTimeout(aWholeSession: Boolean);
procedure HandlerClosed;
procedure iMailConnectionHandler.Closed = HandlerClosed;
procedure iImapConnectionHandler.Closed = HandlerClosed;
function PastPreamble: Boolean;
The reactor's session - 993, implicit TLS, no thread of its own. While it is in IDLE the transport's work deadline stands in for the connection thread's read round, and only then: a session outside IDLE costs no wakeups.
constructor Create(aServer: TsmCustomIMAPServer; 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;
procedure WorkQueued;
What an IMAP conversation on the reactor sees of its transport.
constructor Create(const aTransport: iAppTransport);
destructor Destroy; override;
procedure Detach;
function GetRemoteAddress: string;
function GetSecure: Boolean;
function GetVersionName: string;
function GetCipherSuiteName: string;
function GetPeerCertificate: iCertificate;
function GetPeerCertificatePresent: Boolean;
procedure Send(aData: Pointer; aLen: Integer);
procedure Close(aGraceful: Boolean);
procedure Abort;
inherits from TInterfacedObject
implements iAppProtocol
The ALPN plugin adapter.
constructor Create(aOwner: TsmCustomIMAPServer);
destructor Destroy; override;
procedure Detach;
function GetToken: OctetString;
function GetDescription: string;
function CreateSession(const aTransport: iAppTransport): iAppSession;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function AppProtocol: iAppProtocol;
property Plain: tImapListenerOptions read fPlain write SetPlain;
property Limits: tImapLimits read fLimits write SetLimits;
property AuthMechanisms: tImapServerAuths read fAuthMechanisms write fAuthMechanisms default [isaLoginCmd,isaPlain,isaLogin];
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;
property SpecialUse: TStrings read GetSpecialUse write SetSpecialUse;
function SpecialUseOf(const aFolder: string; const aAccess: iMailboxAccess): string;
inherits from TsmCustomIMAPServer
property Store;
property Users;
property TLSServer;
property ServerName;
property Banner;
property Plain;
property Limits;
property AuthMechanisms;
property Server;
property AlpnToken;
property AlpnPriority;
property IsFallback;
property SpecialUse;
property Active;
property OnAuthenticate;
property OnSessionOpened;
property OnSessionClosed;
property OnLog;