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