Karta.SMTP.LineBuffer (Karta v1.0.0)

Frames SMTP command lines. Holds at most max bytes of an unfinished line plus one network read, so a client can never make us buffer without limit. Lines must end in CRLF; a bare LF, or a CR anywhere else in the line, is returned as {:bare_newline, line} so the session can reject it (a defence against SMTP smuggling).

Summary

Functions

Pops the next complete line. max counts the line including its line ending.

Returns all unconsumed bytes and empties the buffer.

Types

line()

@type line() :: {:line, binary()} | {:bare_newline, binary()}

t()

@type t() :: %Karta.SMTP.LineBuffer{data: binary(), max: pos_integer()}

Functions

append(buf, bytes)

@spec append(t(), binary()) :: t()

new(max)

@spec new(pos_integer()) :: t()

next_line(buf)

@spec next_line(t()) :: {:ok, line(), t()} | {:more, t()} | {:error, :line_too_long}

Pops the next complete line. max counts the line including its line ending.

take_rest(buf)

@spec take_rest(t()) :: {binary(), t()}

Returns all unconsumed bytes and empties the buffer.