1MHBUILD(1) General Commands Manual MHBUILD(1)
2
3
4
6 mhbuild - translate MIME composition drafts for nmh messages
7
9 mhbuild [-help] [-version] file [-auto | -noauto] [-list | -nolist]
10 [-realsize | -norealsize] [-headers | -noheaders] [-directives |
11 -nodirectives] [-rfc934mode | -norfc934mode] [-contentid | -nocon‐
12 tentid] [-verbose | -noverbose] [-disposition | -nodisposition]
13 [-check | -nocheck] [-headerencoding encoding-algorithm | -auto‐
14 headerencoding] [-maxunencoded line-length] [-dist]
15
17 The mhbuild command will translate a MIME composition draft into a
18 valid MIME message.
19
20 mhbuild creates multi-media messages as specified in RFCs 2045 through
21 2049. This includes the encoding of message headers as specified by
22 RFC 2047, and, additionally, the encoding of MIME parameters as speci‐
23 fied in RFC 2231.
24
25 If you specify the name of the composition file as “-”, then mhbuild
26 will accept the composition draft on the standard input. If the trans‐
27 lation of this input is successful, mhbuild will output the new MIME
28 message to the standard output. This argument must be the last argu‐
29 ment on the command line.
30
31 Otherwise, if the file argument to mhbuild is the name of a valid com‐
32 position file, and the translation is successful, mhbuild will replace
33 the original file with the new MIME message. It will rename the origi‐
34 nal file to start with the “,” character and end with the string
35 “.orig”, e.g., if you are editing the file “draft”, it will be renamed
36 to “,draft.orig”. This allows you to easily recover the mhbuild input
37 file.
38
39 Listing the Contents
40 The -list switch tells mhbuild to list the table of contents associated
41 with the MIME message that is created.
42
43 The -headers switch indicates that a one-line banner should be dis‐
44 played above the listing. The -realsize switch tells mhbuild to evalu‐
45 ate the “native” (decoded) format of each content prior to listing.
46 This provides an accurate count at the expense of a small delay. If
47 the -verbose switch is present, then the listing will show any “extra”
48 information that is present in the message, such as comments in the
49 “Content-Type” header.
50
51 If the -disposition switch is present, then the listing will show any
52 relevant information from the “Content-Disposition” header.
53
54 Simplified Attachment Interface
55 For users who wish to simply attach files to text content, mhbuild will
56 scan the composition file for “Attach” headers. An “Attach” header
57 contains a filename that will be appended to the message using normal
58 MIME encapsulation rules. One filename is allowed per “Attach” header,
59 but multiple “Attach” headers are allowed per composition file.
60
61 These files will be appended after any other MIME content, including
62 any content specified by mhbuild directives (see below). See send(1)
63 for more details.
64
65 By default, the Content-Disposition will be “attachment”. mhbuild
66 looks for user profile and mhn.defaults entries of the form
67
68 mhbuild-disposition-type/subtype
69 or
70 mhbuild-disposition-type
71
72 to supply the disposition value. The only supported values are
73 “attachment” and “inline”.
74
75 Convert Interface
76 The convert interface is a powerful mechanism that supports replying to
77 MIME messages. These placeholders are used in the following descrip‐
78 tion:
79
80 TYPE content type/subtype
81 CONVERTER external program, and any fixed arguments, to con‐
82 vert content, such as from a request to a reply
83 ARGSTRING arguments to pass from repl to CONVERTER
84 FILE full path of message being replied to
85 The convert support is based on pseudoheaders of the form
86
87 Nmh-mhbuild-file-TYPE: FILE
88 Nmh-mhbuild-args-TYPE: ARGSTRING
89
90 in the draft. For each such pseudoheader, mhbuild looks in the profile
91 and mhn.defaults for the corresponding TYPE entry to find the converter
92 that supports it:
93
94 mhbuild-convert-TYPE: CONVERTER
95
96 It's a fatal error if no such entry is found for TYPE. An empty entry,
97 e.g.,
98
99 mhbuild-convert-text/html:
100
101 excludes parts of that TYPE from the draft.
102
103 The mhn.defaults file contains default mhbuild-convert-text/html and
104 mhbuild-convert-text/plain entries. Profile entries can be used to
105 override corresponding mhn.defaults entries, as usual. Text converters
106 should limit text line lengths to a maximum of 78 characters, and must
107 limit them to a maximum of 998 characters, per RFC 5322 Sec. 2.1.1.
108
109 For each TYPE part in FILE, mhbuild runs CONVERTER ARGSTRING on the
110 content of the part. Each part in FILE that has no corresponding TYPE
111 entry in the profile or mhn.defaults is excluded from the draft; the
112 user can include them using mhbuild directives.
113
114 repl inserts Nmh-mhbuild-text/html: and Nmh-mhbuild-text/plain: pseudo‐
115 headers in every draft. The user can prevent insertion of content
116 parts of either of those types by putting corresponding empty entries
117 in their profile.
118
119 Only the highest precedence alternative with a supported TYPE of a mul‐
120 tipart/alternative part is used.
121
122 mhn.defaults.sh selects the text/html-to-text/plain converter at
123 install time. It includes iconv and par, or fmt, in the pipeline only
124 if they are found.
125
126 Some content types require the addition of parameters to the Content-
127 Type header, such as “method=REPLY” for text/calendar. mhbuild looks
128 for a Content-Type header, followed by a blank line, at the beginning
129 of the converter output. If one is found, it is used for the corre‐
130 sponding part in the reply draft.
131
132 The convert interface doesn't support different ARGSTRINGs or different
133 converters for different parts of the same TYPE. That would require
134 associating parts by part number with the ARGSTRINGs or converters.
135 Instead, that can be done (currently, without using the convert sup‐
136 port), with mhbuild directives as described below, e.g.,
137
138 #text/html; charset=utf-8 *8bit | mhstore -noverbose -part 42.7
139 -outfile - | w3m -dump -cols 64 -T text/html -O utf-8
140
141 The only way to mix convert pseudoheaders and mhbuild directives is to
142 insert the directives before mhbuild is run, which is typically done by
143 entering mime at the “What now?” prompt, or with an -editor mhbuild
144 switch.
145
146 These (optional) setup steps can make the convert support easier to
147 use:
148
149 1) If the par program is installed on your system, it will be set by
150 default (in mhn.defaults) to filter the converter output. It
151 helps to set the PARINIT environment variable, as described in
152 par(1).
153
154 2) Add this line to your profile:
155
156 mhbuild-next: $EDITOR
157
158 assuming that your EDITOR environment variable is set; if not,
159 replace EDITOR with the name of your editor. Without that profile
160 entry, a response of “e[dit]” at the What now? prompt will require
161 specification of your editor if an -editor mhbuild switch is used.
162
163 3) If using repl, source the Bourne-shell compatible functions in
164 /usr/share/doc/nmh/contrib/replaliases.
165 That script also sets the PARINIT environment variable if it was
166 not set.
167
168 Translating the Composition File
169 mhbuild is essentially a filter to aid in the composition of MIME mes‐
170 sages. mhbuild will convert an mhbuild “composition file” into a valid
171 MIME message. An mhbuild “composition file” is just a file containing
172 plain text that is interspersed with various mhbuild directives. When
173 this file is processed by mhbuild, the various directives will be
174 expanded to the appropriate content, and will be encoded according to
175 the MIME standards. The resulting MIME message can then be sent by
176 electronic mail.
177
178 The formal syntax for a mhbuild composition file is defined at the end
179 of this document, but the ideas behind this format are not complex.
180 Basically, the body contains one or more contents. A content consists
181 of either a directive, indicated with a “#” as the first character of a
182 line; or, plaintext (one or more lines of text). The continuation
183 character, “\“, may be used to enter a single directive on more than
184 one line, e.g.,
185
186 #image/png \
187 /home/foobar/junk/picture.png
188
189 There are five kinds of directives: “type” directives, which name the
190 type and subtype of the content; “external-type” directives, which also
191 name the type and subtype of the content; the “message” directive
192 (#forw), which is used to forward one or more messages; the “begin”
193 directive (#begin), which is used to create a multipart content; and
194 the “on/off/pop” directives (#on, #off, #pop) which control whether any
195 other directives are honored at all.
196
197 The -directives switch allows control over whether mhbuild will honor
198 any of the “#”-directives. This can also be affected with the #on or
199 #off directives, and #pop, which restores the state of processing to
200 that preceding the most recent #on or #off. (The #on, #off, and #pop
201 directives are always honored, of course.) This allows inclusion of
202 plain text which looks like mhbuild directives, without causing errors:
203
204 #off
205 #include <stdio.h>
206 printf("Hello, World!");
207 #pop
208
209 Currently the stack depth for the #on/off/pop directives is 32.
210
211 The “type” directive is used to directly specify the type and subtype
212 of a content. You may only specify discrete types in this manner
213 (can't specify the types multipart or message with this directive).
214 You may optionally specify the name of a file containing the contents
215 in “native” (decoded) format. If this filename starts with the “|”
216 character, then it represents a command to execute whose output is cap‐
217 tured accordingly. For example,
218
219 #audio/basic |raw2audio -F < /usr/lib/sound/giggle.au
220
221 If a filename is not given, mhbuild will look for information in the
222 user's profile to determine how the different contents should be com‐
223 posed. This is accomplished by consulting a composition string, and
224 executing it under /bin/sh, with the standard output set to the con‐
225 tent. If the -verbose switch is given, mhbuild will echo any commands
226 that are used to create contents in this way.
227
228 The composition string may contain the following escapes:
229
230 %a Insert parameters from directive
231 %f Insert filename containing content
232 %F %f, and stdout is not re-directed
233 %s Insert content subtype
234 %% Insert character %
235
236 First, mhbuild will look for an entry of the form:
237
238 mhbuild-compose-type/subtype
239
240 to determine the command to use to compose the content. If this isn't
241 found, mhbuild will look for an entry of the form:
242
243 mhbuild-compose-type
244
245 to determine the composition command. If this isn't found, mhbuild
246 will complain.
247
248 An example entry might be:
249
250 mhbuild-compose-audio/basic: record | raw2audio -F
251
252 Because commands like these will vary, depending on the display envi‐
253 ronment used for login, composition strings for different contents
254 should probably be put in the file specified by the MHBUILD environment
255 variable, instead of directly in your user profile.
256
257 The “external-type” directives are used to provide a MIME reference to
258 a content, rather than enclosing the contents itself (for instance, by
259 specifying an ftp site). Hence, instead of providing a filename as
260 with the type directives, external-parameters are supplied. These look
261 like regular parameters, so they must be separated accordingly. For
262 example,
263
264 #@application/octet-stream; \
265 type=tar; \
266 conversions=compress \
267 [this is the nmh distribution] \
268 {attachment; filename="nmh.tar.gz"} \
269 name="nmh.tar.gz"; \
270 directory="/pub/nmh"; \
271 site="ftp.math.gatech.edu"; \
272 access-type=anon-ftp; \
273 mode="image"
274
275 You must give a description string to separate the content parameters
276 from the external-parameters (although this string may be empty). This
277 description string is specified by enclosing it within “[]”. A dispo‐
278 sition string, to appear in a “Content-Disposition” header, may appear
279 in the optional “{}”.
280
281 These parameters are of the form:
282
283 access-type= usually “anon-ftp”, “mail-server”, or “url”
284 name= filename
285 permission= read-only or read-write
286 site= hostname
287 directory= directoryname (optional)
288 mode= usually “ascii” or “image” (optional)
289 size= number of octets
290 server= mailbox
291 subject= subject to send
292 body= command to send for retrieval
293 url= URL of content
294
295 A minimum “external-type” directive for the url access-type would be as
296 follows:
297
298 #@application/octet-stream [] access-type=url; \
299 url="http://download.savannah.gnu.org/releases/nmh/nmh-1.5.tar.gz"
300
301 Any long URLs will be wrapped according to RFC 2231 rules.
302
303 The “message” directive (#forw) is used to specify a message or group
304 of messages to include. You may optionally specify the name of the
305 folder and which messages are to be forwarded. If a folder is not
306 given, it defaults to the current folder. Similarly, if a message is
307 not given, it defaults to the current message. Hence, the message
308 directive is similar to the forw command, except that the former uses
309 the MIME rules for encapsulation rather than those specified in RFC
310 934. For example,
311
312 #forw +inbox 42 43 99
313
314 If you include a single message, it will be included directly as a con‐
315 tent of type “message/rfc822”. If you include more than one message,
316 then mhbuild will add a content of type “multipart/digest” and include
317 each message as a subpart of this content.
318
319 If you are using this directive to include more than one message, you
320 may use the -rfc934mode switch. This switch will indicate that mhbuild
321 should attempt to utilize the MIME encapsulation rules in such a way
322 that the “multipart/digest” that is created is (mostly) compatible with
323 the encapsulation specified in RFC 934. If given, then RFC 934 compli‐
324 ant user-agents should be able to burst the message on recep‐
325 tion -- providing that the messages being encapsulated do not contain
326 encapsulated messages themselves. The drawback of this approach is
327 that the encapsulations are generated by placing an extra newline at
328 the end of the body of each message.
329
330 The “begin” directive is used to create a multipart content. When
331 using the “begin” directive, you must specify at least one content
332 between the begin and end pairs.
333
334 #begin
335 This will be a multipart with only one part.
336 #end
337
338 If you use multiple directives in a composition draft, mhbuild will
339 automatically encapsulate them inside a multipart content. Therefore
340 the “begin” directive is only necessary if you wish to use nested mul‐
341 tiparts, or create a multipart message containing only one part.
342
343 For all of these directives, the user may include a brief description
344 of the content between the “[” character and the “]” character. This
345 description will be copied into the “Content-Description” header when
346 the directive is processed.
347
348 #forw [important mail from Bob] +bob 1 2 3 4 5
349
350 Similarly, a disposition string may optionally be provided between “{”
351 and “}” characters; it will be copied into the “Content-Disposition”
352 header when the directive is processed. If a disposition string is
353 provided that does not contain a filename parameter, and a filename is
354 provided in the directive, it will be added to the “Content-Disposi‐
355 tion” header. For example, the following directive:
356
357 #text/plain; charset=iso-8859-1 <>{attachment} /tmp/summary.txt
358
359 creates these message part headers:
360
361 Content-Type: text/plain; charset="iso-8859-1"
362 Content-Disposition: attachment; filename="summary.txt"
363
364 By default, mhbuild will generate a unique “Content-ID:” for each
365 directive, corresponding to each message part; however, the user may
366 override this by defining the ID using the “<” and “>” characters. The
367 -nocontentid switch suppresses creation of all “Content-ID:” headers,
368 even in the top level of the message.
369
370 Normally mhbuild will choose an appropriate Content-Transfer-Encoding
371 based on the content and the MIME Content-Type. However, you can over‐
372 ride that in an mhbuild directive by specifying “*” and the encoding.
373 Acceptable encoding values are “8bit”, “qp” (for quoted-printable), and
374 “b64” (for base64 encoding). It should be noted that undesired results
375 may occur if 8bit or quoted-printable is selected for binary content,
376 due to the translation between Unix line endings and the line endings
377 use by the mail transport system.
378
379 In addition to the various directives, plaintext can be present.
380 Plaintext is gathered, until a directive is found or the draft is
381 exhausted, and this is made to form a text content. If the plaintext
382 must contain a “#” at the beginning of a line, simply double it, e.g.,
383
384 ##when sent, this line will start with only one #
385
386 If you want to end the plaintext prior to a directive, e.g., to have
387 two plaintext contents adjacent, simply insert a line containing a sin‐
388 gle “#” character, e.g.,
389
390 this is the first content
391 #
392 and this is the second
393
394 Finally, if the plaintext starts with a line of the form:
395
396 Content-Description: text
397
398 then this will be used to describe the plaintext content. You MUST
399 follow this line with a blank line before starting your text.
400
401 By default, plaintext is captured as a text/plain content. You can
402 override this by starting the plaintext with “#<” followed by a con‐
403 tent-type specification. For example, e.g.,
404
405 #<text/enriched
406 this content will be tagged as text/enriched
407 #
408 and this content will be tagged as text/plain
409 #
410 #<application/x-patch [this is a patch]
411 and this content will be tagged as application/x-patch
412
413 Note that if you use the “#<” plaintext-form, then the content-descrip‐
414 tion must be on the same line which identifies the content type of the
415 plaintext.
416
417 When composing a text content, you may indicate the relevant character
418 set by adding the “charset” parameter to the directive.
419
420 #<text/plain; charset=iso-8859-5
421
422 If a text content contains any 8-bit characters (characters with the
423 high bit set) and the character set is not specified as above, then
424 mhbuild will assume the character set is of the type given by the stan‐
425 dard locale(1) environment variables. If these environment variables
426 are not set, then the character set will be labeled as “x-unknown”.
427
428 If a text content contains only 7-bit characters and the character set
429 is not specified as above, then the character set will be labeled as
430 “us-ascii”.
431
432 By default text content with the high bit set is encoded with an 8-bit
433 Content-Transfer-Encoding. If the text has lines longer than the value
434 of -maxunencoded (which defaults to 78) then the text is encoded using
435 the quoted-printable encoding.
436
437 The -headerencoding switch will indicate which algorithm to use when
438 encoding any message headers that contain 8-bit characters. The valid
439 arguments are base64 for base-64 encoding, quoted for quoted-printable
440 encoding, and utf-8 which requires that all 8-bit header field bodies
441 be encoded as UTF-8 (RFC 6530) and that the message be sent to a SMTP
442 server that supports SMTPUTF8 (RFC 6531). The -autoheaderencoding
443 switch instructs mhbuild to automatically pick the encoding, either
444 base64 or quoted-printable, that results in a shorter encoded string.
445
446 Putting this all together, here is an example of a more complex message
447 draft, which will expand into a multipart/mixed message containing five
448 parts:
449
450 To: nobody@nowhere.org
451 cc:
452 Subject: Look and listen to me!
453 --------
454 The first part will be text/plain
455 #<text/enriched
456 The second part will be text/enriched
457 #
458 This third part will be text/plain
459 #audio/basic [silly giggle] \
460 |raw2audio -F < /usr/lib/sounds/giggle.au
461 #image/gif [photo of foobar] \
462 /home/foobar/lib/picture.gif
463
464 Integrity Check
465 If mhbuild is given the -check switch, then it will also associate an
466 integrity check with each “leaf” content. This will add a Content-MD5
467 header field to the content, along with the md5 sum of the unencoded
468 contents, per RFC 1864. This may be used by the receiver of the mes‐
469 sage to verify that the contents of the message were not changed in
470 transport.
471
472 Transfer Encodings
473 After mhbuild constructs the new MIME message by parsing directives,
474 including files, etc., it scans the contents of the message to deter‐
475 mine which transfer encoding to use. It will check for 8-bit data,
476 long lines, spaces at the end of lines, and clashes with multipart
477 boundaries. It will then choose a transfer encoding appropriate for
478 each content type.
479
480 If an integrity check is being associated with each content by using
481 the -check switch, then mhbuild will encode each content with a trans‐
482 fer encoding, even if the content contains only 7-bit data. This is to
483 increase the likelihood that the content is not changed while in trans‐
484 port.
485
486 Invoking mhbuild
487 Typically, mhbuild is invoked by the whatnow program. This command
488 will expect the body of the draft to be formatted as an mhbuild compo‐
489 sition file. Once you have composed this input file using a command
490 such as comp, forw, or repl, you invoke mhbuild at the “What now”
491 prompt with
492
493 What now? mime
494
495 prior to sending the draft. This will cause whatnow to execute mhbuild
496 to translate the composition file into MIME format.
497
498 Normally it is an error to invoke mhbuild on a file that is already in
499 MIME format. The -auto switch will cause mhbuild to exit without error
500 if the input file already has valid MIME headers. The use of -auto
501 also enables the -nodirectives switch.
502
503 Finally, you should consider adding this line to your profile:
504
505 lproc: show
506
507 This way, if you decide to list after invoking mime, the command
508
509 What now? list
510
511 will work as you expect.
512
513 The -dist switch is intended to be used by dist. It will cause mhbuild
514 to not generate any MIME headers in the composition file (such as
515 “MIME-Version” or “Content-Type”), but it will still encode message
516 headers according to RFC 2047.
517
518 User Environment
519 Because the environment in which mhbuild operates may vary for a user,
520 mhbuild will look for the environment variable MHBUILD. If present,
521 this specifies the name of an additional user profile which should be
522 read. Hence, when a user logs in on a particular machine, this envi‐
523 ronment variable should be set to refer to a file containing defini‐
524 tions useful on that machine.
525
526 Finally, mhbuild will attempt to consult
527
528 /etc/nmh/mhn.defaults
529
530 if it exists.
531
532 See "Profile Lookup" in mh-profile(5) for the profile search order, and
533 for how duplicate entries are treated.
534
535 Syntax of Composition Files
536 The following is the formal syntax of a mhbuild “composition file”.
537
538 body ::= 1*(content | EOL)
539
540 content ::= directive | plaintext
541
542 directive ::= "#" type "/" subtype
543 0*(";" attribute "=" value)
544 [ "(" comment ")" ]
545 [ "<" id ">" ]
546 [ "[" description "]" ]
547 [ "{" disposition "}" ]
548 [ "*8bit" | "*qp" | "*b64" ]
549 [ filename ]
550 EOL
551
552 | "#@" type "/" subtype
553 0*(";" attribute "=" value)
554 [ "(" comment ")" ]
555 [ "<" id ">" ]
556 [ "[" description "]" ]
557 [ "{" disposition "}" ]
558 [ "*8bit" | "*qp" | "*b64" ]
559 external-parameters
560 EOL
561
562 | "#forw"
563 [ "<" id ">" ]
564 [ "[" description "]" ]
565 [ "{" disposition "}" ]
566 [ "+"folder ] [ 0*msg ]
567 EOL
568
569 | "#begin"
570 [ "<" id ">" ]
571 [ "[" description "]" ]
572 [ "{" disposition "}" ]
573 [ "alternative"
574 | "parallel"
575 | something-else ]
576 EOL
577 1*body
578 "#end" EOL
579
580 plaintext ::= [ "Content-Description:"
581 description EOL EOL ]
582 1*line
583 [ "#" EOL ]
584
585 | "#<" type "/" subtype
586 0*(";" attribute "=" value)
587 [ "(" comment ")" ]
588 [ "[" description "]" ]
589 [ "{" disposition "}" ]
590 [ "*8bit" | "*qp" | "*b64" ]
591 EOL
592 1*line
593 [ "#" EOL ]
594
595 line ::= "##" text EOL
596 -- interpreted as "#"text EOL
597 | text EOL
598
600 mhbuild looks for additional user profile files and mhn.defaults in
601 multiple locations: absolute pathnames are accessed directly, tilde
602 expansion is done on usernames, and files are searched for in the
603 user's Mail directory as specified in their profile. If not found
604 there, the directory “/etc/nmh” is checked.
605
606 $HOME/.mh_profile The user's profile.
607 $MHBUILD Additional profile entries.
608 /etc/nmh/mhn.defaults
609 System default MIME profile entries.
610
612 Path: To determine the user's nmh directory.
613 Current-Folder: To find the default current folder.
614 mhbuild-compose-type*:
615 Template for composing contents.
616
618 mhlist(1), mhshow(1), mhstore(1)
619
620 Multipurpose Internet Mail Extensions (MIME) Part One: Format of Inter‐
621 net Message Bodies (RFC 2045)
622
623 Multipurpose Internet Mail Extensions (MIME) Part Two: Media Types (RFC
624 2046)
625
626 Multipurpose Internet Mail Extensions (MIME) Part Three: Message Header
627 Extensions for Non-ASCII Text (RFC 2047)
628
629 Internet Message Format (RFC 5322)
630
631 MIME Parameter Value and Encoded Word Extensions: Character Sets, Lan‐
632 guages, and Continuations (RFC 2231)
633
634 Proposed Standard for Message Encapsulation (RFC 934)
635
636 The Content-MD5 Header Field (RFC 1864)
637
638 Definition of the URL MIME External-Body Access-Type (RFC 2017)
639
640 Overview and Framework for Internationalized Email (RFC 6530)
641
642 SMTP Extension for Internationalized Email (RFC 6531)
643
645 -autoheaderencoding
646 -contentid
647 -headers
648 -maxunencoded 78
649 -nocheck
650 -nodisposition
651 -norfc934mode
652 -noverbose
653 -realsize
654
655
656
657nmh-1.7.1 2016-10-15 MHBUILD(1)