# cd /etc/mail
# cat realnames
dan Dan.Scribner
tyler Tyler.McCafferty
pat Pat.Stover
willy Bill.Wright
craig Craig.Hunt
# makemap hash realnames < realnames
Once the database is created, define it for sendmail. Use the
K command to do this. To use the database that we
have just built, insert the following lines into the Local
Information section of the sendmail.cf file:
# define a database to map login names to firstname.lastname
Krealnames hash /etc/mail/realnames
The K command defines
realnames as the internal sendmail name of this
database. Further, it identifies that this is a database of type
hash and that the path to the database is
/etc/realnames. sendmail adds the correct
filename extensions to the pathname depending on the type of the
database, so you don't need to worry about it.
Finally, we add a new rule that uses the database to rewrite
addresses. We add it to ruleset EnvFromSMTP and ruleset HdrFromSMTP
immediately after the lines in those rulesets that call ruleset
asqHdr. This way, our new rule gets the address as soon as ruleset
asqHdr finishes processing it.
# when masquerading convert login name to firstname.lastname
R$-<@$M.>$* $:$(realnames $1 $)<@$M.>$2 user=>first.last
This rule is designed to process the output of ruleset MasqHdr, which
rewrites the hostname portion of the address. Addresses that meet the
criteria to have the hostname part rewritten are also the addresses
for which we want to rewrite the user part. Look at the output of
ruleset MasqHdr from the earlier test. That address,
craig<@wrotethebook.com.>, matches the
pattern $-<@$M.>$*. The address has exactly
one token (craig) before the literal <@, followed by the value of
(wrotethebook.com), the literal .>, and zero tokens.
The transformation part of this rule takes the first token ($1) from
the input address and uses it as the key to the
realnames database, as indicated by the
$:$(realnames $1
$) syntax. For the sample address
craig<@wrotethebook.com>, $1 is
craig. When used as an index into the database
realnames shown at the beginning of this
section, it returns Craig.Hunt. This returned
value is prepended to the literal <@, the value of macro M
($M), the literal .>, and the value of $2, as
indicated by the <@$M.>$2 part of the
transformation. The effect of this new rule is to convert the
username to the user's real first and last names.
After adding the new rule to rulesets EnvFromSMTP and HdrFromSMTP, a
test yields the following results:
# sendmail -bt -Ctest.cf
ADDRESS TEST MODE (ruleset 3 NOT automatically invoked)
Enter <ruleset> <address>
> /tryflags HS
> /try esmtp craig
Trying header sender address craig for mailer esmtp
canonify input: craig
Canonify2 input: craig
Canonify2 returns: craig
canonify returns: craig
1 input: craig
1 returns: craig
HdrFromSMTP input: craig
PseudoToReal input: craig
PseudoToReal returns: craig
asqSMTP input: craig
asqSMTP returns: craig < @ *LOCAL* >
asqHdr input: craig < @ *LOCAL* >
asqHdr returns: craig < @ wrotethebook . com . >
HdrFromSMTP returns: Craig . Hunt < @ wrotethebook . com . >
final input: Craig . Hunt < @ wrotethebook . com . >
final returns: Craig . Hunt @ wrotethebook . com
Rcode = 0, addr = Craig.Hunt@wrotethebook.com
> /tryflags ES
> /try esmtp craig
Trying envelope sender address craig for mailer esmtp
canonify input: craig
Canonify2 input: craig
Canonify2 returns: craig
canonify returns: craig
1 input: craig
1 returns: craig
EnvFromSMTP input: craig
PseudoToReal input: craig
PseudoToReal returns: craig
asqSMTP input: craig
asqSMTP returns: craig < @ *LOCAL* >
asqEnv input: craig < @ *LOCAL* >
asqHdr input: craig < @ *LOCAL* >
asqHdr returns: craig < @ wrotethebook . com . >
asqEnv returns: craig < @ wrotethebook . com . >
EnvFromSMTP returns: Craig . Hunt < @ wrotethebook . com . >
final input: Craig . Hunt < @ wrotethebook . com . >
final returns: Craig . Hunt @ wrotethebook . com
Rcode = 0, addr = Craig.Hunt@wrotethebook.com
> /quit
If the tests do not give the results you want, make sure that you
have correctly entered the new rewrite rules and that you have
correctly built the database. The following error message could also
be displayed:
test.cf: line 116: readcf: map realnames: class hash not available