Skip to main content

src/sendr@message@body.erl

-module(sendr@message@body).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/sendr/message/body.gleam").
-export([new/2, set_text/2, set_html/2]).
-export_type([body/0]).

-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.

?MODULEDOC(
    " This module provides a lax representation of a message body as defined in\n"
    " [RFC 5322, section 3.3](https://tools.ietf.org/html/rfc5322#section-3.3).\n"
    "\n"
    " It does not enforce any of the rules and requirements of the RFC. Since we\n"
    " do not know what transformations the Mail Submission Agent will perform and\n"
    " what the Mail Submission Agent is capable of handling.\n"
).

-type body() :: {body,
        gleam@option:option(binary()),
        gleam@option:option(binary())}.

-file("src/sendr/message/body.gleam", 23).
?DOC(" Creates a new `Body` with a text and html body.\n").
-spec new(gleam@option:option(binary()), gleam@option:option(binary())) -> body().
new(Text, Html) ->
    {body, Text, Html}.

-file("src/sendr/message/body.gleam", 28).
?DOC(" Set the textual body\n").
-spec set_text(body(), binary()) -> body().
set_text(Body, Text) ->
    {body, {some, Text}, erlang:element(3, Body)}.

-file("src/sendr/message/body.gleam", 33).
?DOC(" Set the html body\n").
-spec set_html(body(), binary()) -> body().
set_html(Body, Html) ->
    {body, erlang:element(2, Body), {some, Html}}.