4 .TH MH-FORMAT %manext5% "%nmhdate%" MH.6.8 [%nmhversion%]
6 mh-format \- format file for mh 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, e.g.
35 This manual section explains how to write and modify format commands.
36 Note: familiarity with the C
40 A format string consists of ordinary text, and special multi-character
41 escape sequences which begin with `%'. When specifying a format
42 string, the usual C backslash characters are honored: `\\b', `\\f',
43 `\\n', `\\r', and `\\t'. Continuation lines in format files end with
44 `\\' followed by the newline character.
46 .\" TALK ABOUT SYNTAX FIRST, THEN SEMANTICS
48 Format strings are built around
49 .IR "escape sequences" .
50 There are four types of escape sequences:
54 .ta +\w'name of escape class xxxxxxx'u
55 .RI "1) header components %{" component }
56 .RI "2) built-in functions %(" "function arg" )
57 .RI "3) flow control %< ... %? ... %| ... %>
58 .RI "4) comments %; ...
62 Comments may be inserted in most places where no function argument is
63 expected. A comment begins with `%;' and ends with a (non-escaped)
68 escape is specified as
71 exists for each header found in the message being processed. For example
73 refers to the `Date:' field of the appropriate message.
74 All component escapes have a string value. Normally, component values are
75 compressed by converting any control characters (tab and newline included)
76 to spaces, then eliding any leading or multiple spaces. However, commands
77 may give different interpretations to some component escapes; be sure
78 to refer to each command's manual entry for complete details.
82 escape is specified as
84 All functions are built-in, and most have a string or numeric value.
85 A function escape may have an
87 The argument follows the function escape: separating
88 whitespace is discarded:
89 .RI `%( function " " argument )'.
91 In addition to literal numbers or strings,
92 the argument to a function escape can be another function, a component,
93 or a control escape. When the argument is a function or a
94 component, they are listed without a leading `%'. When control escapes
95 are used as function arguments, they written as normally, with
102 escape is one of: `%<', `%?', `%|', or `%>'.
103 These are combined into the conditional execution construct:
107 .RI "%< " condition " " "format-text"
108 .RI "%? " condition " " "format-text"
110 .RI "%| " "format-text"
115 (Extra white space is shown here only for clarity.) These
116 constructs may be nested without ambiguity. They form a general
117 .B if\-elseif\-else\-endif
118 block where only one of the
120 is interpreted. In other
121 words, `%<' is like the "if", `%?' is like the "elseif", `%|' is like
122 "else", and `%>' is like "endif".
124 A `%<' or `%?' control escape causes its condition to be evaluated.
129 For integer valued functions or components, the condition is true
130 if the function return or component value is non-zero, and false if zero.
131 For string valued functions or components, the condition is true
132 if the function return or component value is
133 a non-empty string, and false for an empty string.
136 The `%?' control escape is optional, and there may be more
137 than one `%?' control escape in a conditional block.
138 The `%|' control escape
139 is also optional, but may be included at most once.
141 .SS "Function escapes"
142 Functions expecting an argument generally
143 require an argument of a particular type.
144 In addition to the number and string types,
149 .ta +\w'Argument 'u +\w'An optional component, 'u
150 .I "Argument Description Example Syntax
151 literal A literal number %(\fIfunc\fR 1234)
152 or string %(\fIfunc\fR text string)
153 comp Any component %(\fIfunc\fR\^{\fIin-reply-to\fR\^})
154 date A date component %(\fIfunc\fR\^{\fIdate\fR\^})
155 addr An address component %(\fIfunc\fR\^{\fIfrom\fR\^})
156 expr Nothing %(\fIfunc\fR)
157 or a subexpression %(\fIfunc\fR\^(\fIfunc2\fR\^))
158 or control escape %(\fIfunc\fR %<{\fIreply-to\fR\^}%|%{\fIfrom\fR\^}%>)
166 have the same syntax as
168 but require that the header component be a date string, or address
169 string, respectively.
171 Most arguments not of type
174 When escapes are nested (via expr arguments), evaluation is done from inner-most to outer-most.
175 As noted above, for the
178 functions and components are written without a
180 Control escape arguments must use a leading `%', preceded by a space.
186 %<(mymbox{from}) To: %{to}%>
190 writes the value of the header component `From:' to the
191 internal register named str; then (\fImymbox\fR\^) reads str and
192 writes its result to the internal register named
194 then the control escape evaluates
199 string `To:' is printed followed by the value of the
200 header component `To:'.
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
206 has an integer register
208 and a text string register
210 When a function escape that
211 accepts an optional argument is processed,
212 and the argument is not present, the current value of either
216 is used as the argument: which register is
217 used depends on the function, as listed below.
219 Component escapes write the value of their message header in
221 Function escapes write their return value in
223 for functions returning integer or boolean values, and in
225 for functions returning string values. (The boolean type is a subset
226 of integers with usual values 0=false and 1=true.) Control escapes
227 return a boolean value, setting
229 to 1 if the last explicit condition
230 evaluated by a `%<' or `%?' control
231 succeeded, and 0 otherwise.
233 All component escapes, and those function escapes which return an
234 integer or string value, evaluate to their value as well as setting
238 Outermost escape expressions in
239 these forms will print
240 their value, but outermost escapes which return a boolean value
241 do not result in printed output.
243 The function escapes may be roughly grouped into a few categories.
247 .ta \w'Fformataddr 'u +\w'Aboolean 'u +\w'Rboolean 'u
248 .I "Function Argument Result Description
249 msg integer message number
250 cur integer message is current (0 or 1)
251 unseen integer message is unseen (0 or 1)
252 size integer size of message
253 strlen integer length of \fIstr\fR
254 width integer output buffer size in bytes
255 charleft integer bytes left in output buffer
256 timenow integer seconds since the UNIX epoch
257 me string the user's mailbox
258 eq literal boolean \fInum\fR == \fIarg\fR
259 ne literal boolean \fInum\fR != \fIarg\fR
260 gt literal boolean \fInum\fR > \fIarg\fR
261 match literal boolean \fIstr\fR contains \fIarg\fR
262 amatch literal boolean \fIstr\fR starts with \fIarg\fR
263 plus literal integer \fIarg\fR plus \fInum\fR
264 minus literal integer \fIarg\fR minus \fInum\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
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 `\fBatoi\fR(\fIcomp\fR\^)'
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 and print it
286 unquote expr string remove RFC-2822 quotes from \fIstr\fR
287 trim expr trim trailing white-space from \fIstr\fR
288 putstr expr print \fIstr\fR
289 putstrf expr print \fIstr\fR in a fixed width
290 putnum expr print \fInum\fR
291 putnumf expr print \fInum\fR in a fixed width
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
301 The following functions require a date component as an argument:
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 RFC-822 rendering
331 pretty date string user-friendly rendering
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.
341 .ta \w'Fformataddr 'u +\w'Aboolean 'u +\w'Rboolean 'u
342 .I "Function Argument Return Description
343 proper addr string official RFC-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,
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*
360 (A clarification on (\fImymbox\fR\^{\fIcomp\fR\^}) is in order.
361 This function checks each of the addresses in the header component
362 `\fIcomp\fR' against the user's mailbox name and any
363 .RI ` Alternate-Mailboxes '.
364 It returns true if any address matches,
365 however, it also returns true if the `\fIcomp\fR' header is not
366 present in the message. If needed, the (\fInull\fR\^) function can be
367 used to explicitly test for this case.)
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.
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 `From:' 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. The functions (\fIputnum\fR\^) and
389 (\fIputstr\fR\^) are somewhat special: they print their result in
390 the minimum number of characters required, and ignore any leading
391 field width argument.
393 The available output width is kept in an internal register; any output
394 past this width will be truncated.
396 With all this in mind, here's a format string for
398 It's been divided into several pieces for readability.
403 %4(msg)%<(cur)+%| %>%<{replied}\-%| %>
407 which says that the message number should be printed in four digits.
408 If the message is the current message then a `+' else a space should
409 be printed; if a `Replied:' field is present then a `\-'
410 else 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 `Date:' 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 `To:' header,
438 print `To:' followed by a `user-friendly' rendering of the
439 first address in the `To:' 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 `From:' address is printed
451 in a mime-decoded, `user-friendly' format.
460 the mime-decoded subject is printed.
462 For a more complicated example, next consider
469 %(lit)%(formataddr %<{reply-to}
475 and formats the `Reply-To:' header
476 if present. If not present, the else-if clause is executed.
480 %?{from}%?{sender}%?{return-path}%>)\\
485 `From:', `Sender:' or `Return-Path:'
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 `To:'.
500 %(lit)%(formataddr{to})%(formataddr{cc})%(formataddr(me))\\
505 is cleared, and the `To:' and `Cc:' headers, along with the user's
506 address (depending on what was specified with
507 the `\-cc' 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 `Cc:'.
520 %<{subject}Subject: Re: %(decode{subject})\\n%>\\
524 If a subject component was present,
525 a suitable reply subject is output.
529 %<{message-id}In-Reply-To: %{message-id}\\n%>\\
530 %<{message-id}References: %<{references} %{references}%>\\
536 If a message-id component was present, an `In-Reply-To:' header is
537 output including the message-id, followed by a `References:'
538 header with references, if present, and the message-id.
540 plain-text, the row of dashes are output as-is.
542 This last part is a good example for a little more elaboration.
543 Here's that part again in pseudo-code:
548 if (comp_exists(message-id)) then
549 print("In-reply-to: ")
550 print(message-id.value)
553 if (comp_exists(message-id)) then
554 print("References: ")
555 if (comp_exists(references)) then
556 print(references.value);
558 print(message-id.value)
564 .\" (Note that this pseudocode begs the question ``why not just
565 .\" support this syntax?'' MH has been hacked on for a long time...)
570 large message numbers, and it is not uncommon for a folder
571 to have far more than 10000 messages.
572 .\" (Indeed, the original MH
573 .\" tutorial document by Rose and Romine is entitled "How to
574 .\" process 200 messages a day and still get some real work
575 .\" done." The authors apparently only planned to get
576 .\" real work done for about 50 days per folder.)
577 Nonetheless several scan format strings are inherited
578 from older MH versions, and are generally hard-coded to 4
579 digits of message number before formatting problems
581 The mh format strings can be modified to behave more sensibly with larger
586 %(void(msg))%<(gt 9999)%(msg)%|%4(msg)%>
590 The current message number is placed in \fInum\fP.
593 is an int function, not a component.)
597 is used to test whether the message number
600 If so, it is printed at full width: otherwise
603 scan(1), repl(1), ap(8), dp(8)