MHBUILD(1mh)

πŸ“¦
version 1.8 Β· 4 versions
, in debian trixie, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– MHBUILD(1mh) πŸ’–

okay bestie, gather round, because this is the mhbuild page from the 1mh manual and it is a lot, but we're gonna get through it together 🫢


✨ NAME ✨

mhbuild β€” translate MIME composition drafts for nmh messages

no cap, that's the whole job description.


🌸 SYNOPSIS 🌸

mhbuild [-help] [-version] file [-auto | -noauto] [-list | -nolist]
     [-realsize | -norealsize] [-headers | -noheaders] [-directives |
     -nodirectives] [-rfc934mode | -norfc934mode] [-contentid |
     -nocontentid] [-verbose | -noverbose] [-disposition |
     -nodisposition] [-headerencoding encoding-algorithm  |
     -autoheaderencoding] [-maxunencoded line-length] [-dist]

πŸ¦‹ DESCRIPTION πŸ¦‹

so like. mhbuild takes a MIME composition draft and turns it into a valid MIME message. that's the vibe. that's the whole arc.

it creates multi-media messages as specified in RFCs 2045 through 2049 πŸ”₯. and that includes encoding of message headers as specified by RFC 2047, and additionally the encoding of MIME parameters as specified in RFC 2231. we love a standards-enjoyer.

now, the file handling. pay attention, this matters:

  • if you specify the name of the composition file as -, then mhbuild will accept the composition draft on the standard input. if the translation of this input is successful, mhbuild will output the new MIME message to the standard output. this argument must be the last argument on the command line. like, literally last. don't be cute about it.
  • otherwise, if the file argument to mhbuild is the name of a valid composition file, and the translation is successful, mhbuild will replace the original file with the new MIME message. it will rename the original file to start with the , character and end with the string .orig. so for example, if you are editing the file draft, it will be renamed to ,draft.orig. πŸ’… this allows you to easily recover the mhbuild input file. thank u for the safety net, iconic behaviour.

πŸ“‹ Listing the Contents

the -list switch tells mhbuild to list the table of contents associated with the MIME message that is created.

the -headers switch indicates that a one-line banner should be displayed above the listing. cute.

the -realsize switch tells mhbuild to evaluate the "native" (decoded) format of each content prior to listing. this provides an accurate count at the expense of a small delay ⏳ (worth it, imo).

if the -verbose switch is present, then the listing will show any "extra" information that is present in the message, such as comments in the Content-Type header. tea β˜•

if the -disposition switch is present, then the listing will show any relevant information from the Content-Disposition header.

πŸŽ€ Simplified Attachment Interface

for users who wish to simply attach files to text content, mhbuild will scan the composition file for Attach headers. an Attach header contains a filename that will be appended to the message using normal MIME encapsulation rules. one filename is allowed per Attach header, but multiple Attach headers are allowed per composition file. so like, stack 'em. 🌈

these files will be appended after any other MIME content, including any content specified by mhbuild directives (see below). see send(1) for more details.

by default, the Content-Disposition will be attachment. mhbuild looks for user profile and mhn.defaults entries of the form

mhbuild-disposition-type/subtype

or

mhbuild-disposition-type

to supply the disposition value. the only supported values are attachment and inline. that's it. those two. don't try anything else.

🧚 Convert Interface

the convert interface is a powerful mechanism that supports replying to MIME messages. these placeholders are used in the following description:

  • TYPE β€” content type/subtype
  • CONVERTER β€” external program, and any fixed arguments, to convert content, such as from a request to a reply
  • ARGSTRING β€” arguments to pass from repl to CONVERTER
  • FILE β€” full path of message being replied to

the convert support is based on pseudoheaders of the form

Nmh-mhbuild-file-TYPE: FILE
Nmh-mhbuild-args-TYPE: ARGSTRING

in the draft. for each such pseudoheader, mhbuild looks in the profile and mhn.defaults for the corresponding TYPE entry to find the converter that supports it:

mhbuild-convert-TYPE: CONVERTER

it's a fatal error if no such entry is found for TYPE. πŸ’€ like, it will just give up. an empty entry, e.g.,

mhbuild-convert-text/html:

excludes parts of that TYPE from the draft.

the mhn.defaults file contains default mhbuild-convert-text/html and mhbuild-convert-text/plain entries. profile entries can be used to override corresponding mhn.defaults entries, as usual.

for each TYPE part in FILE, mhbuild runs CONVERTER ARGSTRING on the content of the part. each part in FILE that has no corresponding TYPE entry in the profile or mhn.defaults is excluded from the draft; the user can include them using mhbuild directives.

repl inserts Nmh-mhbuild-text/html: and Nmh-mhbuild-text/plain: pseudoheaders in every draft. the user can prevent insertion of content parts of either of those types by putting corresponding empty entries in their profile.

only the highest precedence alternative with a supported TYPE of a multipart/alternative part is used.

mhn.defaults.sh selects the text/html-to-text/plain converter at install time.

some content types require the addition of parameters to the Content-Type header, such as method=REPLY for text/calendar. mhbuild looks for a Content-Type header, followed by a blank line, at the beginning of the converter output. if one is found, it is used for the corresponding part in the reply draft.

the convert interface doesn't support different ARGSTRINGs or different converters for different parts of the same TYPE. that would require associating parts by part number with the ARGSTRINGs or converters. instead, that can be done (currently, without using the convert support), with mhbuild directives as described below, e.g.,

#text/html; charset=utf-8 *8bit | mhstore -noverbose -part 42.7
-outfile - | w3m -dump -cols 64 -T text/html -O utf-8

the only way to mix convert pseudoheaders and mhbuild directives is to insert the directives before mhbuild is run, which is typically done by entering mime at the "What now?" prompt, or with an -editor mhbuild switch.

if there are any Nmh-mhbuild- pseudoheaders in the composition file, mhbuild divides the translation into two stages. the first stage includes all translations except encoding of text content. the second stage encodes text content as needed. this allows the user to edit the text prior to encoding. the second stage, along with the first stage if it had not yet been performed, is selected with the -auto switch.

these (optional) setup steps can make the convert support easier to use:

  1. add this line to your profile:
mhbuild-next: $EDITOR

assuming that your EDITOR environment variable is set; if not, replace EDITOR with the name of your editor. without that profile entry, a response of e[dit] at the What now? prompt will require specification of your editor if an -editor mhbuild switch is used.

  1. if using repl, source the Bourne-shell compatible functions in /usr/share/doc/nmh/contrib/replaliases.

πŸ’œ Translating the Composition File

mhbuild is essentially a filter to aid in the composition of MIME messages. mhbuild will convert an mhbuild "composition file" into a valid MIME message. an mhbuild "composition file" is just a file containing plain text that is interspersed with various mhbuild directives. when this file is processed by mhbuild, the various directives will be expanded to the appropriate content, and will be encoded according to the MIME standards. the resulting MIME message can then be sent by electronic mail. ✨

the formal syntax for a mhbuild composition file is defined at the end of this document, but the ideas behind this format are not complex. basically, the body contains one or more contents. a content consists of either a directive, indicated with a # as the first character of a line; or, plaintext (one or more lines of text). the continuation character, \, may be used to enter a single directive on more than one line, e.g.,

#image/png \
    /home/foobar/junk/picture.png

there are five kinds of directives: "type" directives, which name the type and subtype of the content; "external-type" directives, which also name the type and subtype of the content; the "message" directive (#forw), which is used to forward one or more messages; the "begin" directive (#begin), which is used to create a multipart content; and the "on/off/pop" directives (#on, #off, #pop) which control whether any other directives are honored at all. five. count 'em. πŸ–οΈ

the -directives switch allows control over whether mhbuild will honor any of the #-directives. this can also be affected with the #on or #off directives, and #pop, which restores the state of processing to that preceding the most recent #on or #off. (the #on, #off, and #pop directives are always honored, of course.) this allows inclusion of plain text which looks like mhbuild directives, without causing errors:

#off
#include <stdio.h>
puts("hello, world!");
#pop

currently the stack depth for the #on/off/pop directives is 32. remember that number.

the "type" directive is used to directly specify the type and subtype of a content. you may only specify discrete types in this manner (can't specify the types multipart or message with this directive). you may optionally specify the name of a file containing the contents in "native" (decoded) format. if this filename starts with the | character, then it represents a command to execute whose output is captured accordingly. for example,

#audio/basic |raw2audio -F < /usr/lib/sound/giggle.au

if a filename is not given, mhbuild will look for information in the user's profile to determine how the different contents should be composed. this is accomplished by consulting a composition string, and executing it under /bin/sh, with the standard output set to the content. if the -verbose switch is given, mhbuild will echo any commands that are used to create contents in this way.

the composition string may contain the following escapes:

  • %a β€” Insert parameters from directive
  • %f β€” Insert filename containing content
  • %F β€” %f, and stdout is not re-directed
  • %s β€” Insert content subtype
  • %% β€” Insert character %

first, mhbuild will look for an entry of the form:

mhbuild-compose-type/subtype

to determine the command to use to compose the content. if this isn't found, mhbuild will look for an entry of the form:

mhbuild-compose-type

to determine the composition command. if this isn't found, mhbuild will complain. 😀 and honestly? fair.

an example entry might be:


part 1 done bestie, don't go anywhere β€” more coming πŸ’…
mhbuild-compose-audio/basic: record | raw2audio -F

so like, commands like these are gonna change depending on whatever display environment you logged in from 😭 which means composition strings for different contents should prolly live in the file named by the MHBUILD environment variable, instead of getting dumped straight into your user profile. bestie trust me on this one πŸ’…


the external-type directives πŸ¦‹

The external-type directives give you a MIME reference to a content instead of wrapping the content itself β€” like, say, pointing at an ftp site ✨. So instead of handing over a filename like the type directives do, you supply external-parameters. They look exactly like regular parameters, so they have to be separated the same way. For example:

#@application/octet-stream; \
    type=tar; \
    conversions=compress \
    [this is the nmh distribution] \
    {attachment; filename="nmh.tar.gz"} \
    name="nmh.tar.gz"; \
    directory="/pub/nmh"; \
    site="ftp.math.gatech.edu"; \
    access-type=anon-ftp; \
    mode="image"

You MUST give a description string to separate the content parameters from the external-parameters (it can be empty tho, no pressure 🫢). That description string goes inside []. And a disposition string β€” which shows up in a Content-Disposition header β€” can hang out in the optional {}.

These parameters are shaped like:

  • access-type= β€” usually anon-ftp, mail-server, or url
  • name= β€” filename
  • permission= β€” read-only or read-write
  • site= β€” hostname
  • directory= β€” directoryname (optional)
  • mode= β€” usually ascii or image (optional)
  • size= β€” number of octets
  • server= β€” mailbox
  • subject= β€” subject to send
  • body= β€” command to send for retrieval
  • url= β€” URL of content

A minimum external-type directive for the url access-type would be, like:

#@application/octet-stream [] access-type=url; \
  url="http://download.savannah.gnu.org/releases/nmh/nmh-1.5.tar.gz"

Any long URLs get wrapped according to RFC 2231 rules πŸŽ€.


the message directive (#forw) πŸ“¨

The message directive (#forw) is how you say which message or group of messages to include. You can optionally name the folder and pick which messages get forwarded. No folder given? It defaults to the current folder. No message given? It defaults to the current message. So basically the message directive is like the forw command, except it uses the MIME encapsulation rules instead of the RFC 934 ones. Example:

#forw +inbox 42 43 99

If you include a single message, it gets included directly as a content of type message/rfc822. If you include more than one, then mhbuild adds a content of type multipart/digest and tucks each message in as a subpart of that content ✨.

If you're using this directive to include more than one message, you may use the -rfc934mode switch. This switch says mhbuild should try to use the MIME encapsulation rules in a way that the multipart/digest it creates is (mostly) compatible with the encapsulation in RFC 934. If you give it, then RFC 934 compliant user-agents should be able to burst the message on reception β€” provided that the messages being encapsulated don't themselves contain encapsulated messages 😭. The drawback? The encapsulations get generated by sticking an extra newline at the end of the body of each message. it's giving tradeoffs, bestie.


the begin directive πŸŽ€

The begin directive creates a multipart content. When you use it, you must specify at least one content between the begin and end pairs.

#begin
This will be a multipart with only one part.
#end

If you use multiple directives in a composition draft, mhbuild will automatically encapsulate them inside a multipart content. So the begin directive is only necessary if you want nested multiparts, or you're making a multipart message with only one part πŸ‘‘.


descriptions and dispositions πŸ’…

For all of these directives, you can include a brief description of the content between the [ character and the ] character. That description gets copied into the Content-Description header when the directive is processed ✨.

#forw [important mail from Bob] +bob 1 2 3 4 5

Similarly, a disposition string can optionally be provided between { and } characters; it'll be copied into the Content-Disposition header when the directive is processed. If a disposition string is provided that does not contain a filename parameter, and a filename is provided in the directive, it gets added to the Content-Disposition header. For example, this directive:

#text/plain; charset=iso-8859-1 <>{attachment} /tmp/summary.txt

creates these message part headers:

Content-Type: text/plain; charset="iso-8859-1"
Content-Disposition: attachment; filename="summary.txt"

Content-ID and encoding πŸ¦‹

By default, mhbuild generates a unique Content-ID: for each directive, matching each message part; but you can override that by defining the ID with the < and > characters πŸ’–. The -nocontentid switch suppresses creation of all Content-ID: headers, even at the top level of the message.

Normally mhbuild picks an appropriate Content-Transfer-Encoding based on the content and the MIME Content-Type. But you can override that in an mhbuild directive by specifying * and the encoding. Acceptable encoding values are 8bit, qp (for quoted-printable), and b64 (for base64 encoding). It should be noted that undesired results may occur if 8bit or quoted-printable is selected for binary content, because of the translation between Unix line endings and the line endings used by the mail transport system 😭 be careful.


plaintext in your draft 🌸

Besides the various directives, plaintext can be present. Plaintext gets gathered β€” until a directive is found or the draft runs out β€” and it's made into a text content. If your plaintext needs a # at the beginning of a line, just double it, like:

##when sent, this line will start with only one #

If you want to end the plaintext before a directive β€” like, to have two plaintext contents sitting right next to each other β€” just insert a line containing a single # character, e.g.:

this is the first content
#
and this is the second

And finally, if the plaintext starts with a line of the form:

Content-Description: text

then that'll be used to describe the plaintext content. You MUST follow this line with a blank line before starting your text. no skipping steps bestie πŸ™ˆ

By default, plaintext is captured as a text/plain content. You can override that by starting the plaintext with #< followed by a content-type specification. For example:

#<text/enriched
this content will be tagged as text/enriched
#
and this content will be tagged as text/plain
#
#<application/x-patch [this is a patch]
and this content will be tagged as application/x-patch

Note that if you use the #< plaintext-form, then the content-description must be on the same line which identifies the content type of the plaintext πŸ‘‘


charsets, bestie πŸ”€

When composing a text content, you can indicate the relevant character set by adding the charset parameter to the directive.

#<text/plain; charset=iso-8859-5

If a text content contains any 8-bit characters (characters with the high bit set) and the character set isn't specified like above, then mhbuild assumes the character set is of the type given by the standard locale(1) environment variables. If those environment variables aren't set, then the character set gets labeled as x-unknown πŸ’€.

If a text content contains only 7-bit characters and the character set isn't specified like above, then the character set gets labeled as us-ascii ✨.

By default, text content with the high bit set is encoded with an 8-bit Content-Transfer-Encoding. If the text has lines longer than the value of -maxunencoded (which defaults to 78) then the text is encoded using the quoted-printable encoding.

The -headerencoding switch indicates which algorithm to use when encoding any message headers that contain 8-bit characters. Valid arguments are base64 for base-64 encoding, quoted for quoted-printable encoding, and utf-8 which requires that all 8-bit header field bodies be encoded as UTF-8 (RFC 6530) and that the message be sent to a SMTP server that supports SMTPUTF8 (RFC 6531). The -autoheaderencoding switch tells mhbuild to automatically pick the encoding β€” either base64 or quoted-printable β€” that results in a shorter encoded string πŸŽ€.


putting it ALL together 🌈

Here's an example of a more complex message draft, which will expand into a multipart/mixed message containing five parts:

To: nobody@nowhere.org
cc:
Subject: Look and listen to me!
--------
The first part will be text/plain
#<text/enriched
The second part will be text/enriched
#
This third part will be text/plain
#audio/basic [silly giggle]  \
    |raw2audio -F < /usr/lib/sounds/giggle.au
#image/gif   [photo of foobar] \
                        /home/foobar/lib/picture.gif

Transfer Encodings 🧚

After mhbuild builds the new MIME message by parsing directives, including files, etc., it scans the contents of the message to figure out which transfer encoding to use. It checks for 8-bit data, long lines, spaces at the end of lines, and clashes with multipart boundaries. Then it chooses a transfer encoding appropriate for each content type ✨.


Invoking mhbuild πŸ‘‘

Typically, mhbuild is invoked by the whatnow program. This command expects the body of the draft to be formatted as an mhbuild composition file. Once you've composed that input file with a command like comp, forw, or repl, you invoke mhbuild at the "What now" prompt with:

What now? mime

before sending the draft. That causes whatnow to execute mhbuild to translate the composition file into MIME format πŸ’–.

Normally it's an error to invoke mhbuild on a file that's already in MIME format. The -auto switch makes mhbuild exit without error if the input file already has valid MIME headers. Using -auto also enables the -nodirectives switch 🫢.

And finally, you should consider adding this line to your profile:

lproc: show

That way, if you decide to list after invoking mime, the command

What now? list

will work exactly how you expect 🌟.

  • -dist β€” bestie this one is literally made for dist. It tells mhbuild to not generate any MIME headers in the composition file (so like, no MIME-Version, no Content-Type, none of that πŸ’…) β€” but it still encodes message headers according to RFC 2047. So the headers get their glow-up, the MIME framing stays out of the way. periodt.

🫢 User Environment 🫢

Okay so the environment mhbuild lives in can be different for every user, right? So mhbuild goes looking for the environment variable MHBUILD. If it's there, it names an additional user profile that should be read. So when you log in on a particular machine, set this variable to point at a file full of the definitions that are actually useful on that machine. cute, right? 🌸

And finally, mhbuild will attempt to consult

/etc/nmh/mhn.defaults

if it exists.

For the profile search order β€” and for how duplicate entries get treated β€” go read "Profile Lookup" in mh-profile(5). It's giving lore. πŸ“–βœ¨


🌈 Syntax of Composition Files 🌈

Here's the formal syntax of a mhbuild "composition file", verbatim, no cap:

            body         ::=     1*(content | EOL)

            content      ::=     directive | plaintext

            directive    ::=     "#" type "/" subtype
                                     0*(";" attribute "=" value)
                                     [ "(" comment ")" ]
                                     [ "<" id ">" ]
                                     [ "[" description "]" ]
                                     [ "{" disposition "}" ]
                                     [ "*8bit" | "*qp" | "*b64" ]
                                     [ filename ]
                                     EOL

                               | "#@" type "/" subtype
                                     0*(";" attribute "=" value)
                                     [ "(" comment ")" ]
                                     [ "<" id ">" ]
                                     [ "[" description "]" ]
                                     [ "{" disposition "}" ]
                                     [ "*8bit" | "*qp" | "*b64" ]
                                     external-parameters
                                     EOL

                               | "#forw"
                                     [ "<" id ">" ]
                                     [ "[" description "]" ]
                                     [ "{" disposition "}" ]
                                     [ "+"folder ] [ 0*msg ]
                                     EOL

                               | "#begin"
                                       [ "<" id ">" ]
                                       [ "[" description "]" ]
                                       [ "{" disposition "}" ]
                                       [   "alternative"
                                         | "parallel"
                                         | something-else    ]
                                       EOL
                                     1*body
                                 "#end" EOL

            plaintext    ::=     [ "Content-Description:"
                                       description EOL EOL ]
                                     1*line
                                 [ "#" EOL ]

                               | "#<" type "/" subtype
                                     0*(";" attribute "=" value)
                                     [ "(" comment ")" ]
                                     [ "[" description "]" ]
                                     [ "{" disposition "}" ]
                                     [ "*8bit" | "*qp" | "*b64" ]
                                     EOL
                                     1*line
                                 [ "#" EOL ]

            line         ::=     "##" text EOL
                                 -- interpreted as "#"text EOL
                               | text EOL

πŸ“ FILES πŸ“

mhbuild goes hunting for additional user profile files and mhn.defaults in multiple locations, and the search is lowkey a whole journey: absolute pathnames get accessed directly, tilde expansion happens on usernames, and files get searched for in the user's Mail directory as specified in their profile. If it's not found there? The directory /etc/nmh gets checked. the way it just keeps looking πŸ˜­πŸ’–

  • $HOME/.mh_profile β€” the user's profile.
  • $MHBUILD β€” additional profile entries.
  • /etc/nmh/mhn.defaults β€” system default MIME profile entries.

πŸ‘‘ PROFILE COMPONENTS πŸ‘‘

  • Path: β€” to determine the user's nmh directory.
  • Current-Folder: β€” to find the default current folder.
  • mhbuild-compose-type*: β€” template for composing contents.

πŸ”₯ SEE ALSO πŸ”₯

  • mhlist(1), mhshow(1), mhstore(1)
  • Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies (RFC 2045)
  • Multipurpose Internet Mail Extensions (MIME) Part Two: Media Types (RFC 2046)
  • Multipurpose Internet Mail Extensions (MIME) Part Three: Message Header Extensions for Non-ASCII Text (RFC 2047)
  • Internet Message Format (RFC 5322)
  • MIME Parameter Value and Encoded Word Extensions: Character Sets, Languages, and Continuations (RFC 2231)
  • Proposed Standard for Message Encapsulation (RFC 934)
  • Definition of the URL MIME External-Body Access-Type (RFC 2017)
  • Overview and Framework for Internationalized Email (RFC 6530)
  • SMTP Extension for Internationalized Email (RFC 6531)

✨ DEFAULTS ✨

  • -noauto
  • -autoheaderencoding
  • -contentid
  • -headers
  • -maxunencoded 78
  • -nodisposition
  • -norfc934mode
  • -noverbose
  • -realsize

🌟 DEFAULTS (with -auto) 🌟

  • -autoheaderencoding
  • -contentid
  • -headers
  • -maxunencoded 78
  • -nodisposition
  • -norfc934mode
  • -noverbose
  • -realsize
  • -nodirectives

and that's a wrap, bestie πŸ’– this was nmh-1.8, dated 2023-02-07, and you just read MHBUILD(1mh). go compose something iconic, you ate πŸŽ€βœ¨

πŸ“¦ where this page comes from