Reworked test-rcvdist so that it sees the output of post.
[mmh] / man / mh-format.man
index 8925b8c..1063b0d 100644 (file)
@@ -1,5 +1,5 @@
 .\"
-.\" THIS FILE HAS BEEN AUTOMATICALLY GENERATED.  DO NOT EDIT.
+.\" %nmhwarning%
 .\"
 .TH MH-FORMAT %manext5% "%nmhdate%" MH.6.8 [%nmhversion%]
 .SH NAME
@@ -73,7 +73,15 @@ All component escapes have a string value.  Normally, component values are
 compressed by converting any control characters (tab and newline included)
 to spaces, then eliding any leading or multiple spaces.  However, commands
 may give different interpretations to some component escapes; be sure
-to refer to each command's manual entry for complete details.
+to refer to each command's manual entry for complete details.  Some commands
+(such as
+.B ap
+and
+.BR mhl )
+use a special component
+.RI `%{ text }'
+to refer to the text being processed; see their respective man pages for
+details and examples.
 .PP
 A
 .I function
@@ -145,7 +153,7 @@ these include:
 .RS 5
 .nf
 .ta +\w'Argument 'u +\w'An optional component, 'u
-.I Argument    Description     Example Syntax
+.I "Argument   Description     Example Syntax"
 literal        A literal number        %(\fIfunc\fR 1234)
        or string               %(\fIfunc\fR text string)
 comp   Any component           %(\fIfunc\fR\^{\fIin-reply-to\fR\^})
@@ -243,7 +251,7 @@ The function escapes may be roughly grouped into a few categories.
 .RS 5
 .nf
 .ta \w'Fformataddr 'u +\w'Aboolean 'u +\w'Rboolean 'u
-.I Function    Argument   Result       Description
+.I "Function   Argument   Result       Description"
 msg            integer message number
 cur            integer message is current (0 or 1)
 unseen         integer message is unseen (0 or 1)
@@ -252,7 +260,10 @@ strlen             integer length of \fIstr\fR
 width          integer output buffer size in bytes
 charleft               integer bytes left in output buffer
 timenow                integer seconds since the UNIX epoch
-me             string  the user's mailbox
+me             string  the user's mailbox (username)
+myhost         string  the user's local hostname
+myname         string  the user's name
+localmbox              string  the complete local mailbox
 eq     literal boolean \fInum\fR == \fIarg\fR
 ne     literal boolean \fInum\fR != \fIarg\fR
 gt     literal boolean \fInum\fR > \fIarg\fR
@@ -288,21 +299,50 @@ putstrf   expr            print \fIstr\fR in a fixed width
 putnum expr            print \fInum\fR
 putnumf        expr            print \fInum\fR in a fixed width
 .\" addtoseq literal    add msg to sequence (LBL option)
+putlit expr            print \fIstr\fR without space compression
 nodate string  integer Argument not a date string (0 or 1)
 formataddr     expr            append \fIarg\fR to \fIstr\fR as a
                        (comma separated) address list
+concataddr     expr            append \fIarg\fR to \fIstr\fR as a
+                       (comma separated) address list,
+                       including duplicates,
+                       see Special Handling
 putaddr        literal         print \fIstr\fR address list with
                        \fIarg\fR as optional label;
                        get line width from \fInum\fR
 .fi
 .RE
 .PP
+The (\fIme\fR\^) function returns the username of the current user.  The
+(\fImyhost\fR\^) function returns the
+.B localname
+entry in
+.IR mts.conf ,
+or the local hostname if
+.B localname
+is not configured.  The (\fImyname\fR\^) function will return the value of
+the
+.B SIGNATURE
+environment variable if set, otherwise will return the passwd GECOS field
+(truncated at the first comma if it contains one) for
+the current user.  The (\fIlocalmbox\fR\^) function will return the complete
+form of the local mailbox, suitable for use in a \*(lqFrom\*(rq header.
+It will return the
+.RI \*(lq Local-Mailbox \*(rq
+profile entry if it is set; if it is not, it will be equivalent to:
+.PP
+.RS 5
+.nf
+%(myname) <%(me)@%(myhost)>
+.fi
+.RE
+.PP
 The following functions require a date component as an argument:
 .PP
 .RS 5
 .nf
 .ta \w'Fformataddr 'u +\w'Aboolean 'u +\w'Rboolean 'u
-.I Function    Argument        Return  Description
+.I "Function   Argument        Return  Description"
 sec    date    integer seconds of the minute
 min    date    integer minutes of the hour
 hour   date    integer hours of the day (0-23)
@@ -338,7 +378,7 @@ the first address present in the header component.
 .RS 5
 .nf
 .ta \w'Fformataddr 'u +\w'Aboolean 'u +\w'Rboolean 'u
-.I Function    Argument        Return  Description
+.I "Function   Argument        Return  Description"
 proper addr    string  official 822 rendering
 friendly       addr    string  user-friendly rendering
 addr   addr    string  mbox@host or host!mbox rendering*
@@ -387,10 +427,98 @@ right-justification of the string within the field, with padding on
 the left up to the field width.
 The functions (\fIputnum\fR\^) and
 (\fIputstr\fR\^) are somewhat special: they print their result in the minimum number of characters
-required, and ignore any leading field width argument.
+required, and ignore any leading field width argument.  The (\fIputlit\fR\^)
+function outputs the exact contents of str register without any changes
+such as duplicate space removal or control character conversion.
 .PP
 The available output width is kept in an internal register; any output
 past this width will be truncated.
+.SS Special Handling
+A few functions have different behavior depending on what command they are
+being invoked from.
+.PP
+In
+.BR repl
+the (\fIformataddr\fR\^) function stores all email addresses encountered into
+an internal cache and will use this cache to suppress duplicate addresses.
+If you need to create an address list that includes previously-seen
+addresses you may use the (\fIconcataddr\fR\^) function, which is identical
+to (\fIformataddr\fR\^) in all other respects.  Note that (\fIconcataddr\fR\^)
+will NOT add addresses to the duplicate-suppression cache.
+.SS Other Hints and Tips
+Sometimes to format function writers it is confusing as to why output is
+duplicated.  The general rule to remember is simple: If a function or
+component escape is used where it starts with a %, then it will generate
+text in the output file.  Otherwise, it will not.
+.PP
+A good example is a simple attempt to generate a To: header based on
+the From: and Reply-To: headers:
+.PP
+.RS 5
+.nf
+%(formataddr %<{reply-to}%|%{from})%(putaddr To: )
+.fi
+.RE
+.PP
+Unfortuantely if the Reply-to: header is NOT present, the output line that is
+generated will be something like:
+.PP
+.RS 5
+.nf
+My From User <from@example.com>To: My From User <from@example.com>
+.fi
+.RE
+.PP
+What went wrong?  When performing the test for the
+.B if
+clause (%<), the component is not output because it is considered an
+argument to the
+.B if
+statement (hence the rule about the lack of % applies).  But the component
+escape in our
+.B else
+statement (everything after the `%|') is NOT an argument to anything; the
+syntax is that it is written with a %, and thus the value of that component
+is output.  This also has the side effect of setting the 
+.I str
+register, which is later picked up by the (\fIformataddr\fR\^) function
+and then output by (\fIputaddr\fR\^).  This format string has another bug
+as well; there should always be a valid width value in the
+.I num
+register when (\fIputaddr\fR\^) is called, otherwise bad formatting can take
+place.
+.PP
+The solution is to use the (\fIvoid\fR\^) function; this will prevent the
+function or component from outputting any text.  With this in place (and
+using (\fIwidth\fR\^) to set the
+.I num
+register for the width, a better implementation would look like:
+.PP
+.RS 3
+.nf
+%(formataddr %<{reply-to}%|%(void{from})%(void(width))%(putaddr To: )
+.fi
+.RE
+.PP
+It should be noted here that the side-effects of functions and component
+escapes still are in force: as a result each component
+test in the 
+.B if\-elseif\-else\-endif
+clause sets the
+.I str
+register.
+.PP
+As an additional note, the (\fIformataddr\fR\^) and (\fIconcataddr\fR\^)
+functions have some behavior when it comes to the
+.I str
+register.  The starting point of the register is saved and is used to
+build up entries in the address list.
+.PP
+You will find the
+.B ap
+and
+.B fmtdump
+utilities invaluable in debugging problems with format strings.
 .SS Examples
 With all this in mind,
 here's the default format string for