2 .\" THIS FILE HAS BEEN AUTOMATICALLY GENERATED. DO NOT EDIT.
4 .TH MH-FORMAT %manext5% "%nmhdate%" MH.6.8 [%nmhversion%]
6 mh-format \- format file for nmh message system
10 commands utilize either a
14 file during their execution. For example,
16 uses a format string which directs it how to generate the scan listing
19 uses a format file which directs it
20 how to generate the reply to a message, and so on.
22 There are a few alternate scan listing formats available
24 .IR nmh/etc/scan.time ,
25 .IR nmh/etc/scan.size ,
27 .IR nmh/etc/scan.timely .
34 format files which may have been written at your site.
36 It suffices to have your local
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
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.
50 .\" TALK ABOUT SYNTAX FIRST, THEN SEMANTICS
52 Format strings are built around
53 .IR "escape sequences" .
54 There are three types of escape sequences: header
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)
66 escape is specified as
69 exists for each header found in the message being processed. For example
71 refers to the \*(lqDate:\*(rq field of the appropriate message.
72 All component escapes have a string value. Normally, component values are
73 compressed by converting any control characters (tab and newline included)
74 to spaces, then eliding any leading or multiple spaces. However, commands
75 may give different interpretations to some component escapes; be sure
76 to refer to each command's manual entry for complete details.
80 escape is specified as
82 All functions are built-in, and most have a string or numeric value.
83 A function escape may have an
85 The argument follows the function escape: separating
86 whitespace is discarded:
87 .RI `%( function " " argument )'.
89 In addition to literal numbers or strings,
90 the argument to a function escape can be another function, a component,
91 or a control escape. When the argument is a function or a
92 component, they are listed without a leading `%'. When control escapes
93 are used as function arguments, they written as normally, with
100 escape is one of: `%<', `%?', `%|', or `%>'.
101 These are combined into the conditional execution construct:
105 .RI "%< " condition " " "format-text"
106 .RI "%? " condition " " "format-text"
108 .RI "%| " "format-text"
113 Extra white space is shown here only for clarity. These
114 constructs may be nested without ambiguity. They form a general
115 .B if\-elseif\-else\-endif
116 block where only one of the
118 is interpreted. In other
119 words, `%<' is like the "if", `%?' is like the "elseif", `%|' is like
120 "else", and `%>' is like "endif".
122 A `%<' or `%?' control escape causes its condition to be evaluated.
127 For integer valued functions or components, the condition is true
128 if the function return or component value is non-zero, and false if zero.
129 For string valued functions or components, the condition is true
130 if the function return or component value is
131 a non-empty string, and false for an empty string.
134 The `%?' control escape is optional, and may there may be more
135 than one `%?' control escape in a conditional block.
136 The `%|' control escape
137 is also optional, but may be included at most once.
139 .SS "Function escapes"
140 Functions expecting an argument generally
141 require an argument of a particular type.
142 In addition to the number and string types,
147 .ta +\w'Argument 'u +\w'An optional component, 'u
148 .I Argument Description Example Syntax
149 literal A literal number %(\fIfunc\fR 1234)
150 or string %(\fIfunc\fR text string)
151 comp Any component %(\fIfunc\fR\^{\fIin-reply-to\fR\^})
152 date A date component %(\fIfunc\fR\^{\fIdate\fR\^})
153 addr An address component %(\fIfunc\fR\^{\fIfrom\fR\^})
154 expr Nothing %(\fIfunc\fR)
155 or a subexpression %(\fIfunc\fR\^(\fIfunc2\fR\^))
156 or control escape %(\fIfunc\fR %<{\fIreply-to\fR\^}%|%{\fIfrom\fR\^}%>)
164 have the same syntax as
166 but require that the header component be a date string, or address
167 string, respectively.
169 Most arguments not of type
172 When escapes are nested (via expr arguments), evaluation is done from inner-most to outer-most.
173 As noted above, for the
176 functions and components are written without a
178 Control escape arguments must use a leading `%', preceded by a space.
184 %<(mymbox{from}) To: %{to}%>
188 writes the value of the header component \*(lqFrom:\*(rq to the
189 internal register named str; then (\fImymbox\fR\^) reads str and
190 writes its result to the internal register named
192 then the control escape evaluates
197 string \*(lqTo:\*(rq is printed followed by the value of the
198 header component \*(lqTo:\*(rq.
200 The evaluation of format strings is performed
201 by a small virtual machine.
202 The machine is capable of evaluating nested expressions
203 as described above, and in addition
204 has an integer register
206 and a text string register
208 When a function escape that
209 accepts an optional argument is processed,
210 and the argument is not present, the current value of either
214 is used as the argument: which register is
215 used depends on the function, as listed below.
217 Component escapes write the value of their message header in
219 Function escapes write their return value in
221 for functions returning integer or boolean values, and in
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
227 to 1 if the last explicit condition
228 evaluated by a `%<' or `%?' control
229 succeeded, and 0 otherwise.
231 All component escapes, and those function escapes which return an
232 integer or string value, evaluate to their value as well as setting
236 Outermost escape expressions in
237 these forms will print
238 their value, but outermost escapes which return a boolean value
239 do not result in printed output.
241 The function escapes may be roughly grouped into a few categories.
245 .ta \w'Fformataddr 'u +\w'Aboolean 'u +\w'Rboolean 'u
246 .I Function Argument Result Description
247 msg integer message number
248 cur integer message is current (0 or 1)
249 unseen integer message is unseen (0 or 1)
250 size integer size of message
251 strlen integer length of \fIstr\fR
252 width integer output buffer size in bytes
253 charleft integer bytes left in output buffer
254 timenow integer seconds since the UNIX epoch
255 me string the user's mailbox
256 eq literal boolean \fInum\fR == \fIarg\fR
257 ne literal boolean \fInum\fR != \fIarg\fR
258 gt literal boolean \fInum\fR > \fIarg\fR
259 match literal boolean \fIstr\fR contains \fIarg\fR
260 amatch literal boolean \fIstr\fR starts with \fIarg\fR
261 plus literal integer \fIarg\fR plus \fInum\fR
262 minus literal integer \fIarg\fR minus \fInum\fR
263 divide literal integer \fInum\fR divided by \fIarg\fR
264 modulo literal integer \fInum\fR modulo \fIarg\fR
265 num literal integer Set \fInum\fR to \fIarg\fR.
266 num integer Set \fInum\fR to zero.
267 lit literal string Set \fIstr\fR to \fIarg\fR.
268 lit string Clear \fIstr\fR.
269 getenv literal string Set \fIstr\fR to environment value of \fIarg\fR
270 profile literal string Set \fIstr\fR to profile component \fIarg\fR
272 .\" dat literal int return value of dat[arg]
273 nonzero expr boolean \fInum\fR is non-zero
274 zero expr boolean \fInum\fR is zero
275 null expr boolean \fIstr\fR is empty
276 nonnull expr boolean \fIstr\fR is non-empty
277 void expr Set \fIstr\fR or \fInum\fR
278 comp comp string Set \fIstr\fR to component text
279 compval comp integer Set \fInum\fR to \*(lq\fBatoi\fR(\fIcomp\fR\^)\*(rq
280 .\" compflag comp integer Set \fInum\fR to component flags bits (internal)
281 .\" decodecomp comp string Set \fIstr\fR to RFC-2047 decoded component text
282 decode expr string decode \fIstr\fR as RFC-2047 (MIME-encoded)
284 unquote expr string remove RFC-2822 quotes from \fIstr\fR
285 trim expr trim trailing white-space from \fIstr\fR
286 putstr expr print \fIstr\fR
287 putstrf expr print \fIstr\fR in a fixed width
288 putnum expr print \fInum\fR
289 putnumf expr print \fInum\fR in a fixed width
290 nodate string integer Argument not a date string (0 or 1)
291 formataddr expr append \fIarg\fR to \fIstr\fR as a
292 (comma separated) address list
293 putaddr literal print \fIstr\fR address list with
294 \fIarg\fR as optional label;
295 get line width from \fInum\fR
299 The following functions require a date component as an argument:
303 .ta \w'Fformataddr 'u +\w'Aboolean 'u +\w'Rboolean 'u
304 .I Function Argument Return Description
305 sec date integer seconds of the minute
306 min date integer minutes of the hour
307 hour date integer hours of the day (0-23)
308 wday date integer day of the week (Sun=0)
309 day date string day of the week (abbrev.)
310 weekday date string day of the week
311 sday date integer day of the week known?
312 (1=explicit,0=implicit,\-1=unknown)
313 mday date integer day of the month
314 yday date integer day of the year
315 mon date integer month of the year
316 month date string month of the year (abbrev.)
317 lmonth date string month of the year
318 year date integer year (may be > 100)
319 zone date integer timezone in hours
320 tzone date string timezone string
321 szone date integer timezone explicit?
322 (1=explicit,0=implicit,\-1=unknown)
323 date2local date coerce date to local timezone
324 date2gmt date coerce date to GMT
325 dst date integer daylight savings in effect? (0 or 1)
326 clock date integer seconds since the UNIX epoch
327 rclock date integer seconds prior to current time
328 tws date string official 822 rendering
329 pretty date string user-friendly rendering
333 These functions require an address component as an argument.
334 The return value of functions noted with `*' is computed from
335 the first address present in the header component.
339 .ta \w'Fformataddr 'u +\w'Aboolean 'u +\w'Rboolean 'u
340 .I Function Argument Return Description
341 proper addr string official 822 rendering
342 friendly addr string user-friendly rendering
343 addr addr string mbox@host or host!mbox rendering*
344 pers addr string the personal name*
345 note addr string commentary text*
346 mbox addr string the local mailbox*
347 mymbox addr integer List has the user's address? (0 or 1)
348 host addr string the host domain*
349 nohost addr integer no host was present (0 or 1)*
350 type addr integer host type* (0=local,1=network,
352 path addr string any leading host route*
353 ingrp addr integer address was inside a group (0 or 1)*
354 gname addr string name of group*
358 (A clarification on (\fImymbox\fR\^{\fIcomp\fR\^}) is in order.
359 This function checks each of the addresses in the header component
360 \*(lq\fIcomp\fR\*(rq against the user's mailbox name and any
361 .RI \*(lq Alternate-Mailboxes \*(rq.
362 It returns true if any address matches,
363 however, it also returns true if the \*(lq\fIcomp\fR\*(rq header is not
364 present in the message. If needed, the (\fInull\fR\^) function can be
365 used to explicitly test for this case.)
367 When a function or component escape is interpreted and the result will
368 be immediately printed, an optional field width can be specified to
369 print the field in exactly a given number of characters. For example, a
370 numeric escape like %4(\fIsize\fR\^) will print at most 4 digits of the
371 message size; overflow will be indicated by a `?' in the first position
372 (like `?234'). A string escape like %4(\fIme\fR\^) will print the first 4
373 characters and truncate at the end. Short fields are padded at the right
374 with the fill character (normally, a blank). If the field width argument
375 begins with a leading zero, then the fill character is set to a zero.
377 The functions (\fIputnumf\fR\^) and (\fIputstrf\fR\^)
378 print their result in exactly the number of characters
379 specified by their leading field width argument. For example,
380 %06(\fIputnumf\fR\^(\fIsize\fR\^)) will print the message
381 size in a field six characters wide filled with leading zeros;
382 %14(\fIputstrf\^\fR{\fIfrom\^\fR}) will print the \*(lqFrom:\*(rq header
383 component in fourteen characters with trailing spaces added as needed.
384 For \fIputstrf\fR, using a negative value for the field width causes
385 right-justification of the string within the field, with padding on
386 the left up to the field width.
387 The functions (\fIputnum\fR\^) and
388 (\fIputstr\fR\^) are somewhat special: they print their result in the minimum number of characters
389 required, and ignore any leading field width argument.
391 The available output width is kept in an internal register; any output
392 past this width will be truncated.
394 With all this in mind,
395 here's the default format string for
397 It's been divided into several pieces for readability.
402 %4(msg)%<(cur)+%| %>%<{replied}\-%?{encrypted}E%| %>
406 which says that the message number should be printed in four digits.
407 If the message is the current message then a `+' else a space should
408 be printed; if a \*(lqReplied:\*(rq field is present then a `\-'
409 else if an \*(lqEncrypted:\*(rq field is present then an `E' otherwise
410 a space should be printed. Next:
414 %02(mon{date})/%02(mday{date})
418 the month and date are printed in two digits (zero filled) separated by
427 If a \*(lqDate:\*(rq field was present,
428 then a space is printed, otherwise a `*'.
433 %<(mymbox{from})%<{to}To:%14(decode(friendly{to}))%>%>
437 if the message is from me, and there is a \*(lqTo:\*(rq header,
438 print \*(lqTo:\*(rq followed by a \*(lquser-friendly\*(rq rendering of the
439 first address in the \*(lqTo:\*(rq field; any MIME-encoded
440 characters are decoded into the actual characters.
445 %<(zero)%17(decode(friendly{from}))%>
449 if either of the above two tests failed,
450 then the \*(lqFrom:\*(rq address is printed
451 in a mime-decoded, \*(lquser-friendly\*(rq format.
456 %(decode{subject})%<{body}<<%{body}>>%>
460 the mime-decoded subject and initial body (if any) are printed.
462 For a more complicated example, next consider
469 %(lit)%(formataddr %<{reply-to}
475 and formats the \*(lqReply-To:\*(rq header
476 if present. If not present, the else-if clause is executed.
480 %?{from}%?{sender}%?{return-path}%>)\\
485 \*(lqFrom:\*(rq, \*(lqSender:\*(rq and \*(lqReturn-Path:\*(rq
486 headers, stopping as soon as one of them is present. Next:
490 %<(nonnull)%(void(width))%(putaddr To: )\\n%>\\
494 If the \fIformataddr\fR result is non-null, it is printed as
495 an address (with line folding if needed) in a field \fIwidth\fR
496 wide with a leading label of \*(lqTo:\*(rq.
500 %(lit)%(formataddr{to})%(formataddr{cc})%(formataddr(me))\\
505 is cleared, and the \*(lqTo:\*(rq and \*(lqCc:\*(rq headers, along with the user's
506 address (depending on what was specified with
507 the \*(lq\-cc\*(rq switch to \fIrepl\fR\^) are formatted.
511 %<(nonnull)%(void(width))%(putaddr cc: )\\n%>\\
515 If the result is non-null, it is printed as above with a
516 leading label of \*(lqCc:\*(rq.
520 %<{fcc}Fcc: %{fcc}\\n%>\\
531 for more details about %{\fIfcc\fR\^}),
532 an \*(lqFcc:\*(rq header is output.
536 %<{subject}Subject: Re: %{subject}\\n%>\\
540 If a subject component was present,
541 a suitable reply subject is output.
545 %<{message-id}In-Reply-To: %{message-id}\\n%>\\
546 %<{message-id}References: %<{references} %{references}%>\\
552 If a message-id component was present, an \*(lqIn-Reply-To:\*(rq header is
553 output including the message-id, followed by a \*(lqReferences:\*(rq
554 header with references, if present, and the message-id.
556 plain-text, the row of dashes are output as-is.
558 This last part is a good example for a little more elaboration.
559 Here's that part again in pseudo-code:
564 if (comp_exists(message-id)) then
565 print (\*(lqIn-reply-to: \*(rq)
566 print (message-id.value)
567 print (\*(lq\\n\*(rq)
569 if (comp_exists(message-id)) then
570 print (\*(lqReferences: \*(rq)
571 if (comp_exists(references)) then
572 print(references.value);
574 print (message-id.value)
575 print (\*(lq\\n\*(rq)
580 .\" (Note that this pseudocode begs the question ``why not just
581 .\" support this syntax?'' MH has been hacked on for a long time...)
583 One more example: Currently,
586 large message numbers, and it is not uncommon for a folder
587 to have far more than 10000 messages.
588 .\" (Indeed, the original MH
589 .\" tutorial document by Rose and Romine is entitled "How to
590 .\" process 200 messages a day and still get some real work
591 .\" done." The authors apparently only planned to get
592 .\" real work done for about 50 days per folder.)
593 Nontheless (as noted above)
594 the various scan format strings are inherited
595 from older MH versions, and are generally hard-coded to 4
596 digits of message number before formatting problems
598 The nmh format strings can be modified to behave more sensibly with larger
603 %(void(msg))%<(gt 9999)%(msg)%|%4(msg)%>
607 The current message number is placed in \fInum\fP.
610 is an int function, not a component.)
614 is used to test whether the message number
617 If so, it is printed at full width: otherwise
620 scan(1), repl(1), ap(8), dp(8)