]> diplodocus.org Git - nmh/blob - man/mhbuild.man
Garbage collect unused code.
[nmh] / man / mhbuild.man
1 .TH MHBUILD %manext1% "March 21, 2013" "%nmhversion%"
2 .\"
3 .\" %nmhwarning%
4 .\"
5 .SH NAME
6 mhbuild \- translate MIME composition draft
7 .SH SYNOPSIS
8 .na
9 .HP 5
10 .B mhbuild
11 .I file
12 .RB [ \-auto " | " \-noauto ]
13 .RB [ \-list " | " \-nolist ]
14 .RB [ \-realsize " | " \-norealsize ]
15 .RB [ \-headers " | " \-noheaders ]
16 .RB [ \-directives " | " \-nodirectives ]
17 .RB [ \-rfc934mode " | " \-norfc934mode ]
18 .RB [ \-contentid " | " \-nocontentid ]
19 .RB [ \-verbose " | " \-noverbose ]
20 .RB [ \-check " | " \-nocheck ]
21 .RB [ \-headerencoding
22 .IR encoding\-algorithm
23 .RB " | " \-autoheaderencoding ]
24 .RB [ \-dist ]
25 .RB [ \-version ]
26 .RB [ \-help ]
27 .ad
28 .SH DESCRIPTION
29 The
30 .B mhbuild
31 command will translate a MIME composition draft into
32 a valid MIME message.
33 .PP
34 .B mhbuild
35 creates multi-media messages as specified in RFC 2045
36 to RFC 2049. This includes the encoding of message headers as specified
37 by RFC 2047.
38 .PP
39 If you specify the name of the composition file as \*(lq-\*(rq,
40 then
41 .B mhbuild
42 will accept the composition draft on the standard
43 input. If the translation of this input is successful,
44 .B mhbuild
45 will output the new MIME message to the standard output. This argument
46 must be the last argument on the command line.
47 .PP
48 Otherwise if the file argument to
49 .B mhbuild
50 is the name of a valid
51 composition file, and the translation is successful,
52 .B mhbuild
53 will replace the original file with the new MIME message. It will rename
54 the original file to start with the \*(lq,\*(rq character and end with the
55 string \*(lq.orig\*(rq, e.g., if you are editing the file \*(lqdraft\*(rq,
56 it will be renamed to \*(lq,draft.orig\*(rq. This allows you to easily
57 recover the
58 .B mhbuild
59 input file.
60 .SS "Listing the Contents"
61 The
62 .B \-list
63 switch tells
64 .B mhbuild
65 to list the table of contents associated with the MIME message that is created.
66 .PP
67 The
68 .B \-headers
69 switch indicates
70 that a one-line banner should be displayed above the listing. The
71 .B \-realsize
72 switch tells
73 .B mhbuild
74 to evaluate the \*(lqnative\*(rq
75 (decoded) format of each content prior to listing. This provides an
76 accurate count at the expense of a small delay. If the
77 .B \-verbose
78 switch
79 is present, then the listing will show any \*(lqextra\*(rq information
80 that is present in the message, such as comments in the
81 \*(lqContent-Type\*(rq header.
82 .SS "Translating the Composition File"
83 .B mhbuild
84 is essentially a filter to aid in the composition of MIME
85 messages.
86 .B mhbuild
87 will convert an
88 .B mhbuild
89 \*(lqcomposition file\*(rq
90 into a valid MIME message. A
91 .B mhbuild
92 \*(lqcomposition file\*(rq
93 is just a file containing plain text that is interspersed
94 with various
95 .B mhbuild
96 directives. When this file is processed
97 by
98 .BR mhbuild ,
99 the various directives will be expanded to the
100 appropriate content, and will be encoded according to the MIME standards.
101 The resulting MIME message can then be sent by electronic mail.
102 .PP
103 The formal syntax for a
104 .B mhbuild
105 composition file is defined at the
106 end of this document, but the ideas behind this format are not complex.
107 Basically, the body contains one or more contents. A content consists of
108 either a directive, indicated with a \*(lq#\*(rq as the first character
109 of a line; or, plaintext (one or more lines of text). The continuation
110 character, \*(lq\\\*(lq, may be used to enter a single directive on more
111 than one line, e.g.,
112 .PP
113 .RS 5
114 .nf
115 #image/png \\
116 /home/foobar/junk/picture.png
117 .fi
118 .RE
119 .PP
120 There are five kinds of directives: \*(lqtype\*(rq directives, which
121 name the type and subtype of the content; \*(lqexternal-type\*(rq
122 directives, which also name the type and subtype of the content; the
123 \*(lqmessage\*(rq directive (#forw), which is used to forward one or
124 more messages; the \*(lqbegin\*(rq directive (#begin), which is
125 used to create a multipart content; and the \*(lqon/off/pop\*(rq
126 directives (#on, #off, #pop) which control whether any other
127 directives are honored at all.
128 .PP
129 The
130 .B \-directives
131 switch allows control over whether mhbuild will honor any of the
132 \*(lq#\*(rq-directives. This can also be affected with the #on or
133 #off directives, and #pop, which restores the state of processing to
134 that preceding the most recent #on or #off. (The #on, #off, and #pop
135 directives are always honored, of course.) This allows inclusion of
136 plain text which looks like mhbuild directives, without causing
137 errors:
138 .PP
139 .RS 5
140 .nf
141 #off
142 #include <stdio.h>
143 printf("Hello, World!);
144 #pop
145 .fi
146 .RE
147 .PP
148 Currently the stack depth for the #on/off/pop directives is 32.
149 .PP
150 The \*(lqtype\*(rq directive is used to directly specify the type and
151 subtype of a content. You may only specify discrete types in this manner
152 (can't specify the types multipart or message with this directive).
153 You may optionally specify the name of a file containing the contents
154 in \*(lqnative\*(rq (decoded) format. If this filename starts with the
155 \*(lq|\*(rq character, then it represents a command to execute whose
156 output is captured accordingly.
157 For example,
158 .PP
159 .RS 5
160 .nf
161 #audio/basic |raw2audio -F < /usr/lib/sound/giggle.au
162 .fi
163 .RE
164 .PP
165 If a filename is not given,
166 .B mhbuild
167 will look for information in the
168 user's profile to determine how the different contents should be composed.
169 This is accomplished by consulting a composition string, and executing
170 it under
171 .BR /bin/sh ,
172 with the standard output set to the content.
173 If the
174 .B \-verbose
175 switch is given,
176 .B mhbuild
177 will echo any commands that are used to create contents in this way.
178 .PP
179 The composition string may contain the following escapes:
180 .PP
181 .RS 5
182 .nf
183 .ta \w'%P 'u
184 %a Insert parameters from directive
185 %f Insert filename containing content
186 %F %f, and stdout is not re-directed
187 %s Insert content subtype
188 %% Insert character %
189 .fi
190 .RE
191 .PP
192 First,
193 .B mhbuild
194 will look for an entry of the form:
195 .PP
196 .RS 5
197 mhbuild-compose-<type>/<subtype>
198 .RE
199 .PP
200 to determine the command to use to compose the content. If this isn't
201 found,
202 .B mhbuild
203 will look for an entry of the form:
204 .PP
205 .RS 5
206 mhbuild-compose-<type>
207 .RE
208 .PP
209 to determine the composition command. If this isn't found,
210 .B mhbuild
211 will complain.
212 .PP
213 An example entry might be:
214 .PP
215 .RS 5
216 mhbuild-compose-audio/basic: record | raw2audio -F
217 .RE
218 .PP
219 Because commands like these will vary, depending on the display
220 environment used for login, composition strings for different
221 contents should probably be put in the file specified by the
222 .B $MHBUILD
223 environment variable, instead of directly in your
224 user profile.
225 .PP
226 The \*(lqexternal-type\*(rq directives are used to provide a MIME
227 reference to a content, rather than enclosing the contents itself
228 (for instance, by specifying an ftp site). Hence, instead of
229 providing a filename as with the type directives, external-parameters
230 are supplied. These look like regular parameters, so they must be
231 separated accordingly. For example,
232 .PP
233 .RS 5
234 .nf
235 #@application/octet-stream; \\
236 type=tar; \\
237 conversions=compress \\
238 [this is the nmh distribution] \\
239 {attachment; filename="nmh.tar.gz"} \\
240 name="nmh.tar.gz"; \\
241 directory="/pub/nmh"; \\
242 site="ftp.math.gatech.edu"; \\
243 access-type=anon-ftp; \\
244 mode="image"
245 .fi
246 .RE
247 .PP
248 You must give a description string to separate the content parameters
249 from the external-parameters (although this string may be empty).
250 This description string is specified by enclosing it within
251 \*(lq[]\*(rq. A disposition string, to appear in a
252 \*(lqContent-Disposition\*(rq header, may appear in the optional
253 \*(lq{}\*(rq.
254 .PP
255 These parameters are of the form:
256 .PP
257 .RS 5
258 .nf
259 .ta \w'access-type= 'u
260 access-type= usually \fIanon-ftp\fR, \fImail-server\fR, or \fIurl\fR
261 name= filename
262 permission= read-only or read-write
263 site= hostname
264 directory= directoryname (optional)
265 mode= usually \fIascii\fR or \fIimage\fR (optional)
266 size= number of octets
267 server= mailbox
268 subject= subject to send
269 body= command to send for retrieval
270 url= URL of content
271 .fi
272 .RE
273 .PP
274 A mimimum \*(lqexternal\-type\*(rq directive for the
275 .B url
276 .I access\-type
277 would be as follows:
278 .PP
279 .RS 3
280 .nf
281 #@application/octet-stream [] access-type=url; \\
282 url="http://download.savannah.gnu.org/releases/nmh/nmh-1.5.tar.gz"
283 .fi
284 .RE
285 .PP
286 Any long URLs will be wrapped according to RFC 2017 rules.
287 .PP
288 The \*(lqmessage\*(rq directive (#forw) is used to specify a message or
289 group of messages to include. You may optionally specify the name of
290 the folder and which messages are to be forwarded. If a folder is not
291 given, it defaults to the current folder. Similarly, if a message is not
292 given, it defaults to the current message. Hence, the message directive
293 is similar to the
294 .B forw
295 command, except that the former uses
296 the MIME rules for encapsulation rather than those specified in RFC 934.
297 For example,
298 .PP
299 .RS 5
300 .nf
301 #forw +inbox 42 43 99
302 .fi
303 .RE
304 .PP
305 If you include a single message, it will be included directly as a content
306 of type \*(lqmessage/rfc822\*(rq. If you include more than one message,
307 then
308 .B mhbuild
309 will add a content of type \*(lqmultipart/digest\*(rq
310 and include each message as a subpart of this content.
311 .PP
312 If you are using this directive to include more than one message, you
313 may use the
314 .B \-rfc934mode
315 switch. This switch will indicate that
316 .B mhbuild
317 should attempt to utilize the MIME encapsulation rules
318 in such a way that the \*(lqmultipart/digest\*(rq that is created
319 is (mostly) compatible with the encapsulation specified in RFC 934.
320 If given, then RFC 934 compliant user-agents should be able to burst the
321 message on reception\0--\0providing that the messages being encapsulated
322 do not contain encapsulated messages themselves. The drawback of this
323 approach is that the encapsulations are generated by placing an extra
324 newline at the end of the body of each message.
325 .PP
326 The \*(lqbegin\*(rq directive is used to create a multipart content.
327 When using the \*(lqbegin\*(rq directive, you must specify at least one
328 content between the begin and end pairs.
329 .PP
330 .RS 5
331 .nf
332 #begin
333 This will be a multipart with only one part.
334 #end
335 .fi
336 .RE
337 .PP
338 If you use multiple directives in a composition draft,
339 .B mhbuild
340 will
341 automatically encapsulate them inside a multipart content. Therefore the
342 \*(lqbegin\*(rq directive is only necessary if you wish to use nested
343 multiparts, or create a multipart message containing only one part.
344 .PP
345 For all of these directives, the user may include a brief description
346 of the content between the \*(lq[\*(rq character and the \*(lq]\*(rq
347 character. This description will be copied into the
348 \*(lqContent-Description\*(rq header when the directive is processed.
349 .PP
350 .RS 5
351 .nf
352 #forw [important mail from Bob] +bob 1 2 3 4 5
353 .fi
354 .RE
355 .PP
356 Similarly, a disposition string may optionally be provided between
357 \*(lq{\*(rq and \*(lq}\*(rq characters; it will be copied into the
358 \*(lqContent-Disposition\*(rq header when the directive is processed.
359 If a disposition string is provided that does not contain a filename
360 parameter, and a filename is provided in the directive, it will be
361 added to the \*(lqContent-Disposition\*(rq header. For example, the
362 following directive:
363 .PP
364 .RS 5
365 .nf
366 #text/plain; charset=iso-8859-1 <>{attachment} /tmp/summary.txt
367 .fi
368 .RE
369 .PP
370 creates these message part headers:
371 .PP
372 .RS 5
373 .nf
374 Content-Type: text/plain; charset="iso-8859-1"
375 Content-Disposition: attachment; filename="summary.txt"
376 .fi
377 .RE
378 .PP
379 By default,
380 .B mhbuild
381 will generate a unique \*(lqContent-ID:\*(rq for each directive,
382 corresponding to each message part; however, the user may override
383 this by defining the ID using the \*(lq<\*(rq and \*(lq>\*(rq
384 characters. The
385 .B \-nocontentid
386 switch suppresses creation of all \*(lqContent-ID:\*(rq headers,
387 even in the top level of the message.
388 .PP
389 In addition to the various directives, plaintext can be present.
390 Plaintext is gathered, until a directive is found or the draft is
391 exhausted, and this is made to form a text content. If the plaintext
392 must contain a \*(lq#\*(rq at the beginning of a line, simply double it,
393 e.g.,
394 .PP
395 .RS 5
396 ##when sent, this line will start with only one #
397 .RE
398 .PP
399 If you want to end the plaintext prior to a directive, e.g., to have two
400 plaintext contents adjacent, simply insert a line containing a single
401 \*(lq#\*(rq character, e.g.,
402 .PP
403 .RS 5
404 .nf
405 this is the first content
406 #
407 and this is the second
408 .fi
409 .RE
410 .PP
411 Finally, if the plaintext starts with a line of the form:
412 .PP
413 .RS 5
414 Content-Description: text
415 .RE
416 .PP
417 then this will be used to describe the plaintext content.
418 You MUST follow this line with a blank line before starting
419 your text.
420 .PP
421 By default, plaintext is captured as a text/plain content. You can
422 override this by starting the plaintext with \*(lq#<\*(rq followed by
423 a content-type specification. For example, e.g.,
424 .PP
425 .RS 5
426 .nf
427 #<text/enriched
428 this content will be tagged as text/enriched
429 #
430 and this content will be tagged as text/plain
431 #
432 #<application/x-patch [this is a patch]
433 and this content will be tagged as application/x-patch
434 .fi
435 .RE
436 .PP
437 Note that if you use the \*(lq#<\*(rq plaintext-form, then the
438 content-description must be on the same line which identifies the content
439 type of the plaintext.
440 .PP
441 When composing a text content, you may indicate the relevant character
442 set by adding the \*(lqcharset\*(rq parameter to the directive.
443 .PP
444 .RS 5
445 #<text/plain; charset=iso-8859-5
446 .RE
447 .PP
448 If a text content contains any 8\-bit characters (characters with the
449 high bit set) and the character set is not specified as above, then
450 .B mhbuild
451 will assume the character set is of the type given by the
452 environment variable MM_CHARSET. If this environment variable is not
453 set, then the character set will be labeled as \*(lqx-unknown\*(rq.
454 .PP
455 If a text content contains only 7\-bit characters and the character set
456 is not specified as above, then the character set will be labeled as
457 \*(lqus-ascii\*(rq.
458 .PP
459 The
460 .B \-headerencoding
461 switch will indicate which algorithm to use when encoding any message headers
462 that contain 8\-bit characters. The valid arguments are
463 .I base64
464 for based\-64 encoding and
465 .I quoted
466 for quoted\-printable encoding. The
467 .B \-autoheaderencoding
468 switch will instruct
469 .B mhbuild
470 to automatically pick the algorithm that results in a shorter encoded string.
471 .PP
472 Putting this all together,
473 here is an example of a more complicated message draft. The
474 following draft will expand into a multipart/mixed message
475 containing five parts:
476 .PP
477 .RS 5
478 .nf
479 To: nobody@nowhere.org
480 cc:
481 Subject: Look and listen to me!
482 --------
483 The first part will be text/plain
484 #<text/enriched
485 The second part will be text/enriched
486 #
487 This third part will be text/plain
488 #audio/basic [silly giggle] \\
489 |raw2audio -F < /usr/lib/sounds/giggle.au
490 #image/gif [photo of foobar] \\
491 /home/foobar/lib/picture.gif
492 .fi
493 .RE
494 .SS "Integrity Check"
495 If
496 .B mhbuild
497 is given the
498 .B \-check
499 switch, then it will also associate an integrity check with each
500 \*(lqleaf\*(rq content. This will add a Content-MD5 header field to
501 the content, along with the md5 sum of the unencoded contents, per RFC
502 1864. This may be used by the receiver of the message to verify that
503 the contents of the message were not changed in transport.
504 .SS "Transfer Encodings"
505 After
506 .B mhbuild
507 constructs the new MIME message by parsing directives,
508 including files, etc., it scans the contents of the message to determine
509 which transfer encoding to use. It will check for 8bit data, long lines,
510 spaces at the end of lines, and clashes with multipart boundaries. It will
511 then choose a transfer encoding appropriate for each content type.
512 .PP
513 If an integrity check is being associated with each content by using
514 the
515 .B \-check
516 switch, then
517 .B mhbuild
518 will encode each content with
519 a transfer encoding, even it the content contains only 7\-bit data. This
520 is to increase the likelihood that the content is not changed while in
521 transport.
522 .SS "Invoking mhbuild"
523 Typically,
524 .B mhbuild
525 is invoked by the
526 .B whatnow
527 program. This
528 command will expect the body of the draft to be formatted as an
529 .B mhbuild
530 composition file. Once you have composed this input file
531 using a command such as
532 .BR comp ,
533 .BR repl ,
534 or
535 .BR forw ,
536 you invoke
537 .B mhbuild
538 at the \*(lqWhat now\*(rq prompt with
539 .PP
540 .RS 5
541 What now? mime
542 .RE
543 .PP
544 prior to sending the draft. This will cause
545 .B whatnow
546 to execute
547 .B mhbuild
548 to translate the composition file into MIME format.
549 .PP
550 Normally it is an error to invoke
551 .B mhbuild
552 on file that already in MIME format. The
553 .B \-auto
554 switch will cause
555 .B mhbuild
556 to exit without error if the input file already has valid MIME headers.
557 .PP
558 Finally, you should consider adding this line to your profile:
559 .PP
560 .RS 5
561 lproc: show
562 .RE
563 .PP
564 This way, if you decide to
565 .B list
566 after invoking
567 .BR mime ,
568 the command
569 .PP
570 .RS 5
571 What now? list
572 .RE
573 .PP
574 will work as you expect.
575 .PP
576 The
577 .B \-dist
578 switch is intended to be used by
579 .BR dist .
580 It will cause mhbuild to not generate any MIME headers in the composition
581 file (such as \*(lqMIME-Version\*(rq or \*(lqContent-Type\*(rq), but it
582 will still encode message headers according to RFC 2047.
583 .SS "User Environment"
584 Because the environment in which
585 .B mhbuild
586 operates may vary for a
587 user,
588 .B mhbuild
589 will look for the environment variable
590 .BR $MHBUILD .
591 If present, this specifies the name of an additional user profile which
592 should be read. Hence, when a user logs in on a particular machine,
593 this environment variable should be set to refer to a file containing
594 definitions useful for that machine.
595 .PP
596 Finally,
597 .B mhbuild
598 will attempt to consult a global
599 .B mhbuild
600 user profile, e.g.,
601 .PP
602 .RS 5
603 %etcdir%/mhn.defaults
604 .RE
605 .PP
606 if it exists.
607 .SS "Syntax of Composition Files"
608 The following is the formal syntax of a
609 .B mhbuild
610 \*(lqcomposition file\*(rq.
611 .PP
612 .RS 5
613 .nf
614 body ::= 1*(content | EOL)
615
616 content ::= directive | plaintext
617
618 directive ::= "#" type "/" subtype
619 0*(";" attribute "=" value)
620 [ "(" comment ")" ]
621 [ "<" id ">" ]
622 [ "[" description "]" ]
623 [ "{" disposition "}" ]
624 [ filename ]
625 EOL
626
627 | "#@" type "/" subtype
628 0*(";" attribute "=" value)
629 [ "(" comment ")" ]
630 [ "<" id ">" ]
631 [ "[" description "]" ]
632 [ "{" disposition "}" ]
633 external-parameters
634 EOL
635
636 | "#forw"
637 [ "<" id ">" ]
638 [ "[" description "]" ]
639 [ "{" disposition "}" ]
640 [ "+"folder ] [ 0*msg ]
641 EOL
642
643 | "#begin"
644 [ "<" id ">" ]
645 [ "[" description "]" ]
646 [ "{" disposition "}" ]
647 [ "alternative"
648 | "parallel"
649 | something-else ]
650 EOL
651 1*body
652 "#end" EOL
653
654 plaintext ::= [ "Content-Description:"
655 description EOL EOL ]
656 1*line
657 [ "#" EOL ]
658
659 | "#<" type "/" subtype
660 0*(";" attribute "=" value)
661 [ "(" comment ")" ]
662 [ "[" description "]" ]
663 [ "{" disposition "}" ]
664 EOL
665 1*line
666 [ "#" EOL ]
667
668 line ::= "##" text EOL
669 -- interpreted as "#"text EOL
670 | text EOL
671 .fi
672 .RE
673 .SH FILES
674 .B mhbuild
675 looks for additional user profile files and mhn.defaults in multiple
676 locations: absolute pathnames are accessed directly, tilde expansion
677 is done on usernames, and files are searched for in the user's
678 .I Mail
679 directory as specified in their profile. If not found there, the directory
680 .RI \*(lq %etcdir% \*(rq
681 is checked.
682 .PP
683 .fc ^ ~
684 .nf
685 .ta \w'%etcdir%/ExtraBigFileName 'u
686 ^$HOME/\&.mh\(ruprofile~^The user profile
687 ^$MHBUILD~^Additional profile entries
688 ^%etcdir%/mhn.defaults~^System default MIME profile entries
689 .fi
690 .SH "PROFILE COMPONENTS"
691 .fc ^ ~
692 .nf
693 .ta 2.4i
694 .ta \w'ExtraBigProfileName 'u
695 ^Path:~^To determine the user's nmh directory
696 ^Current\-Folder:~^To find the default current folder
697 ^mhbuild-compose-<type>*~^Template for composing contents
698 .fi
699 .SH "SEE ALSO"
700 .IR mhlist (1),
701 .IR mhshow (1),
702 .IR mhstore (1)
703 .PP
704 .I "Proposed Standard for Message Encapsulation"
705 (RFC 934),
706 .PP
707 .I "The Content-MD5 Header Field"
708 (RFC 1864),
709 .PP
710 .I "Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies"
711 (RFC 2045),
712 .PP
713 .I "Multipurpose Internet Mail Extensions (MIME) Part Two: Media Types"
714 (RFC 2046),
715 .PP
716 .I "Multipurpose Internet Mail Extensions (MIME) Part Three: Message Header Extensions for Non-ASCII Text"
717 (RFC 2047),
718 .PP
719 .I "Multipurpose Internet Mail Extensions (MIME) Part Four: Registration Procedures"
720 (RFC 2048),
721 .PP
722 .I "Multipurpose Internet Mail Extensions (MIME) Part Five: Conformance Criteria and Examples"
723 (RFC 2049)
724 .I "Definition of the URL MIME External-Body Access-Type"
725 (RFC 2017)
726 .SH DEFAULTS
727 .nf
728 .RB ` \-headers '
729 .RB ` \-realsize '
730 .RB ` \-norfc934mode '
731 .RB ` \-contentid '
732 .RB ` \-nocheck '
733 .RB ` \-noverbose '
734 .RB ` \-autoheaderencoding '
735 .fi