]> diplodocus.org Git - nmh/blob - man/mh-format.man
vector.c: Move interface to own file.
[nmh] / man / mh-format.man
1 .TH MH-FORMAT %manext5% 2015-01-10 "%nmhversion%"
2 .
3 .\" %nmhwarning%
4 .
5 .SH NAME
6 mh-format \- formatting language for nmh message system
7 .SH DESCRIPTION
8 Several
9 .B nmh
10 commands utilize either a
11 .I format
12 string or a
13 .I format
14 file during their execution. For example,
15 .B scan
16 uses a format string to generate its listing of messages;
17 .B repl
18 uses a format file to generate message replies, and so on.
19 .PP
20 There are a number of scan listing formats available,
21 including
22 .IR nmh/etc/scan.time ,
23 .IR nmh/etc/scan.size ,
24 and
25 .IR nmh/etc/scan.timely .
26 Look in
27 .I %nmhetcdir%
28 for other
29 .B scan
30 and
31 .B repl
32 format files which may have been written at your site.
33 .PP
34 You can have your local
35 .B nmh
36 expert write new format commands or modify existing ones,
37 or you can try your hand at it yourself.
38 This manual section explains how to do that.
39 Note: some familiarity with the C
40 .B printf
41 routine is assumed.
42 .PP
43 A format string consists of ordinary text combined with special,
44 multi-character, escape sequences which begin with `%'.
45 When specifying a format string, the usual C backslash characters
46 are honored: `\\b', `\\f', `\\n', `\\r', and `\\t'.
47 Continuation lines in format files end with `\\' followed by the
48 newline character. A literal `%' can be inserted into a format
49 file by using the sequence `%%'.
50 .\" TALK ABOUT SYNTAX FIRST, THEN SEMANTICS
51 .SS SYNTAX
52 Format strings are built around
53 .IR "escape sequences" .
54 There are three types of escape sequence: header
55 .IR components ,
56 built-in
57 .IR functions ,
58 and flow
59 .IR control .
60 Comments may be inserted in most places where a function argument is
61 not expected. A comment begins with `%;' and ends with a (non-escaped)
62 newline.
63 .SS "Component escapes"
64 A
65 .I component
66 escape is specified as
67 .RI `%{ component }',
68 and
69 exists for each header in the message being processed. For example,
70 .RI `%{ date }'
71 refers to the \*(lqDate:\*(rq field of the message.
72 All component escapes have a string value. Such values are usually
73 compressed by converting any control characters (tab and newline included)
74 to spaces, then eliding any leading or multiple spaces. Some commands,
75 however, may interpret some component escapes differently; be sure to
76 refer to each command's manual entry for details.
77 Some commands (such as
78 .IR ap (8)
79 and
80 .IR mhl (1) )
81 use a special component
82 .RI `%{ text }'
83 to refer to the text being processed; see their respective man pages for
84 details and examples.
85 .SS "Function escapes"
86 A
87 .I function
88 escape is specified as
89 .RI `%( function )'.
90 All functions are built-in, and most have a string or integer value.
91 A function escape may take an
92 .IR argument .
93 The argument follows the function escape (and any separating
94 whitespace is discarded) as in the following example:
95 .PP
96 .RS 5
97 .nf
98 .RI %( function " " argument )
99 .fi
100 .RE
101 .PP
102 In addition to literal numbers or strings, the argument to a
103 function escape can be another function, or a component,
104 or a control escape. When the argument is a function or a
105 component, the argument is specified without a leading `%'.
106 When the argument is a control escape, it is specified
107 with a leading `%'.
108 .SS "Control escapes"
109 A
110 .I control
111 escape is one of: `%<', `%?', `%|', or `%>'.
112 These are combined into the conditional execution construct:
113 .PP
114 .RS 5
115 .nf
116 .RI "%< " condition " " "format-text"
117 .RI "%? " condition " " "format-text"
118 ...
119 .RI "%| " "format-text"
120 %>
121 .fi
122 .RE
123 .PP
124 (Extra white space is shown here only for clarity.)
125 These constructs, which may be nested without ambiguity, form a general
126 .B if-elseif-else-endif
127 block where only one of the format-texts is interpreted. In other
128 words, `%<' is like the "if", `%?' is like the "elseif", `%|' is like
129 "else", and `%>' is like "endif".
130 .PP
131 A `%<' or `%?' control escape causes its condition to be evaluated.
132 This condition is a
133 .I component
134 or
135 .IR function .
136 For components and functions whose value is an integer, the condition is true
137 if it is non-zero, and false if zero.
138 For components and functions whose value is a string, the condition is true
139 it is a non-empty string, and false if an empty string.
140 .PP
141 The `%?' control escape is optional, and can be used multiple times
142 in a conditional block. The `%|' control escape is also optional,
143 but may only be used once.
144 .SS "Function escapes"
145 Functions expecting an argument generally require an argument of a
146 particular type. In addition to the integer and string types,
147 these include:
148 .PP
149 .RS 5
150 .nf
151 .ta +\w'Argument 'u +\w'An optional component, 'u
152 .I "Argument Description Example Syntax"
153 literal A literal number %(\fIfunc\fR 1234)
154 or string %(\fIfunc\fR text string)
155 comp Any component %(\fIfunc\fR\^{\fIin-reply-to\fR\^})
156 date A date component %(\fIfunc\fR\^{\fIdate\fR\^})
157 addr An address component %(\fIfunc\fR\^{\fIfrom\fR\^})
158 expr Nothing %(\fIfunc\fR)
159 or a subexpression %(\fIfunc\fR\^(\fIfunc2\fR\^))
160 or control escape %(\fIfunc\fR %<{\fIreply-to\fR\^}%|%{\fIfrom\fR\^}%>)
161 .fi
162 .RE
163 .PP
164 The
165 .I date
166 and
167 .I addr
168 types have the same syntax as the component type,
169 .IR comp ,
170 but require a header component which is a date, or address,
171 string, respectively.
172 .PP
173 Most arguments not of type
174 .I expr
175 are required.
176 When escapes are nested (via expr arguments), evaluation is done
177 from innermost to outermost. As noted above, for the
178 .I expr
179 argument type, functions and components are written without a
180 leading `%'.
181 Control escape arguments must use a leading `%', preceded by a space.
182 .PP
183 For example,
184 .PP
185 .RS 5
186 .nf
187 %<(mymbox{from}) To: %{to}%>
188 .fi
189 .RE
190 .PP
191 writes the value of the header component \*(lqFrom:\*(rq to the
192 internal register named str; then (\fImymbox\fR\^) reads str and
193 writes its result to the internal register named
194 .IR num ;
195 then the control escape, `%<', evaluates
196 .IR num .
197 If
198 .I num
199 is non-zero, the string \*(lqTo:\*(rq is printed followed by the
200 value of the header component \*(lqTo:\*(rq.
201 .SS Evaluation
202 The evaluation of format strings is performed
203 by a small virtual machine.
204 The machine is capable of evaluating nested expressions
205 (as described above) and, in addition, has an integer register
206 .IR num ,
207 and a text string register
208 .IR str .
209 When a function escape that accepts an optional argument is processed,
210 and the argument is not present, the current value of either
211 .I num
212 or
213 .I str
214 is substituted as the argument: the register used depends on the function,
215 as listed below.
216 .PP
217 Component escapes write the value of their message header in
218 .IR str .
219 Function escapes write their return value in
220 .I num
221 for functions returning integer or boolean values, and in
222 .I str
223 for functions returning string values. (The boolean type is a subset
224 of integers, with usual values 0=false and 1=true.) Control escapes
225 return a boolean value, setting
226 .I num
227 to 1 if the last explicit condition
228 evaluated by a `%<' or `%?' control escape succeeded, and 0 otherwise.
229 .PP
230 All component escapes, and those function escapes which return an
231 integer or string value, evaluate to their value as well as setting
232 .I str
233 or
234 .IR num .
235 Outermost escape expressions in these forms will print
236 their value, but outermost escapes which return a boolean value
237 do not result in printed output.
238 .SS Functions
239 The function escapes may be roughly grouped into a few categories.
240 .PP
241 .RS 5
242 .nf
243 .ta \w'Fformataddr 'u +\w'Aboolean 'u +\w'Rboolean 'u
244 .I "Function Argument Return Description"
245 msg integer message number
246 cur integer message is current (0 or 1)
247 unseen integer message is unseen (0 or 1)
248 size integer size of message
249 strlen integer length of \fIstr\fR
250 width integer column width of terminal
251 charleft integer bytes left in output buffer
252 timenow integer seconds since the Unix epoch
253 me string the user's mailbox (username)
254 myhost string the user's local hostname
255 myname string the user's name
256 localmbox string the complete local 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 multiply literal integer \fInum\fR multiplied by \fIarg\fR
265 divide literal integer \fInum\fR divided by \fIarg\fR
266 modulo literal integer \fInum\fR modulo \fIarg\fR
267 num literal integer Set \fInum\fR to \fIarg\fR.
268 num integer Set \fInum\fR to zero.
269 lit literal string Set \fIstr\fR to \fIarg\fR.
270 lit string Clear \fIstr\fR.
271 getenv literal string Set \fIstr\fR to environment value of \fIarg\fR
272 profile literal string Set \fIstr\fR to profile component \fIarg\fR
273 value
274 .\" dat literal int return value of dat[arg]
275 nonzero expr boolean \fInum\fR is non-zero
276 zero expr boolean \fInum\fR is zero
277 null expr boolean \fIstr\fR is empty
278 nonnull expr boolean \fIstr\fR is non-empty
279 void expr Set \fIstr\fR or \fInum\fR
280 comp comp string Set \fIstr\fR to component text
281 compval comp integer Set \fInum\fR to \*(lq\fBatoi\fR(\fIcomp\fR\^)\*(rq
282 .\" compflag comp integer Set \fInum\fR to component flags bits (internal)
283 .\" decodecomp comp string Set \fIstr\fR to RFC 2047 decoded component text
284 decode expr string decode \fIstr\fR as RFC 2047 (MIME-encoded)
285 component
286 unquote expr string remove RFC 2822 quotes from \fIstr\fR
287 trim expr trim trailing whitespace from \fIstr\fR
288 kilo expr string express in SI units: 15.9K, 2.3M, etc.
289 %(kilo) scales by factors of 1000,
290 kibi expr string express in IEC units: 15.5Ki, 2.2Mi.
291 %(kibi) scales by factors of 1024.
292 putstr expr print \fIstr\fR
293 putstrf expr print \fIstr\fR in a fixed width
294 putnum expr print \fInum\fR
295 putnumf expr print \fInum\fR in a fixed width
296 putlit expr print \fIstr\fR without space compression
297 zputlit expr print \fIstr\fR without space compression;
298 \fIstr\fR must occupy no width on display
299 bold string set terminal bold mode
300 underline string set terminal underlined mode
301 standout string set terminal standout mode
302 resetterm string reset all terminal attributes
303 hascolor boolean terminal supports color
304 fgcolor literal string set terminal foreground color
305 bgcolor literal string set terminal background color
306 formataddr expr append \fIarg\fR to \fIstr\fR as a
307 (comma separated) address list
308 concataddr expr append \fIarg\fR to \fIstr\fR as a
309 (comma separated) address list,
310 including duplicates,
311 see Special Handling
312 putaddr literal print \fIstr\fR address list with
313 \fIarg\fR as optional label;
314 get line width from \fInum\fR
315 .fi
316 .RE
317 .PP
318 The (\fIme\fR\^) function returns the username of the current user.
319 The (\fImyhost\fR\^) function returns the
320 .B localname
321 entry in
322 .IR mts.conf ,
323 or the local hostname if
324 .B localname
325 is not configured. The (\fImyname\fR\^) function will return the value of
326 the
327 .B SIGNATURE
328 environment variable if set, otherwise it will return the passwd GECOS field
329 (truncated at the first comma if it contains one) for
330 the current user. The (\fIlocalmbox\fR\^) function will return the complete
331 form of the local mailbox, suitable for use in a \*(lqFrom\*(rq header.
332 It will return the
333 .RI \*(lq Local-Mailbox \*(rq
334 profile entry if there is one; if not, it will be equivalent to:
335 .PP
336 .RS 5
337 .nf
338 %(myname) <%(me)@%(myhost)>
339 .fi
340 .RE
341 .PP
342 The following functions require a date component as an argument:
343 .PP
344 .RS 5
345 .nf
346 .ta \w'Fformataddr 'u +\w'Aboolean 'u +\w'Rboolean 'u
347 .I "Function Argument Return Description"
348 sec date integer seconds of the minute
349 min date integer minutes of the hour
350 hour date integer hours of the day (0-23)
351 wday date integer day of the week (Sun=0)
352 day date string day of the week (abbrev.)
353 weekday date string day of the week
354 sday date integer day of the week known?
355 (1=explicit,0=implicit,\-1=unknown)
356 mday date integer day of the month
357 yday date integer day of the year
358 mon date integer month of the year
359 month date string month of the year (abbrev.)
360 lmonth date string month of the year
361 year date integer year (may be > 100)
362 zone date integer timezone in minutes
363 tzone date string timezone string
364 szone date integer timezone explicit?
365 (1=explicit,0=implicit,\-1=unknown)
366 date2local date coerce date to local timezone
367 date2gmt date coerce date to GMT
368 dst date integer daylight savings in effect? (0 or 1)
369 clock date integer seconds since the Unix epoch
370 rclock date integer seconds prior to current time
371 tws date string official RFC 822 rendering
372 pretty date string user-friendly rendering
373 nodate date integer returns 1 if date is invalid
374 .fi
375 .RE
376 .PP
377 The following functions require an address component as an argument.
378 The return value of functions noted with `*' is computed from
379 the first address present in the header component.
380 .PP
381 .RS 5
382 .nf
383 .ta \w'Fformataddr 'u +\w'Aboolean 'u +\w'Rboolean 'u
384 .I "Function Argument Return Description"
385 proper addr string official RFC 822 rendering
386 friendly addr string user-friendly rendering
387 addr addr string mbox@host or host!mbox rendering*
388 pers addr string the personal name*
389 note addr string commentary text*
390 mbox addr string the local mailbox*
391 mymbox addr integer list has the user's address? (0 or 1)
392 getmymbox addr string the user's (first) address,
393 with personal name
394 getmyaddr addr string the user's (first) address,
395 without personal name
396 host addr string the host domain*
397 nohost addr integer no host was present (0 or 1)*
398 type addr integer host type* (0=local,1=network,
399 \-1=uucp,2=unknown)
400 path addr string any leading host route*
401 ingrp addr integer address was inside a group (0 or 1)*
402 gname addr string name of group*
403 .fi
404 .RE
405 .PP
406 (A clarification on (\fImymbox\fR\^{\fIcomp\fR\^}) is in order.
407 This function checks each of the addresses in the header component
408 \*(lq\fIcomp\fR\*(rq against the user's mailbox name and any
409 .RI \*(lq Alternate-Mailboxes \*(rq.
410 It returns true if any address matches. However, it also returns true
411 if the \*(lq\fIcomp\fR\*(rq header is not present in the message.
412 If needed, the (\fInull\fR\^) function can be used to explicitly
413 test for this case.)
414 .SS Formatting
415 When a function or component escape is interpreted and the result will
416 be printed immediately, an optional field width can be specified to
417 print the field in exactly a given number of characters. For example, a
418 numeric escape like %4(\fIsize\fR\^) will print at most 4 digits of the
419 message size; overflow will be indicated by a `?' in the first position
420 (like `?234'). A string escape like %4(\fIme\fR\^) will print the first 4
421 characters and truncate at the end. Short fields are padded at the right
422 with the fill character (normally, a blank). If the field width argument
423 begins with a leading zero, then the fill character is set to a zero.
424 .PP
425 The functions (\fIputnumf\fR\^) and (\fIputstrf\fR\^)
426 print their result in exactly the number of characters
427 specified by their leading field width argument. For example,
428 %06(\fIputnumf\fR\^(\fIsize\fR\^)) will print the message
429 size in a field six characters wide filled with leading zeros;
430 %14(\fIputstrf\^\fR{\fIfrom\^\fR}) will print the \*(lqFrom:\*(rq header
431 component in fourteen characters with trailing spaces added as needed.
432 For \fIputstrf\fR, using a negative value for the field width causes
433 right-justification of the string within the field, with padding on
434 the left up to the field width.
435 The functions (\fIputnum\fR\^) and
436 (\fIputstr\fR\^) are somewhat special: they print their result in the
437 minimum number of characters required, and ignore any leading field width
438 argument. The (\fIputlit\fR\^) function outputs the exact contents of the
439 str register without any changes such as duplicate space removal or control
440 character conversion. Similarly, the (\fIzputlit\fR\^) function outputs
441 the exact contents of the str register, but requires that those contents
442 not occupy any output width. It can therefore be used for outputting
443 terminal escape sequences.
444 .PP
445 There are a limited number of function escapes to output terminal escape
446 sequences. These sequences are retrieved from the
447 .IR terminfo (5)
448 database according to the current terminal setting. The (\fIbold\fR\^),
449 (\fIunderline\fR\^), and (\fIstandout\fR\^) escapes set bold mode,
450 underline mode, and standout mode respectively.
451 (\fIhascolor\fR\^)
452 can be used to determine if the current terminal supports color.
453 (\fIfgcolor\fR\^) and (\fIbgcolor\fR\^) set the foreground and
454 background colors respectively. Both of these escapes take one literal
455 argument, the color name, which can be one of: black, red, green, yellow,
456 blue, magenta, cyan, white. (\fIresetterm\fR\^) resets all terminal
457 attributes to their default setting. These terminal escapes should be
458 used in conjunction with (\fIzputlit\fR\^) (preferred) or
459 (\fIputlit\fR\^), as the normal (\fIputstr\fR\^) function will strip
460 out control characters.
461 .PP
462 The available output width is kept in an internal register; any output
463 exceeding this width will be truncated. The one exception to this is that
464 (\fIzputlit\fR\^) functions will still be executed if a terminal
465 reset code is being placed at the end of a line.
466 .SS Special Handling
467 Some functions have different behavior depending on the command they are
468 invoked from.
469 .PP
470 In
471 .B repl
472 the (\fIformataddr\fR\^) function stores all email addresses encountered into
473 an internal cache and will use this cache to suppress duplicate addresses.
474 If you need to create an address list that includes previously-seen
475 addresses you may use the (\fIconcataddr\fR\^) function, which is identical
476 to (\fIformataddr\fR\^) in all other respects. Note that (\fIconcataddr\fR\^)
477 does
478 .I not
479 add addresses to the duplicate-suppression cache.
480 .SS Other Hints and Tips
481 Sometimes, the writer of a format function is confused because output is
482 duplicated. The general rule to remember is simple: If a function or
483 component escape begins with a `%', it will generate text in the output file.
484 Otherwise, it will not.
485 .PP
486 A good example is a simple attempt to generate a To: header based on
487 the From: and Reply-To: headers:
488 .PP
489 .RS 5
490 .nf
491 %(formataddr %<{reply-to}%|%{from})%(putaddr To: )
492 .fi
493 .RE
494 .PP
495 Unfortunately, if the Reply-to: header is
496 .I not
497 present, the output line
498 will be something like:
499 .PP
500 .RS 5
501 .nf
502 My From User <from@example.com>To: My From User <from@example.com>
503 .fi
504 .RE
505 .PP
506 What went wrong? When performing the test for the
507 .B if
508 clause (%<), the component is not output because it is considered an
509 argument to the
510 .B if
511 statement (so the rule about not starting with % applies). But the component
512 escape in our
513 .B else
514 statement (everything after the `%|') is
515 .I not
516 an argument to anything;
517 it begins with a %, and thus the value of that component is output.
518 This also has the side effect of setting the
519 .I str
520 register, which is later picked up by the (\fIformataddr\fR\^) function
521 and then output by (\fIputaddr\fR\^). The example format string above
522 has another bug: there should always be a valid width value in the
523 .I num
524 register when (\fIputaddr\fR\^) is called, otherwise bad formatting can take
525 place.
526 .PP
527 The solution is to use the (\fIvoid\fR\^) function; this will prevent the
528 function or component from outputting any text. With this in place (and
529 using (\fIwidth\fR\^) to set the
530 .I num
531 register for the width) a better implementation would look like:
532 .PP
533 .RS 3
534 .nf
535 %(formataddr %<{reply-to}%|%(void{from})%(void(width))%(putaddr To: )
536 .fi
537 .RE
538 .PP
539 It should be noted here that the side effects of function and component
540 escapes are still in force and, as a result, each component test in the
541 .B if-elseif-else-endif
542 clause sets the
543 .I str
544 register.
545 .PP
546 As an additional note, the (\fIformataddr\fR\^) and (\fIconcataddr\fR\^)
547 functions have special behavior when it comes to the
548 .I str
549 register. The starting point of the register is saved and is used to
550 build up entries in the address list.
551 .PP
552 You will find the
553 .IR fmttest (1)
554 utility invaluable when debugging problems with format strings.
555 .SS Examples
556 With all the above in mind, here is a breakdown of the default format string for
557 .BR scan .
558 The first part is:
559 .PP
560 .RS
561 .nf
562 %4(msg)%<(cur)+%| %>%<{replied}\-%?{encrypted}E%| %>
563 .fi
564 .RE
565 .PP
566 which says that the message number should be printed in four digits.
567 If the message is the current message then a `+', else a space, should
568 be printed; if a \*(lqReplied:\*(rq field is present then a `\-',
569 else if an \*(lqEncrypted:\*(rq field is present then an `E', otherwise
570 a space, should be printed. Next:
571 .PP
572 .RS
573 .nf
574 %02(mon{date})/%02(mday{date})
575 .fi
576 .RE
577 .PP
578 the month and date are printed in two digits (zero filled) separated by
579 a slash. Next,
580 .PP
581 .RS 5
582 .nf
583 %<{date} %|*%>
584 .fi
585 .RE
586 .PP
587 If a \*(lqDate:\*(rq field is present it is printed, followed by a space;
588 otherwise a `*' is printed.
589 Next,
590 .PP
591 .RS 5
592 .nf
593 %<(mymbox{from})%<{to}To:%14(decode(friendly{to}))%>%>
594 .fi
595 .RE
596 .PP
597 if the message is from me, and there is a \*(lqTo:\*(rq header,
598 print \*(lqTo:\*(rq followed by a \*(lquser-friendly\*(rq rendering of the
599 first address in the \*(lqTo:\*(rq field; any MIME-encoded
600 characters are decoded into the actual characters.
601 Continuing,
602 .PP
603 .RS 5
604 .nf
605 %<(zero)%17(decode(friendly{from}))%>
606 .fi
607 .RE
608 .PP
609 if either of the above two tests failed,
610 then the \*(lqFrom:\*(rq address is printed
611 in a mime-decoded, \*(lquser-friendly\*(rq format.
612 And finally,
613 .PP
614 .RS 5
615 .nf
616 %(decode{subject})%<{body}<<%{body}>>%>
617 .fi
618 .RE
619 .PP
620 the mime-decoded subject and initial body (if any) are printed.
621 .PP
622 For a more complicated example, consider a possible
623 .I replcomps
624 format file.
625 .PP
626 .RS 5
627 .nf
628 %(lit)%(formataddr %<{reply-to}
629 .fi
630 .RE
631 .PP
632 This clears
633 .I str
634 and formats the \*(lqReply-To:\*(rq header
635 if present. If not present, the else-if clause is executed.
636 .PP
637 .RS 5
638 .nf
639 %?{from}%?{sender}%?{return-path}%>)\\
640 .fi
641 .RE
642 .PP
643 This formats the
644 \*(lqFrom:\*(rq, \*(lqSender:\*(rq and \*(lqReturn-Path:\*(rq
645 headers, stopping as soon as one of them is present. Next:
646 .PP
647 .RS 5
648 .nf
649 %<(nonnull)%(void(width))%(putaddr To: )\\n%>\\
650 .fi
651 .RE
652 .PP
653 If the \fIformataddr\fR result is non-null, it is printed as
654 an address (with line folding if needed) in a field \fIwidth\fR
655 wide, with a leading label of \*(lqTo:\*(rq.
656 .PP
657 .RS 5
658 .nf
659 %(lit)%(formataddr{to})%(formataddr{cc})%(formataddr(me))\\
660 .fi
661 .RE
662 .PP
663 .I str
664 is cleared, and the \*(lqTo:\*(rq and \*(lqCc:\*(rq headers, along with the user's
665 address (depending on what was specified with
666 the \*(lq\-cc\*(rq switch to \fIrepl\fR\^) are formatted.
667 .PP
668 .RS 5
669 .nf
670 %<(nonnull)%(void(width))%(putaddr cc: )\\n%>\\
671 .fi
672 .RE
673 .PP
674 If the result is non-null, it is printed as above with a
675 leading label of \*(lqcc:\*(rq.
676 .PP
677 .RS 5
678 .nf
679 %<{fcc}Fcc: %{fcc}\\n%>\\
680 .fi
681 .RE
682 .PP
683 If a
684 .B \-fcc
685 .I folder
686 switch was given to
687 .B repl
688 (see
689 .IR repl (1)
690 for more details about %{\fIfcc\fR\^}),
691 an \*(lqFcc:\*(rq header is output.
692 .PP
693 .RS 5
694 .nf
695 %<{subject}Subject: Re: %{subject}\\n%>\\
696 .fi
697 .RE
698 .PP
699 If a subject component was present,
700 a suitable reply subject is output.
701 .PP
702 .RS 5
703 .nf
704 %<{message-id}In-Reply-To: %{message-id}\\n%>\\
705 %<{message-id}References: %<{references} %{references}%>\\
706 %{message-id}\\n%>
707 \-\-\-\-\-\-\-\-
708 .fi
709 .RE
710 .PP
711 If a message-id component was present, an \*(lqIn-Reply-To:\*(rq header is
712 output including the message-id, followed by a \*(lqReferences:\*(rq
713 header with references, if present, and the message-id.
714 As with all
715 plain-text, the row of dashes are output as-is.
716 .PP
717 This last part is a good example for a little more elaboration.
718 Here's that part again in pseudo-code:
719 .PP
720 .RS 5
721 .nf
722 .ta .5i 1i 1.5i 2i
723 if (comp_exists(message-id)) then
724 print (\*(lqIn-reply-to: \*(rq)
725 print (message-id.value)
726 print (\*(lq\\n\*(rq)
727 endif
728 if (comp_exists(message-id)) then
729 print (\*(lqReferences: \*(rq)
730 if (comp_exists(references)) then
731 print(references.value);
732 endif
733 print (message-id.value)
734 print (\*(lq\\n\*(rq)
735 endif
736 .fi
737 .RE
738 .PP
739 .\" (Note that this pseudocode begs the question ``why not just
740 .\" support this syntax?'' MH has been hacked on for a long time...)
741 .\".PP
742 One more example: Currently,
743 .B nmh
744 supports very large message numbers, and it is not uncommon for a folder
745 to have far more than 10000 messages.
746 .\" (Indeed, the original MH
747 .\" tutorial document by Rose and Romine is entitled "How to
748 .\" process 200 messages a day and still get some real work
749 .\" done." The authors apparently only planned to get
750 .\" real work done for about 50 days per folder.)
751 Nonetheless (as noted above) the various scan format strings, inherited
752 from older MH versions, are generally hard-coded to 4 digits for the message
753 number. Thereafter, formatting problems occur.
754 The nmh format strings can be modified to behave more sensibly with larger
755 message numbers:
756 .PP
757 .RS
758 .nf
759 %(void(msg))%<(gt 9999)%(msg)%|%4(msg)%>
760 .fi
761 .RE
762 .PP
763 The current message number is placed in \fInum\fP.
764 (Note that
765 .RI ( msg )
766 is a function escape which returns an integer, it is not a component.)
767 The
768 .RI ( gt )
769 conditional
770 is used to test whether the message number
771 has 5
772 or more digits.
773 If so, it is printed at full width, otherwise
774 at 4 digits.
775 .SH "SEE ALSO"
776 .IR scan (1),
777 .IR repl (1),
778 .IR fmttest (1)
779 .SH CONTEXT
780 None