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