[comp.mail.sendmail] Full name expansion in From: header

jonathan@cs.kl.ac.uk (Jonathan Knight) (11/10/90)

I have been driven nuts trying to make sendmail put my full
name on the From: header line.

I have the mailer specification and flags from UK-sendmail-2.1 and Sun's
examples.  I'm running on sun4 and sun3's under OS4.1

The problem I see is that any email which originates locally and is
delivered locally appears with a from line with the full email
address and full name on.  Any email sent to another host is
delivered without the full name.  It appears that sendmail has
declared that the 'x' macro is undefined in these circumstances.

If you want the config file, it's below.

The configuration is a sun4 fileserver with sun3 and sun4 clients.
The sun3's and 4's nfs mount /var/spool/mail without root access so
all mail must be delivered on the server (doc).  We also have
a microvax called derek which handles our external mail.

I've tried the 'R' option that sun have, but that causes sendmail
to omit all headers that are not part of the message and I get no
'From:' line at all.

If you have a moment to scan through I'd appreciate any hints
-- 
  ______    JANET :jonathan@uk.ac.keele.cs     Jonathan Knight,
    /       BITNET:jonathan%cs.kl.ac.uk@ukacrl Department of Computer Science
   / _   __ other :jonathan@cs.keele.ac.uk     University of Keele, Keele,
(_/ (_) / / UUCP  :...!ukc!kl-cs!jonathan      Staffordshire.  ST5 5BG.  U.K.

# This is sendmail.cf for the CS Departments mail server and clients.
# (JWK Nov 90)
#
# The server version of this file is created by removing the text #SERVER#
# from the start of the line.  The client version is created by removing
# the text #CLIENT#
#
# This configuration assumes that all clients and the server are
# sharing an NFS spool directory.  All the machines have write
# access to the directory, but not necessarily as root.  It seems
# that /bin/mail is capable of delivering mail when it does not
# have root access.
#
# All outbound mail is sent to a smart mailer

# Set up the things we must.
# Dues to a bug in sendmail we have to explicity tell it our hostname.
# Set the welcome message, the user from whom errors are sent, the format
# of the from header, the delimiters and the format of the sender name

Dmcs.keele.ac.uk
Dj$w.$m
De$j   Department of Computer Science\, University of Keele.
DnPOSTMASTER
DlFrom $g  $d
Do%@!.:^=/[]~
Dq$?x$x  <$g>$|$g$.

# Host to send mail to when we don't want to deal with it here.
# This host must not send mail back here unless it's for our domain
# M is its ethernet name and F is its full name.

DMderek
DFderek.cs.keele.ac.uk

# The clients have a tough life and can't really deliver stuff into
# the spool directory reliably.  Sun have provided an 'R' option
# which is supposed to do the trick, but it doesn't process the headers
# and in general leaves things in a bit of a mess, so we have two
# versions of the configuration file.  One for the server which has
# a local mailer and one for the client which sends it to the server
# for delivery.  The S macro defines that server.

DSdoc

# Define all our local names.  Add machines here to make sendmail
# deliver the mail on this machine.  Our domain name will always
# be delivered locally.  The name + domain will be tried.

CN adam bing elvis des happy sleepy grumpy doc
CN alpha beta gamma

# Define special case names.  Mail for These should be sent to the host listed.
# These are tried with the domain name.  It should be noted that mail for these
# hosts and those in the 'N' class above will have a from line of
# 'user@doc.cs.keele.ac.uk' so that the reply will arrive in the right place.
# If a user specifies a machine with 'cs.keele.ac.uk' as the domain then
# this too will arrive with doc.cs.keele.ac.uk as the domain.  Any other
# machine will be assumed to be outside the dept of CS and the mail
# will appear to come from 'cs.keele.ac.uk'.  Therefore if a dept of CS
# machine is added, it must be placed in either the N class above or
# the S class below if the reply address is to be correct.

CS derek annie zarick

# Option setting - This config file runs on all machines, so the 
# idea is that the options should be suitable for clients as well
# as the server.  Note we do not use the R option.  It doesn't
# work very well (headers get missed out) and we don't need it anyway.

# Where the alias file is at.
OA/etc/aliases

# Wait 15 mins for the alias file to rebuild
Oa15m

# Disallow empty messages to more than 1 recipient.  Allow 1
# because it may be a mail server that reads the subject line.
# Any more than that has to be a mistake on the part of the sender
Ob1

# To stop sendmail repeating messages to vast numbers of people
# because of some failure on one entry in a list of recipients
# we can tell sendmail to checkpoint the queue.
OC5

# Deliver all mail asynchronously.  (ie go into the background)
Odbackground

# Mail errors back.  Writing on the terminal may confuse the user.
Oem

# Keep queue files private
OF0600

# The help file
OH/usr/lib/sendmail.hf

# Set hop count high as some UUCP stuff takes a lot of hops to get here
Oh30

# Set logging level to 9
OL9

# We may get old header formats.  /bin/mail is a likely candidate
# (also old crufty V7 lovers)
Oo

# Our local postman Pat
OPPostmaster

# The spool directory
OQ/usr/spool/mqueue

# Read timeouts can be short.  We're on an ethernet so there's no
# excuse for sluggish transfers
Or5m

# Where the status file is.
OS/etc/sendmail.st

# Timeout for the queue will be short.  Users tend to assume that
# a message is succesful unles told otherwise.  Three days is a long
# time to wait for an error.
OT6h

# Default userid for mailers
Ou1

# Don't refuse incomming messages ever, but queue up if load goes above 2
Ox2

# Define the trusted users.  We'll trust root and daemon.
T root daemon

# Define the mailers.  We have ethernet, local and a program.
# We also have a mailer called 'outside' which rips off our
# machine name and just leaves the domain.

Mether,	  P=[TCP],	F=nsmFDMuXC,	A=TCP $h, S=13
Moutside, P=[TCP],	F=nsmFDMuXC,	A=TCP $h, S=12
Mlocal,	  P=/bin/mail,	F=rnlsmFDM,	A=mail -d $u
Mprog,	  P=/bin/sh,	F=lsDFMeu,	A=sh -c $u

# Define the headers
HFrom: $q
H?D?Date: $a
H?M?Message-Id: <$p.$t@$j>
H?F?Resent-From: $q
H?D?Resent-Date: $b
H?M?Resent-Message-Id: <$p.$t@$j>
HSubject:
HReceived: $?sfrom $s by $j; $b$.

# Now comes the tricky bit.  These are the rulesets that define how
# sendmail reacts to various addresses.  Remember that the tactic
# is to recognise local stuff and deliver it straight into spool area.
# All non-local stuff is sent off to a mail server.  Hosts in our domain
# but not served by our cluster are sent via SMTP

# Ruleset 0
# 
# Resolve an address to a mailer.

S0

# What we do here is try and recognise the address that's already been
# through ruleset 3 and 2.  As 11 rips off all the local domain
# part, anything with an @ left in it must be for another machine.
# As $S is the server and no other machine can write to /var/spool/mail
# we send all client mail (including local mail) to doc for delivery.

R$*				$:$>11$1
R$+@$=S.$m			$#ether$@$2$:$1
R$+@$+				$#outside$@$M$:$1@$2
R$*@$*				$#error$:Malformed address
#CLIENT#R$*				$#ether$@$S$:$1
#SERVER#R$*				$#local$:$1

# Ruleset 1
#
# This is applied to the sender address.

S1

R$+@$+				$@$1@$2
R$+				$:$1@$j

# Ruleset 2
#
# Applied to recipient address.

S2

# Ruleset 3
#
# Turn address into canonical form.  Applied to all addresses.
# This is where we turn everything into user@host.domain

S3

R$-			$@$1
R$*<$*>$*		$2
R$+!$+			$:$>10$1!$2
R$+%$+			$1@$2
R$+@$+@$+		$1%$2@$3

# Ruleset 4
#
# This is applied to all names in the message.  It is applied last

S4

#----------------------------------------------------------------------

# Ruleset 10
#
# Called from ruleset 3 when a UUCP address is discovered

S10

R$+%$+			$1@$2
R$+!$+@$+		$2@$1@$3
R$+!$+			$:$>10$2@$1

# Ruleset 11
#
# Local domain removal

S11

# Look for me a rip me off the list

R$+@cs.keele.ac.uk		$:$1
R$+@cs.keele.ac			$:$1
R$+@cs.keele			$:$1
R$+@cs				$:$1
R$+@cs.kl.ac.uk			$:$1
R$+@cs.kl.ac			$:$1
R$+@cs.kl			$:$1
R$+@uk.ac.keele.cs		$:$1
R$+@ac.keele.cs			$:$1
R$+@keele.cs			$:$1
R$+@uk.ac.kl.cs			$:$1
R$+@ac.kl.cs			$:$1
R$+@kl.cs			$:$1

R$+@$=N.cs.keele.ac.uk		$:$1
R$+@$=N.cs.keele.ac		$:$1
R$+@$=N.cs.keele		$:$1
R$+@$=N.cs			$:$1
R$+@$=N				$:$1
R$+@$=N.cs.kl.ac.uk		$:$1
R$+@$=N.cs.kl.ac		$:$1
R$+@$=N.cs.kl			$:$1
R$+@uk.ac.keele.cs.$=N		$:$1
R$+@ac.keele.cs.$=N		$:$1
R$+@keele.cs.$=N		$:$1
R$+@uk.ac.kl.cs.$=N		$:$1
R$+@ac.kl.cs.$=N		$:$1
R$+@kl.cs.$=N			$:$1

R$+@kl-cs			$:$1
R$+@kl-cs.uucp			$:$1
R$+@uucp.kl-cs			$:$1

R$+@$=S.cs.keele.ac		$:$1@$2.$m
R$+@$=S.cs.keele		$:$1@$2.$m
R$+@$=S.cs			$:$1@$2.$m
R$+@$=S				$:$1@$2.$m
R$+@$=S.cs.kl.ac.uk		$:$1@$2.$m
R$+@$=S.cs.kl.ac		$:$1@$2.$m
R$+@$=S.cs.kl			$:$1@$2.$m
R$+@uk.ac.keele.cs.$=S		$:$1@$2.$m
R$+@ac.keele.cs.$=S		$:$1@$2.$m
R$+@keele.cs.$=S		$:$1@$2.$m
R$+@uk.ac.kl.cs.$=S		$:$1@$2.$m
R$+@ac.kl.cs.$=S		$:$1@$2.$m
R$+@kl.cs.$=S			$:$1@$2.$m

R$+@$+				$@$1@$2
R$+%$+				$1@$2
R$+@$+@$+			$1%$2@$3
R$+@$+				$:$>11$1

# Ruleset 12
#
# This is called for the 'outside' mailer.  We want to change our sender
# address from 'doc.cs.keele.ac.uk' to 'cs.keele.ac.uk' so we hide
# behind our domain.  If no domain at all then add ours.

S12

R$+@$j				$@$1@$m
R$+@$+				$@$1@$2
R$+				$:$1@$j


# Ruleset 13
#
# If no @ sign then add our name on to it.

S13

R$+@$+				$@$1@$2
R$+				$:$1@$j

rickert@mp.cs.niu.edu (Neil Rickert) (11/10/90)

In article <22619.9011091840@derek.cs.kl.ac.uk> jonathan@cs.kl.ac.uk (Jonathan Knight) writes:
>I have been driven nuts trying to make sendmail put my full
>name on the From: header line.
>
>The problem I see is that any email which originates locally and is
>delivered locally appears with a from line with the full email
>address and full name on.  Any email sent to another host is
>delivered without the full name.  It appears that sendmail has
>declared that the 'x' macro is undefined in these circumstances.
>
>If you want the config file, it's below.

  This topic was just discussed recently.

  To recap, it is because your mail is configured to send mail for local users
to your file server for delivery.

  This is the procedure that 'sendmail' uses for assigning a value to the
'$x' macro.

   If the 'From: ' header already exists, no additional $x is added, even
if the sender name is absent from the existing header.  In other words, for
'sendmail' to add the sender name, there must be no 'From: ' header when
the mail arrives.  As stated in 'sendmail' operations guide, the value of
$x is determined from the 'Full-name:' header if present, then from the
'From:' header if present.  Apparently these statement apply even if the
value so determined is null.

    Now, given that there is no 'From:' line, the next step is for
'sendmail' to determine whether the sender is local.  If not, there is
no attempt to assign a value to $x.

    The determination of whether the sender is local is handled as follows:

	A simulated attempt is made to send mail to the sender.  That is, the
	sender address is parsed by rulesets 3,0.  If this results in selecting
	the local mailer, the user is local, and the operand to $: in the
	mailer selection rewrite rule is the local user name.

In the case of the 'sendmail.cf' enclosed by Jonathan Knight, there was no
rule which selected the local mailer.  Therefore no user will ever be
recognized as local.

I presume that Sun introduced the 'OR' definition into its 'sendmail.cf'
for exactly this reason.  It allowed the local mailer to be selected, but
the local mail to still be forwarded by SMTP to a server.  My friends who
deal a lot with Sun systems tell me that 'OR' causes problems, and they would
just as soon not use it.

For another approach, you might want to pick up the sendmail-5.65+IDA
package from uxc.cso.uiuc.edu.  In the latest config package (1.4.1) I
have an option for sending local mail to a server, yet still correctly
evaluating $x.  To achieve this, it parses a local user so that it selects
the LOCAL mailer when a sender address is being parsed, but so that it
selects the TCP mailer when actual mail is being processed.  However this
can only be done because of the code enhancements in the IDA package.  The
same approach would not work on an unmodified 'sendmail'.  To be more
specific, it requires the $&X option for runtime evaluation of $X.

Another method that has been suggested is to set the mailer flags so that
when local mail is sent to the local server, no 'From: ' header is
generated.  Then the header can be generated on the server machine.  Of
course this presumes the sender has an entry in the passwd file on the
server machine, and will be satisfied with that information for the value
of $x.  Of course this means you can not set $x with the 'NAME' environment
variable, or, worse still, if NAME was defined when the daemon was started
on the server, that may become every user's name.

-- 
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
  Neil W. Rickert, Computer Science               <rickert@cs.niu.edu>
  Northern Illinois Univ.
  DeKalb, IL 60115.                                  +1-815-753-6940

per@erix.ericsson.se (Per Hedeland) (11/12/90)

In article <1990Nov10.003601.27771@mp.cs.niu.edu>, rickert@mp.cs.niu.edu
(Neil Rickert) writes: 
|>   This topic was just discussed recently.

|>    If the 'From: ' header already exists, no additional $x is added, even
|> if the sender name is absent from the existing header.  In other words, for
|> 'sendmail' to add the sender name, there must be no 'From: ' header when
|> the mail arrives.

This is not true - as mentioned in the summary from the last discussion,
if the address on the 'From: ' line exactly matches the envelope sender
address, sendmail *will* attempt to add the Full name if/as found in the
passwd file. I.e. if the client uses the <address> form for the 'From: '
line, as in:

Dq$x <$g>

the server will try to do the Full name lookup, with the caveats
mentioned (i.e. sender must be considered "local" on the server etc).

--Per Hedeland
per@erix.ericsson.se  or
per%erix.ericsson.se@uunet.uu.net  or
...uunet!erix.ericsson.se!per