package mrmime

  1. Overview
  2. Docs
type t = Emile.mailbox

Type of mailbox. Normally, a mailbox is composed of two parts:

  • an optional display name that indicates the name of the recipient (which can be a person or a system) that could be displayed to the user of a mail application, and
  • an addr-spec address enclosed in angle brackets ("<" and ">").

There is an alternate simple form of a mailbox where the addr-spec address appears alone, without the recipient's name or the angle brackets.

Equals.

val equal : ?case_sensitive:bool -> t -> t -> bool
val escape_string : string -> string

escape_string x returns a safe string where control characters are escaped (\x00, \x5c, \a, \b, \t, \n, \v, \f, \r and \x22 - double quote).

module Phrase : sig ... end

A phrase in the context of the mailbox is a display-name that indicates the name of the recipient. We provide an easily way to make it and keep conformances according standards.

module Literal_domain : sig ... end
module Domain : sig ... end

A domain can be constructed in several ways. The most common way is:

module Local : sig ... end

Local part of a mailbox is a non-empty list of word elements. You can construct local-part like this:

val make : ?name:Emile.phrase -> Emile.local -> ?domains:Emile.domain list -> Emile.domain -> t

make ?name local ?domains domain returns a mailbox with local-part local, first domain domain, others domains domains (default is an empty list) and an optional name.

let me =
  make Local.(v [ w "romain"; w "calascibetta" ])
    ~domains:[ Domain.(v domain [ a "gmail"; a "com" ]) ]
    Domain.(v domain [ a "x25519"; a "net" ]) ;;
val me : t = ....
to_string me ;;
- : string = "<@gmail.com:romain.calascibetta@x25519.net>"
val (@) : 'a Local.local -> ('b Domain.t * 'b) -> t

@ operator constructs an usual e-mail address:

let me = Local.[ w "romain"; w "calascibetta" ] @ Domain.(domain, [ a "x25519"; a "net" ]) ;;
val me : t = { name= None
             ; local= [ `Atom "romain"; `Atom "calascibetta" ]
             ; domain= (`Domain ["x25519"; "net"], []) }
to_string me ;;
- : string = "romain.calascibetta@x25519.net"

With only one domain and without a display-name. If you want to put multiple domains, you should use make instead. If you want to put a phrase, you can use with_phrase.

@ operator can raise Invalid_argument where local-part or domain fail to normalize inputs according standards (see Local.make and Domain.make).

val with_name : Emile.phrase -> t -> t

with_name phrase t put or replace display name of mailbox t.

let dbuenzli = with_name Phrase.(v [ w "Daniel"; e ~encoding:q "Bünzli" ]) dbuenzli
val dbuenzli : t = ...
(* Stringify dbuenzli! *)
to_string dbuenzli ;;
- : string = "Daniel =?UTF-8?Q?B=C3=BCnzli?= <daniel.buenzli@erratique.ch>"
val to_string : t -> string

to_string x returns a string which represents x as is it in a e-mails.

val of_string : string -> (t, [> `Msg of string ]) result

of_string x returns a t from a well-formed string x according RFC 5322. A mailbox can have several forms and can include FWS tokens. Some examples of what is allowed:

  • thomas@gazagnaire.org
  • Hannesm <hannes@menhert.org>
  • <anil@recoil.org>
  • Romain Calascibetta <@gmail.com:romain.calascibetta@x25519.net>
  • Daniel =?UTF-8?Q?B=C3=BCnzli?= <daniel.buenzli@erratique.ch>

Any encoded-word are normalized to a valid UTF-8 string (even if charset is something else than "UTF-8").

Pretty-printers.

val pp : Format.formatter -> t -> unit

Decoder of mailbox.

module Decoder : sig ... end

Encoder of mailbox.

module Encoder : sig ... end
OCaml

Innovation. Community. Security.