Karta.SMTP.DataReader (Karta v1.0.0)

Reads a DATA section (RFC 5321 §4.1.1.4, §4.5.2).

  • The message ends only on a strict <CRLF>.<CRLF>, where the leading CRLF may be the virtual one at the start of DATA. A bare LF or a bare CR never ends a line, so \n.\r\n and friends cannot smuggle a second message; any bare LF/CR is flagged and the session rejects the message.
  • A leading dot on a line is removed (dot-unstuffing).
  • Bytes past max are counted but not stored, so memory stays bounded while we still read up to the terminator and can answer 552.

Summary

Functions

Discards the message: the sink drops what it holds (used when the connection ends mid-DATA).

Feeds bytes. Returns {:done, reader, rest} once the terminator is seen; rest follows it.

Types

t()

@type t() :: %Karta.SMTP.DataReader{
  at_line_start: term(),
  bare_newline: term(),
  max: term(),
  pending: term(),
  sink: term(),
  sink_state: term(),
  size: term(),
  too_large: term()
}

Functions

abort(r)

@spec abort(t()) :: :ok

Discards the message: the sink drops what it holds (used when the connection ends mid-DATA).

feed(r, chunk)

@spec feed(t(), binary()) :: {:more, t()} | {:done, t(), binary()}

Feeds bytes. Returns {:done, reader, rest} once the terminator is seen; rest follows it.

finish(r)

@spec finish(t()) :: %{
  body: term(),
  size: non_neg_integer(),
  too_large: boolean(),
  bare_newline: boolean()
}

new(max, sink \\ Memory, sink_opts \\ [])

@spec new(pos_integer(), module(), keyword()) :: t()