Subject: Re: Sendmail and duplicate mail addresses
To: David Brownlee <david@mono.org>
From: Davyd Norris <Davyd.Norris@fcollins.com.au>
List: tech-net
Date: 01/29/1997 10:28:48
This is a multi-part message in MIME format.
------------3EE2278F30010
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=us-ascii

David Brownlee wrote:
> 
.
.
.
> 
> > Also- how can I use long email addresses, e.g. "Nick.Loman" with the NetBSD
> > password file?
> >
>         Rewriting outgoing mail, or just aliases for incoming?
>         Incoming aliases:
>         edit /etc/aliases and add lines of the form
>                 from:   to
>         (to can be an external address, ie
>                 anne:   a.n.other@somwhere.else
>         The run 'newaliases'.
> 
>         Rewriting outgoing mail is more fun - never wanted to do it
>         myself, but I'm sure someone else who has can help?
> 
> > Thanks in advance- if this is the wrong mailing list to ask sendmail
> > specific questions in then could someone direct me to somewhere more
> > appropriate?
> 

Howdy,

The best way to enable user name rewriting is to use the userdb database. this allows you to rewrite 
names in both directions (in and out)

You will need to read the information in the sendmail source (the FAQ has it) on enabling userdb. It 
is really simple, just a line or two in your cf file.

You will then need to create your userdb file. I have attached a rough hack script to add mail names 
to a userdb file as well as a shadow pop account (mh's popd for those who want to know). You should 
get the idea from that.

_______________________________0/_________________________________
                               o\
#!/bin/sh
# Script to add a new user to the userdb file

#	if ["$3" == ""]; then
	if [ $# != 3 ]; then
		echo "syntax: $0 loginame Firstname Lastname"
		exit 1
	fi

	loginame=$1
	firstname=$2
	lastname=$3
	firstinit=`expr $2 : '\(^.\)'`
	lastinit=`expr $3 : '\(^.\)'`

	echo >> /etc/userdb
	echo "${loginame}:mailname			$firstname.$lastname" >> /etc/userdb
	echo "$firstname.${lastname}:maildrop		$loginame@pop" >> /etc/userdb
	echo "$firstinit.${lastname}:maildrop		$loginame@pop" >> /etc/userdb
	echo "$firstname${lastinit}:maildrop		$loginame@pop" >> /etc/userdb
	echo "${loginame}:maildrop			$loginame@pop" >> /etc/userdb
	echo "${loginame}::$firstname${lastinit}:::::::0" >> /var/spool/pop/POP

	makemap btree /etc/userdb.db < /etc/userdb
	newaliases
	exit 0

__________________________________________________________________

As shown above, if you enter:

	addmailname johnny John Smith

then sendmail will:
1. Rewrite outgoing mail from johnny@whatever.com to John.Smith@whatever.com
2. Redirect incoming mail sent to
	johnny@whatever.com
	john.smith@whatever.com
	j.smith@whatever.com
	johns@whatever.com

to the pop mailbox johns@pop

As I said, this is a really rough script. One major problem with it is if your user names are of a 
similar form to any of the other forms above (ie. username is johns) then makemap will yell like crazy 
about duplicate keys, but will only add the one key to the btree.

A much worse problem exists if John Smith and John Stanley exist on your system, but that is another 
script (Hey, it works for me and I didn't have much time!) You get the idea though.

GLuck!

D.
-- 
Davyd Norris - Systems Manager
Franklin Collins Pty. Ltd.
Melbourne, Australia.
http://www.fcollins.com.au/
------------3EE2278F30010
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="addmailname"
Content-Type: text/plain; charset=us-ascii; name="addmailname"

#!/bin/sh
# Script to add a new user to the userdb file

#	if ["$3" == ""]; then
	if [ $# != 3 ]; then
		echo "syntax: $0 loginame Firstname Lastname"
		exit 1
	fi

	loginame=$1
	firstname=$2
	lastname=$3
	firstinit=`expr $2 : '\(^.\)'`
	lastinit=`expr $3 : '\(^.\)'`

	echo >> /etc/userdb
	echo "${loginame}:mailname			$firstname.$lastname" >> /etc/userdb
	echo "$firstname.${lastname}:maildrop		$loginame@pop" >> /etc/userdb
	echo "$firstinit.${lastname}:maildrop		$loginame@pop" >> /etc/userdb
	echo "$firstname${lastinit}:maildrop		$loginame@pop" >> /etc/userdb
	echo "${loginame}:maildrop			$loginame@pop" >> /etc/userdb
	echo "${loginame}::$firstname${lastinit}:::::::0" >> /var/spool/pop/POP

	makemap btree /etc/userdb.db < /etc/userdb
	newaliases

	exit 0

------------3EE2278F30010--