internal/renderer/internet_message

This module implements functions to render a sendr message into the internet message format as specified in RFC 5322 and updated by RFC 6854.

Types

Errors that can occur when encoding header field bodies.

pub type FieldBodyError {
  InvalidDate(#(timestamp.Timestamp, duration.Duration))
  InvalidEmailAddress(String)
}

Constructors

Errors that can occur during message rendering.

pub type RenderError {
  InvalidHeaderFieldName(String)
  InvalidHeaderFieldBody(FieldBodyError)
  InvalidEncoding(encoding.Encoding)
  NoUsableEncodingFound(List(encoding.Encoding))
  EncodingFailed(encoding.EncoderError)
}

Constructors

  • InvalidHeaderFieldName(String)

    The header field name is invalid (e.g., contains spaces or special characters).

  • InvalidHeaderFieldBody(FieldBodyError)

    The header field body is invalid and can’t be encoded.

  • InvalidEncoding(encoding.Encoding)

    An invalid encoding was specified for the context (header/body) it is used in.

  • NoUsableEncodingFound(List(encoding.Encoding))

    No suitable encoder could be found for the given input and constraints.

  • EncodingFailed(encoding.EncoderError)

    Encoding failed due to an encoder error.

Values

pub fn encode(
  mail message: message.Message,
  with mode: encoding.EncodingMode,
) -> Result(List(String), RenderError)

Render a sendr Message into an Internet Message format string.

This function converts a sendr/message.Message into a string conforming to RFC 5322 and updated by RFC 6854.

The rendered message includes:

  • Date header (automatically generated from the current system time)
  • From, Reply-To, To, Cc headers (if set on the message)
  • Subject header (if set on the message)
  • Message-ID header (generated from the sender’s address)
  • MIME-Version: 1.0 header
  • Message body (text and/or HTML) with appropriate MIME encoding
  • Attachments (if any), wrapped in multipart/mixed or multipart/related
Search Document