]> diplodocus.org Git - nmh/blob - man/mh-format.man
Update some of the 'how to do a release' documentation
[nmh] / man / mh-format.man
1 .\"
2 .\" THIS FILE HAS BEEN AUTOMATICALLY GENERATED. DO NOT EDIT.
3 .\" $Id$
4 .\"
5 .TH MH-FORMAT %manext5% "%nmhdate%" MH.6.8 [%nmhversion%]
6 .SH NAME
7 mh-format \- format file for nmh message system
8 .SH DESCRIPTION
9 Several
10 .B nmh
11 commands utilize either a
12 .I format
13 string or a
14 .I format
15 file during their execution. For example,
16 .B scan
17 uses a format string which directs it how to generate the scan listing
18 for each message;
19 .B repl
20 uses a format file which directs it
21 how to generate the reply to a message, and so on.
22 .PP
23 There are a few alternate scan listing formats available
24 in
25 .IR nmh/etc/scan.time ,
26 .IR nmh/etc/scan.size ,
27 and
28 .IR nmh/etc/scan.timely .
29 Look in
30 .I nmh/etc
31 for other
32 .B scan
33 and
34 .B repl
35 format files which may have been written at your site.
36 .PP
37 It suffices to have your local
38 .B nmh
39 expert actually write new format
40 commands or modify existing ones. This manual section explains how to
41 do that. Note: familiarity with the C
42 .B printf
43 routine is assumed.
44 .PP
45 A format string consists of ordinary text, and special multi-character
46 escape sequences which begin with `%'. When specifying a format
47 string, the usual C backslash characters are honored: `\\b', `\\f',
48 `\\n', `\\r', and `\\t'. Continuation lines in format files end with
49 `\\' followed by the newline character.
50
51 .\" TALK ABOUT SYNTAX FIRST, THEN SEMANTICS
52 .SS SYNTAX
53 Format strings are built around
54 .IR "escape sequences" .
55 There are three types of escape sequences: header
56 .IR components ,
57 built-in
58 .IR functions ,
59 and flow
60 .IR control .
61 Comments may be inserted in most places where a function argument is
62 not expected. A comment begins with `%;' and ends with a (non-escaped)
63 newline.
64 .PP
65 A
66 .I component
67 escape is specified as
68 .RI `%{ component }',
69 and
70 exists for each header found in the message being processed. For example
71 .RI `%{ date }'
72 refers to the \*(lqDate:\*(rq field of the appropriate message.
73 All component escapes have a string value. Normally, component values are
74 compressed by converting any control characters (tab and newline included)
75 to spaces, then eliding any leading or multiple spaces. However, commands
76 may give different interpretations to some component escapes; be sure
77 to refer to each command's manual entry for complete details.
78 .PP
79 A
80 .I function
81 escape is specified as
82 .RI `%( function )'.
83 All functions are built-in, and most have a string or numeric value.
84 A function escape may have an
85 .IR argument .
86 The argument follows the function escape: separating
87 whitespace is discarded:
88 .RI `%( function " " argument )'.
89 .PP
90 In addition to literal numbers or strings,
91 the argument to a function escape can be another function, a component,
92 or a control escape. When the argument is a function or a
93 component, they are listed without a leading `%'. When control escapes
94 are used as function arguments, they written as normally, with
95 a leading `%';
96
97 .SS "Control escapes"
98 .PP
99 A
100 .I control
101 escape is one of: `%<', `%?', `%|', or `%>'.
102 These are combined into the conditional execution construct:
103 .PP
104 .RS 5
105 .nf
106 .RI "%< " condition " " "format-text"
107 .RI "%? " condition " " "format-text"
108 \&...
109 .RI "%| " "format-text"
110 %>
111 .fi
112 .RE
113 .PP
114 Extra white space is shown here only for clarity. These
115 constructs may be nested without ambiguity. They form a general
116 .B if\-elseif\-else\-endif
117 block where only one of the
118 format-texts
119 is interpreted. In other
120 words, `%<' is like the "if", `%?' is like the "elseif", `%|' is like
121 "else", and `%>' is like "endif".
122 .PP
123 A `%<' or `%?' control escape causes its condition to be evaluated.
124 This condition is a
125 .I component
126 or
127 .IR function .
128 For integer valued functions or components, the condition is true
129 if the function return or component value is non-zero, and false if zero.
130 For string valued functions or components, the condition is true
131 if the function return or component value is
132 a non-empty string, and false for an empty string.
133
134 .PP
135 The `%?' control escape is optional, and may there may be more
136 than one `%?' control escape in a conditional block.
137 The `%|' control escape
138 is also optional, but may be included at most once.
139
140 .SS "Function escapes"
141 Functions expecting an argument generally
142 require an argument of a particular type.
143 In addition to the number and string types,
144 these include:
145 .PP
146 .RS 5
147 .nf
148 .ta +\w'Argument 'u +\w'An optional component, 'u
149 .I Argument Description Example Syntax
150 literal A literal number %(\fIfunc\fR 1234)
151 or string %(\fIfunc\fR text string)
152 comp Any component %(\fIfunc\fR\^{\fIin-reply-to\fR\^})
153 date A date component %(\fIfunc\fR\^{\fIdate\fR\^})
154 addr An address component %(\fIfunc\fR\^{\fIfrom\fR\^})
155 expr Nothing %(\fIfunc\fR)
156 or a subexpression %(\fIfunc\fR\^(\fIfunc2\fR\^))
157 or control escape %(\fIfunc\fR %<{\fIreply-to\fR\^}%|%{\fIfrom\fR\^}%>)
158 .fi
159 .RE
160 .PP
161 The types
162 .I date
163 and
164 .I addr
165 have the same syntax as
166 .IR comp ,
167 but require that the header component be a date string, or address
168 string, respectively.
169 .PP
170 Most arguments not of type
171 .IR expr
172 are required.
173 When escapes are nested (via expr arguments), evaluation is done from inner-most to outer-most.
174 As noted above, for the
175 expr
176 argument type,
177 functions and components are written without a
178 leading `%'.
179 Control escape arguments must use a leading `%', preceded by a space.
180 .PP
181 For example,
182 .PP
183 .RS 5
184 .nf
185 %<(mymbox{from}) To: %{to}%>
186 .fi
187 .RE
188 .PP
189 writes the value of the header component \*(lqFrom:\*(rq to the
190 internal register named str; then (\fImymbox\fR\^) reads str and
191 writes its result to the internal register named
192 .IR num ;
193 then the control escape evaluates
194 .IR num .
195 If
196 .IR num
197 is non-zero, the
198 string \*(lqTo:\*(rq is printed followed by the value of the
199 header component \*(lqTo:\*(rq.
200 .SS Evaluation
201 The evaluation of format strings is performed
202 by a small virtual machine.
203 The machine is capable of evaluating nested expressions
204 as described above, and in addition
205 has an integer register
206 .IR num ,
207 and a text string register
208 .IR str .
209 When a function escape that
210 accepts an optional argument is processed,
211 and the argument is not present, the current value of either
212 .I num
213 or
214 .I str
215 is used as the argument: which register is
216 used depends on the function, as listed below.
217 .PP
218 Component escapes write the value of their message header in
219 .IR str .
220 Function escapes write their return value in
221 .I num
222 for functions returning integer or boolean values, and in
223 .I str
224 for functions returning string values. (The boolean type is a subset
225 of integers with usual values 0=false and 1=true.) Control escapes
226 return a boolean value, setting
227 .I num
228 to 1 if the last explicit condition
229 evaluated by a `%<' or `%?' control
230 succeeded, and 0 otherwise.
231 .PP
232 All component escapes, and those function escapes which return an
233 integer or string value, evaluate to their value as well as setting
234 .I str
235 or
236 .IR num .
237 Outermost escape expressions in
238 these forms will print
239 their value, but outermost escapes which return a boolean value
240 do not result in printed output.
241 .SS Functions
242 The function escapes may be roughly grouped into a few categories.
243 .PP
244 .RS 5
245 .nf
246 .ta \w'Fformataddr 'u +\w'Aboolean 'u +\w'Rboolean 'u
247 .I Function Argument Result Description
248 msg integer message number
249 cur integer message is current (0 or 1)
250 unseen integer message is unseen (0 or 1)
251 size integer size of message
252 strlen integer length of \fIstr\fR
253 width integer output buffer size in bytes
254 charleft integer bytes left in output buffer
255 timenow integer seconds since the UNIX epoch
256 me string the user's mailbox
257 eq literal boolean \fInum\fR == \fIarg\fR
258 ne literal boolean \fInum\fR != \fIarg\fR
259 gt literal boolean \fInum\fR > \fIarg\fR
260 match literal boolean \fIstr\fR contains \fIarg\fR
261 amatch literal boolean \fIstr\fR starts with \fIarg\fR
262 plus literal integer \fIarg\fR plus \fInum\fR
263 minus literal integer \fIarg\fR minus \fInum\fR
264 divide literal integer \fInum\fR divided by \fIarg\fR
265 modulo literal integer \fInum\fR modulo \fIarg\fR
266 num literal integer Set \fInum\fR to \fIarg\fR.
267 num integer Set \fInum\fR to zero.
268 lit literal string Set \fIstr\fR to \fIarg\fR.
269 lit string Clear \fIstr\fR.
270 getenv literal string Set \fIstr\fR to environment value of \fIarg\fR
271 profile literal string Set \fIstr\fR to profile component \fIarg\fR
272 value
273 .\" dat literal int return value of dat[arg]
274 nonzero expr boolean \fInum\fR is non-zero
275 zero expr boolean \fInum\fR is zero
276 null expr boolean \fIstr\fR is empty
277 nonnull expr boolean \fIstr\fR is non-empty
278 void expr Set \fIstr\fR or \fInum\fR
279 comp comp string Set \fIstr\fR to component text
280 compval comp integer Set \fInum\fR to \*(lq\fBatoi\fR(\fIcomp\fR\^)\*(rq
281 .\" compflag comp integer Set \fInum\fR to component flags bits (internal)
282 .\" decodecomp comp string Set \fIstr\fR to RFC-2047 decoded component text
283 decode expr string decode \fIstr\fR as RFC-2047 (MIME-encoded)
284 component
285 unquote expr string remove RFC-2822 quotes from \fIstr\fR
286 trim expr trim trailing white-space from \fIstr\fR
287 putstr expr print \fIstr\fR
288 putstrf expr print \fIstr\fR in a fixed width
289 putnum expr print \fInum\fR
290 putnumf expr print \fInum\fR in a fixed width
291 .\" addtoseq literal add msg to sequence (LBL option)
292 nodate string integer Argument not a date string (0 or 1)
293 formataddr expr append \fIarg\fR to \fIstr\fR as a
294 (comma separated) address list
295 putaddr literal print \fIstr\fR address list with
296 \fIarg\fR as optional label;
297 get line width from \fInum\fR
298 .fi
299 .RE
300 .PP
301 The following functions require a date component as an argument:
302 .PP
303 .RS 5
304 .nf
305 .ta \w'Fformataddr 'u +\w'Aboolean 'u +\w'Rboolean 'u
306 .I Function Argument Return Description
307 sec date integer seconds of the minute
308 min date integer minutes of the hour
309 hour date integer hours of the day (0-23)
310 wday date integer day of the week (Sun=0)
311 day date string day of the week (abbrev.)
312 weekday date string day of the week
313 sday date integer day of the week known?
314 (1=explicit,0=implicit,\-1=unknown)
315 mday date integer day of the month
316 yday date integer day of the year
317 mon date integer month of the year
318 month date string month of the year (abbrev.)
319 lmonth date string month of the year
320 year date integer year (may be > 100)
321 zone date integer timezone in hours
322 tzone date string timezone string
323 szone date integer timezone explicit?
324 (1=explicit,0=implicit,\-1=unknown)
325 date2local date coerce date to local timezone
326 date2gmt date coerce date to GMT
327 dst date integer daylight savings in effect? (0 or 1)
328 clock date integer seconds since the UNIX epoch
329 rclock date integer seconds prior to current time
330 tws date string official 822 rendering
331 pretty date string user-friendly rendering
332 .fi
333 .RE
334 .PP
335 These functions require an address component as an argument.
336 The return value of functions noted with `*' is computed from
337 the first address present in the header component.
338 .PP
339 .RS 5
340 .nf
341 .ta \w'Fformataddr 'u +\w'Aboolean 'u +\w'Rboolean 'u
342 .I Function Argument Return Description
343 proper addr string official 822 rendering
344 friendly addr string user-friendly rendering
345 addr addr string mbox@host or host!mbox rendering*
346 pers addr string the personal name*
347 note addr string commentary text*
348 mbox addr string the local mailbox*
349 mymbox addr integer List has the user's address? (0 or 1)
350 host addr string the host domain*
351 nohost addr integer no host was present (0 or 1)*
352 type addr integer host type* (0=local,1=network,
353 \-1=uucp,2=unknown)
354 path addr string any leading host route*
355 ingrp addr integer address was inside a group (0 or 1)*
356 gname addr string name of group*
357 .fi
358 .RE
359 .PP
360 (A clarification on (\fImymbox\fR\^{\fIcomp\fR\^}) is in order.
361 This function checks each of the addresses in the header component
362 \*(lq\fIcomp\fR\*(rq against the user's mailbox name and any
363 .RI \*(lq Alternate-Mailboxes \*(rq.
364 It returns true if any address matches,
365 however, it also returns true if the \*(lq\fIcomp\fR\*(rq header is not
366 present in the message. If needed, the (\fInull\fR\^) function can be
367 used to explicitly test for this case.)
368 .SS Formatting
369 When a function or component escape is interpreted and the result will
370 be immediately printed, an optional field width can be specified to
371 print the field in exactly a given number of characters. For example, a
372 numeric escape like %4(\fIsize\fR\^) will print at most 4 digits of the
373 message size; overflow will be indicated by a `?' in the first position
374 (like `?234'). A string escape like %4(\fIme\fR\^) will print the first 4
375 characters and truncate at the end. Short fields are padded at the right
376 with the fill character (normally, a blank). If the field width argument
377 begins with a leading zero, then the fill character is set to a zero.
378 .PP
379 The functions (\fIputnumf\fR\^) and (\fIputstrf\fR\^)
380 print their result in exactly the number of characters
381 specified by their leading field width argument. For example,
382 %06(\fIputnumf\fR\^(\fIsize\fR\^)) will print the message
383 size in a field six characters wide filled with leading zeros;
384 %14(\fIputstrf\^\fR{\fIfrom\^\fR}) will print the \*(lqFrom:\*(rq header
385 component in fourteen characters with trailing spaces added as needed.
386 For \fIputstrf\fR, using a negative value for the field width causes
387 right-justification of the string within the field, with padding on
388 the left up to the field width.
389 The functions (\fIputnum\fR\^) and
390 (\fIputstr\fR\^) are somewhat special: they print their result in the minimum number of characters
391 required, and ignore any leading field width argument.
392 .PP
393 The available output width is kept in an internal register; any output
394 past this width will be truncated.
395 .SS Examples
396 With all this in mind,
397 here's the default format string for
398 .BR scan .
399 It's been divided into several pieces for readability.
400 The first part is:
401 .PP
402 .RS
403 .nf
404 %4(msg)%<(cur)+%| %>%<{replied}\-%?{encrypted}E%| %>
405 .fi
406 .RE
407 .PP
408 which says that the message number should be printed in four digits.
409 If the message is the current message then a `+' else a space should
410 be printed; if a \*(lqReplied:\*(rq field is present then a `\-'
411 else if an \*(lqEncrypted:\*(rq field is present then an `E' otherwise
412 a space should be printed. Next:
413 .PP
414 .RS
415 .nf
416 %02(mon{date})/%02(mday{date})
417 .fi
418 .RE
419 .PP
420 the month and date are printed in two digits (zero filled) separated by
421 a slash. Next,
422 .PP
423 .RS 5
424 .nf
425 %<{date} %|*%>
426 .fi
427 .RE
428 .PP
429 If a \*(lqDate:\*(rq field was present,
430 then a space is printed, otherwise a `*'.
431 Next,
432 .PP
433 .RS 5
434 .nf
435 %<(mymbox{from})%<{to}To:%14(decode(friendly{to}))%>%>
436 .fi
437 .RE
438 .PP
439 if the message is from me, and there is a \*(lqTo:\*(rq header,
440 print \*(lqTo:\*(rq followed by a \*(lquser-friendly\*(rq rendering of the
441 first address in the \*(lqTo:\*(rq field; any MIME-encoded
442 characters are decoded into the actual characters.
443 Continuing,
444 .PP
445 .RS 5
446 .nf
447 %<(zero)%17(decode(friendly{from}))%>
448 .fi
449 .RE
450 .PP
451 if either of the above two tests failed,
452 then the \*(lqFrom:\*(rq address is printed
453 in a mime-decoded, \*(lquser-friendly\*(rq format.
454 And finally,
455 .PP
456 .RS 5
457 .nf
458 %(decode{subject})%<{body}<<%{body}>>%>
459 .fi
460 .RE
461 .PP
462 the mime-decoded subject and initial body (if any) are printed.
463 .PP
464 For a more complicated example, next consider
465 a possible
466 .I replcomps
467 format file.
468 .PP
469 .RS 5
470 .nf
471 %(lit)%(formataddr %<{reply-to}
472 .fi
473 .RE
474 .PP
475 This clears
476 .I str
477 and formats the \*(lqReply-To:\*(rq header
478 if present. If not present, the else-if clause is executed.
479 .PP
480 .RS 5
481 .nf
482 %?{from}%?{sender}%?{return-path}%>)\\
483 .fi
484 .RE
485 .PP
486 This formats the
487 \*(lqFrom:\*(rq, \*(lqSender:\*(rq and \*(lqReturn-Path:\*(rq
488 headers, stopping as soon as one of them is present. Next:
489 .PP
490 .RS 5
491 .nf
492 %<(nonnull)%(void(width))%(putaddr To: )\\n%>\\
493 .fi
494 .RE
495 .PP
496 If the \fIformataddr\fR result is non-null, it is printed as
497 an address (with line folding if needed) in a field \fIwidth\fR
498 wide with a leading label of \*(lqTo:\*(rq.
499 .PP
500 .RS 5
501 .nf
502 %(lit)%(formataddr{to})%(formataddr{cc})%(formataddr(me))\\
503 .fi
504 .RE
505 .PP
506 .I str
507 is cleared, and the \*(lqTo:\*(rq and \*(lqCc:\*(rq headers, along with the user's
508 address (depending on what was specified with
509 the \*(lq\-cc\*(rq switch to \fIrepl\fR\^) are formatted.
510 .PP
511 .RS 5
512 .nf
513 %<(nonnull)%(void(width))%(putaddr cc: )\\n%>\\
514 .fi
515 .RE
516 .PP
517 If the result is non-null, it is printed as above with a
518 leading label of \*(lqcc:\*(rq.
519 .PP
520 .RS 5
521 .nf
522 %<{fcc}Fcc: %{fcc}\\n%>\\
523 .fi
524 .RE
525 .PP
526 If a
527 .B \-fcc
528 .I folder
529 switch was given to
530 .B repl
531 (see
532 .BR repl (1)
533 for more details about %{\fIfcc\fR\^}),
534 an \*(lqFcc:\*(rq header is output.
535 .PP
536 .RS 5
537 .nf
538 %<{subject}Subject: Re: %{subject}\\n%>\\
539 .fi
540 .RE
541 .PP
542 If a subject component was present,
543 a suitable reply subject is output.
544 .PP
545 .RS 5
546 .nf
547 %<{message-id}In-Reply-To: %{message-id}\\n%>\\
548 %<{message-id}References: %<{references} %{references}%>\\
549 %{message-id}\\n%>
550 \-\-\-\-\-\-\-\-
551 .fi
552 .RE
553 .PP
554 If a message-id component was present, an \*(lqIn-Reply-To:\*(rq header is
555 output including the message-id, followed by a \*(lqReferences:\*(rq
556 header with references, if present, and the message-id.
557 As with all
558 plain-text, the row of dashes are output as-is.
559 .PP
560 This last part is a good example for a little more elaboration.
561 Here's that part again in pseudo-code:
562 .PP
563 .RS 5
564 .nf
565 .ta .5i 1i 1.5i 2i
566 if (comp_exists(message-id)) then
567 print (\*(lqIn-reply-to: \*(rq)
568 print (message-id.value)
569 print (\*(lq\\n\*(rq)
570 endif
571 if (comp_exists(message-id)) then
572 print (\*(lqReferences: \*(rq)
573 if (comp_exists(references)) then
574 print(references.value);
575 endif
576 print (message-id.value)
577 print (\*(lq\\n\*(rq)
578 endif
579 .fi
580 .RE
581 .PP
582 .\" (Note that this pseudocode begs the question ``why not just
583 .\" support this syntax?'' MH has been hacked on for a long time...)
584 .\".PP
585 One more example: Currently,
586 .B nmh
587 supports very
588 large message numbers, and it is not uncommon for a folder
589 to have far more than 10000 messages.
590 .\" (Indeed, the original MH
591 .\" tutorial document by Rose and Romine is entitled "How to
592 .\" process 200 messages a day and still get some real work
593 .\" done." The authors apparently only planned to get
594 .\" real work done for about 50 days per folder.)
595 Nontheless (as noted above)
596 the various scan format strings are inherited
597 from older MH versions, and are generally hard-coded to 4
598 digits of message number before formatting problems
599 start to occur.
600 The nmh format strings can be modified to behave more sensibly with larger
601 message numbers:
602 .PP
603 .RS
604 .nf
605 %(void(msg))%<(gt 9999)%(msg)%|%4(msg)%>
606 .fi
607 .RE
608 .PP
609 The current message number is placed in \fInum\fP.
610 (Note that
611 .RI ( msg )
612 is an int function, not a component.)
613 The
614 .RI ( gt )
615 conditional
616 is used to test whether the message number
617 has 5
618 or more digits.
619 If so, it is printed at full width: otherwise
620 at 4 digits.
621 .SH "SEE ALSO"
622 scan(1), repl(1), ap(8), dp(8)
623
624 .SH CONTEXT
625 None