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