Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

mail.content

import mail

Everything here is re-exported by mail, so import mail is enough and the names are called as mail.*. Importing mail.content on its own works too and reaches the same definitions.

The two headers that say what a part holds and what to do with it.

Content-Type names the media type and carries the parameters that go with it: the character set of text, the boundary of a multipart, the name of a file. Content-Disposition says whether the part is meant to be shown where it sits or offered as an attachment, and carries the filename to offer it under.

import mail.content { ContentType }

var type = ContentType.parse('text/plain; charset="utf-8"; format=flowed')

echo type.mime_type()
echo type.charset()
echo type.get('format')
text/plain
utf-8
flowed

Constants

DEFAULT_TYPE

mail.DEFAULT_TYPE = 'text/plain'

DEFAULT_CHARSET

mail.DEFAULT_CHARSET = 'us-ascii'

Classes

ContentType

class mail.ContentType

A media type and the parameters that came with it.

  • printable — has a @to_string(), so echo and print() show something useful

Constructor

mail.ContentType(type: string, subtype: string, parameters: ?dict)

Parameters

  • type (string) — The type, such as text.
  • subtype (string) — The subtype, such as plain.
  • parameters (?dict) — The parameters, already decoded.

ContentType.parse()

mail.ContentType.parse(text: ?string) -> ContentType

Reads a Content-Type header.

A header that is missing or empty gives text/plain, which is what a part with no type is defined to be.

Parameters

  • text (?string)

Returns ContentType

ContentType.mime_type()

mail.ContentType.mime_type() -> string

The type and subtype together, as text/plain.

Returns string

ContentType.get()

mail.ContentType.get(name: string, fallback) -> any

One parameter’s value.

Parameters

  • name (string) — Matched without regard to case.
  • fallback (?any) — Returned when the parameter is absent.

Returns any

ContentType.charset()

mail.ContentType.charset() -> string

The character set of a text part.

Returns string — us-ascii when the header does not say, which is the defined default.

ContentType.boundary()

mail.ContentType.boundary() -> string|nil

The boundary that separates the parts of a multipart, or nil when this is not one.

Returns string|nil

ContentType.name()

mail.ContentType.name() -> string|nil

The filename this part suggests, taken from the name parameter.

Content-Disposition is the header that is supposed to carry it, and Message.filename() looks there first.

Returns string|nil

ContentType.is_multipart()

mail.ContentType.is_multipart() -> bool

Whether this part contains other parts.

Returns bool

ContentType.is_text()

mail.ContentType.is_text() -> bool

Whether this part is text, and so has a character set worth applying.

Returns bool

ContentType.to_string()

mail.ContentType.to_string() -> string

The header value, with every parameter written in the form it needs.

Returns string

ContentDisposition

class mail.ContentDisposition

What a part is for: shown where it sits, or offered as a file.

  • printable — has a @to_string(), so echo and print() show something useful

Constructor

mail.ContentDisposition(kind: string, parameters: ?dict)

Parameters

  • kind (string) — inline or attachment.
  • parameters (?dict)

ContentDisposition.parse()

mail.ContentDisposition.parse(text: ?string) -> ContentDisposition

Reads a Content-Disposition header.

Parameters

  • text (?string)

Returns ContentDisposition

ContentDisposition.get()

mail.ContentDisposition.get(name: string, fallback) -> any

One parameter’s value.

Parameters

  • name (string)
  • fallback (?any)

Returns any

ContentDisposition.filename()

mail.ContentDisposition.filename() -> string|nil

The filename the part should be saved under, or nil.

Returns string|nil

ContentDisposition.is_attachment()

mail.ContentDisposition.is_attachment() -> bool

Whether the part is meant to be offered as a file rather than shown in place.

Returns bool

ContentDisposition.to_string()

mail.ContentDisposition.to_string()

2026, Richard Ore and Zuri contributors