### 3.9 `decodemail` – Decode multipart messages ¶

The `decodemail` utility is a filter program that reads messages from the input mailbox, decodes “textual” parts of each multipart message from a base64- or quoted-printable encoding to an 8-bit or 7-bit transfer encoding, and stores the processed messages in the output mailbox. All messages from the input mailbox are stored in the output, regardless of whether a change was made.

The message parts deemed to be textual are those whose ‘`Content-Type`’ header matches a predefined, or user-defined, mime type pattern. In addition, encoded pieces of the ‘`From:`’, ‘`To:`’, ‘`Subject:`’, etc., headers are decoded.

For example, `decodemail` makes this transformation:

    Subject: =?utf-8?Q?The=20Baroque=20Enquirer=20|=20July=202020?=
    ⇒ Subject: The Baroque Enquirer | July 2020

The built-in list of textual content type patterns is:

    text/*
    application/*shell
    application/shellscript
    */x-csrc
    */x-csource
    */x-diff
    */x-patch
    */x-perl
    */x-php
    */x-python
    */x-sh

These strings are matched as shell globbing patterns (see glob in glob(7) manual page).

More patterns can be added to this list using the `mime.text-type` configuration statement. See The `mime` Statement, for a detailed discussion, and the configuration section below for a simple example.

When processing old mesages you may encounter ‘`Content-Type`’ headers whose value contains only type, but no subtype. To match such headers, use the pattern without ‘`/whatever`’ part. E.g. ‘`text/*`’ matches ‘`text/plain`’ and ‘`text/html`’, but does not match ‘`text`’. On the other hand, ‘`t*xt`’ does not match ‘`text/plain`’, but does match ‘`text`’.

Optionally, the decoded parts can be converted to another character set. By default, the character set is not changed.