Alias Lister For Users

Mic Kaczmarczik mic at ut-emx.uucp
Mon Nov 19 15:09:10 AEST 1990


In article <1990Nov17.023351.16824 at lokkur.dexter.mi.us>
scs at lokkur.dexter.mi.us (Steve Simmons) posted a sendmail alias
expander that used sendmail -bv to verify the alias.  One advantage of
using sendmail instead of parsing the alias database directly is that
it works on systems where the alias file is distributed using Sun's
NIS (nee Yellow Pages) network database, instead of being a file on
disk. 

The script below uses the same idea as Steve's script (make *sendmail*
figure things out), but instead uses the SMTP EXPN command and parses
the server's response.  Since I haven't seen too much use of the
SMTP-through-a-pipe technique elsewhere (maybe for good reasons :-),
here 'tis. 

--mic--

------------------------------------CUT HERE-----------------------------------
#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  expn
# Wrapped by mic at emx.utexas.edu on Sun Nov 18 22:02:23 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'expn' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'expn'\"
else
echo shar: Extracting \"'expn'\" \(634 characters\)
sed "s/^X//" >'expn' <<'END_OF_FILE'
X#!/bin/sh
X#
X# This hack runs sendmail in SMTP mode and uses the EXPN command to
X# expand an address into the real address(es) that the mail will be
X# delivered to.  It takes advantage of sendmail's ability to read
X# SMTP commands from standard input when you use the -bs flag.
X#
X#	Usage:
X#		expn alias
X#
X#	Output:
X#		the address(es) mail sent to ``alias'' will really go to
X
Xif [ -z "$1" ]; then
X	echo usage: `basename $0` sendmail-alias
X	exit 1
Xfi
Xecho "expn $1
Xquit" | /usr/lib/sendmail -bs | tr -d '\015' | \
X	sed -e 's/^250.*<\([^>]*\)>.*/\1/' \
X	    -e 's/^5[0-9][0-9].\(.*\)/\1/' \
X	    -e '/^[0-9][0-9][0-9] /d' | sort
Xexit 0
X
END_OF_FILE
if test 634 -ne `wc -c <'expn'`; then
    echo shar: \"'expn'\" unpacked with wrong size!
fi
chmod +x 'expn'
# end of 'expn'
fi
echo shar: End of shell archive.
exit 0
------------------------------------CUT HERE-----------------------------------



More information about the Alt.sources mailing list