package mrmime

  1. Overview
  2. Docs

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.

let name = Phrase.(v [ w "Daniel"; w "B" ]) ;;
val name : phrase
Phrase.to_string name ;;
- : string = "Daniel B"

About special encoding/charset, a `Word can store a valid UTF-8 string. Otherwise, you can use an Encoded_word.t to keep special characters:

let name = Phrase.(v [ w "Daniel"; e ~encoding:q "Bünzli" ]) ;;
- name : phrase
Phrase.to_string name ;;
- "Daniel =?UTF-8?Q?B=C3=BCnzli?=" : string

NOTE: we accept only valid UTF-8 contents. Other charset (like latin1) are NOT allowed - we can compute them but we choose to never produce them.

type elt = [
  1. | `Dot
  2. | `Word of Emile.word
  3. | `Encoded of string * Emile.raw
]
type 'a t =
  1. | [] : Mrmime__.Peano.z t
  2. | :: : elt * 'a t -> 'a Mrmime__.Peano.s t
    (*

    Phrase, according RFC 5322, is a non-empty list of three elements (elt):

    • `Dot a dot surrounded by space
    • `Word w a word
    • `Encoded e an encoded-word
    *)
val o : elt

o produces a `Dot.

val w : string -> elt

w produces a safe word. w will try to escape control characters and verify if contents respects standards. Otherwise, w raises an Invalid_argument. `Word produced by w can be surrounded by double-quote.

val e : encoding:Encoded_word.encoding -> string -> elt

e is an alias of Encoded_word.make_exn. About `Encoded word, user can choose the way to encode the word. b for a Base64 encoding or q for a Quoted-Printable encoding. Both accept only UTF-8 contents - we don't accept any other charset.

Quoted-Printable encoding.

Base64 encoding.

val word : string -> (elt, [> Rresult.R.msg ]) result

word x tries to normalize x as a `Word according RFC 5322. It returns Error if x does not respect standards. If contents is an UTF-8 contents, word will surround x with double-quote and will escape control characters (see escape_string).

NOTE: UTF-8 is allowed in e-mails according RFC 6532.

val word_exn : string -> elt

Same as word but raises Invalid_argument instead to return Error.

val coerce : 'a Mrmime__.Peano.s t -> Emile.phrase

coerce l returns a valid and safe phrase.

val make : 'a t -> (Emile.phrase, [> Rresult.R.msg ]) result

make l returns a phrase only if l is a non-empty list.

val v : 'a t -> Emile.phrase

Same as make but raises an exception instead to return Error.

val to_string : Emile.phrase -> string

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

OCaml

Innovation. Community. Security.