Karta. SMTP. Spool
(Karta v1.0.0)
The disk spool for incoming message data.
DATA and BDAT bytes are written to one file per message in the spool
directory, so memory stays bounded whatever the message size. Files are
private: the directory is mode 0700, each file is created with
O_EXCL under a random name and set to mode 0600 before any data is
written.
Every file belongs to the connection process that opened it. This
process (the janitor) monitors the owners and deletes their files when
they exit, whatever the reason, so an aborted or crashed connection never
leaves message data behind. At start it removes files left by a previous
run. Only names this module creates (msg-<hex>.eml) are ever deleted.
Summary
Functions
Returns a specification to start this module under a supervisor.
The spool directory.
Creates a new spool file owned by the calling process and opens it for writing. Returns the raw file handle and the path.
Creates the directory with mode 0700 and removes spool files left by an earlier run. Other files in the directory are left alone.
Deletes a spool file of the calling process and forgets it. Paths the caller does not own are ignored. Safe to call twice.
Waits until the janitor has handled all earlier messages (for tests).
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec dir() :: Path.t()
The spool directory.
@spec open() :: {:ok, :file.io_device(), Path.t()} | {:error, term()}
Creates a new spool file owned by the calling process and opens it for writing. Returns the raw file handle and the path.
@spec prepare_dir!(Path.t()) :: :ok
Creates the directory with mode 0700 and removes spool files left by an earlier run. Other files in the directory are left alone.
@spec release(Path.t() | Karta.SMTP.SpoolFile.t() | nil) :: :ok
Deletes a spool file of the calling process and forgets it. Paths the caller does not own are ignored. Safe to call twice.
@spec sync() :: :ok
Waits until the janitor has handled all earlier messages (for tests).