Karta.Inbound.Encoding (Karta v1.0.0)

The bytes of the request bodies Karta sends for received mail, encoded as the formats it imitates encode them:

  • base64_lines/1 - base64 in lines of 60 characters, each ended by a line feed, as Ruby's Base64.encode64 writes it (Postal's formats);
  • form/1 - application/x-www-form-urlencoded, as Ruby's URI.encode_www_form writes it: letters, digits and *-._ as they are, a space as +, every other byte as %XX; a nil value is the name alone (name, not name=), and a list repeats the name once per value (an empty list is left out, where Ruby writes a stray &);
  • multipart/1 - multipart/form-data (SendGrid's format, and Mailgun's when the message has attachments).

Summary

Functions

Base64 in lines of 60 characters, each ended by a line feed, as Ruby's Base64.encode64 (and so Postal) writes it.

Form data as Ruby's URI.encode_www_form writes it (see the module doc). A value that is an integer, a float or a boolean is written as to_string/1 writes it, as Ruby's to_s does.

A multipart/form-data request body and its content type.

Functions

base64_lines(data)

@spec base64_lines(binary()) :: binary()

Base64 in lines of 60 characters, each ended by a line feed, as Ruby's Base64.encode64 (and so Postal) writes it.

form(fields)

@spec form(keyword() | [{String.t(), term()}]) :: String.t()

Form data as Ruby's URI.encode_www_form writes it (see the module doc). A value that is an integer, a float or a boolean is written as to_string/1 writes it, as Ruby's to_s does.

multipart(parts, opts \\ [])

@spec multipart([map()], keyword()) :: {String.t(), binary()}

A multipart/form-data request body and its content type.

Each part is a map with :name and :data, and optionally :filename and :content_type (a file part). boundary: fixes the boundary (tests use it); otherwise it is random, which keeps it out of any part.