* Copyright (c) 1983 Eric P. Allman
* Copyright (c) 1988, 1993
* The Regents of the University of California. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
static char sccsid
[] = "@(#)macro.c 8.1 (Berkeley) 6/7/93";
** EXPAND -- macro expand a string using $x escapes.
** s -- the string to expand.
** buf -- the place to put the expansion.
** buflim -- the buffer limit, i.e., the address
** of the last usable position in buf.
** e -- envelope in which to work.
expand(s
, buf
, buflim
, e
)
bool skipping
; /* set if conditionally skipping output */
bool recurse
= FALSE
; /* set if recursion required */
int iflev
; /* if nesting level */
for (xp
= xbuf
; *s
!= '\0'; s
++)
** Check for non-ordinary (special?) character.
** 'q' will be the interpolated quantity.
case CONDIF
: /* see if var set */
skipping
= macvalue(c
, e
) == NULL
;
case CONDELSE
: /* change state of skipping */
case CONDFI
: /* stop skipping */
case MACROEXPAND
: /* macro interpolation */
q
= macvalue(c
& 0177, e
);
** Interpolate q or output one character
if (skipping
|| xp
>= &xbuf
[sizeof xbuf
])
/* copy to end of q or max space remaining in buf */
while ((c
= *q
++) != '\0' && xp
< &xbuf
[sizeof xbuf
- 1])
/* check for any sendmail metacharacters */
/* recurse as appropriate */
expand(xbuf
, buf
, buflim
, e
);
** DEFINE -- define a macro.
** this would be better done using a #define macro.
** e -- the envelope to store the definition in.
** e->e_macro[n] is defined.
** There is one macro for each ASCII character,
** although they are not all used. The currently
** $a date in ARPANET format (preferring the Date: line
** $b the current date (as opposed to the date as found
** the message) in ARPANET format
** $d (current) date in UNIX (ctime) format
** $e the SMTP entry message+
** $g translated from address
** $j official SMTP hostname, used in messages+
** $l UNIX-style from line+
** $m The domain part of our full name.
** $n name of sendmail ("MAILER-DAEMON" on local
** $o delimiters ("operators") for address tokens+
** $p my process id in decimal
** $q the string that becomes an address -- this is
** normally used to combine $g & $x.
** $r protocol used to talk to sender
** $t the current time in seconds since 1/1/1970
** $v version number of sendmail
** $w our host name (if it can be determined)
** $x signature (full name) of from person
** $y the tty id of our terminal
** $z home directory of to person
** $_ RFC1413 authenticated sender address
** Macros marked with + must be defined in the
** configuration file and are used internally, but
** There are also some macros that can be used
** arbitrarily to make the configuration file
** cleaner. In general all upper-case letters
printf("define(%c as ", n
);
e
->e_macro
[n
& 0177] = v
;
** MACVALUE -- return uninterpreted value of a macro.
** n -- the name of the macro.
register char *p
= e
->e_macro
[n
];