Sovite.SMTP.DataEncoder (sovite v0.2.0)

Copy Markdown View Source

Streaming encoder for SMTP DATA content, the inverse of Sovite.SMTP.DataDecoder.

It dot-stuffs the message (RFC 5321 §4.5.2) as chunks are fed in, and finish/1 returns the terminating <CRLF>.<CRLF>, adding a CRLF first if the message does not end with one.

encoder = DataEncoder.new()
{data, encoder} = DataEncoder.encode(encoder, "Subject: hi\r\n\r\n.dot\r\n")
IO.iodata_to_binary([data, DataEncoder.finish(encoder)])
#=> "Subject: hi\r\n\r\n..dot\r\n.\r\n"

The message must use CRLF line endings, as Sovite.Queue.Spool stores it. A dot is stuffed after every LF, so a bare LF can never produce a line that ends the data early.

Summary

Functions

Encodes the next chunk of the message.

Returns the end-of-data sequence.

Returns an encoder for the start of a message.

Types

t()

@opaque t()

Functions

encode(encoder, chunk)

@spec encode(t(), iodata()) :: {iodata(), t()}

Encodes the next chunk of the message.

finish(data_encoder)

@spec finish(t()) :: iodata()

Returns the end-of-data sequence.

new()

@spec new() :: t()

Returns an encoder for the start of a message.