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