autoreply - How to ???
Erik E. Fair
fair at Apple.COM
Sun Feb 19 18:42:33 AEST 1989
#!/bin/sh
#
# Mail back articles in *.test newsgroups to the sender
#
# Erik E. Fair <ucbvax!fair>
# December 5, 1987 (revised to use domain address)
# March 16, 1986 (revised)
# August 7, 1985
#
tmp=/tmp/bounce$$
libdir=/usr/lib/news
#
# this file contains the mappings from "uucp" names to fully qualified
# internet domain names:
#
gwfile=${libdir}/gw-u-to-i
#
trap "rm -f ${tmp}; exit 0" 0 1 2 3 15
cat > ${tmp} << 'EOF'
This is an automatic echo of your posting to *.test.
We're mailing this back to you by sending to a hacked up version
of the address in the Path: header (we have some simple routines
in awk to do that), and to the domain address in the From: header
(if the top level domain isn't ".UUCP"). I hope your domain name
is registered so that this will work.
NNTP service with a :-)
Erik E. Fair ucbvax!usenet usenet at ucbvax.berkeley.edu
EOF
cat >> ${tmp}
#
# Do it all on one command line...
#
/usr/ucb/Mail -s "Automatic Test Echo" `
(
echo '@@UUNAME'
uuname
if [ -f ${gwfile} ] ; then
cat ${gwfile}
fi
echo '@@END'
cat ${tmp}
) | awk -e '
BEGIN{
uuinput = 0;
addr = "";
}
# Some state changes
/^@@UUNAME/ { uuinput = 1; next; }
/^@@END/ { uuinput = 0; next; }
#
{
#
# suck in uuname output for path optimization
#
if (uuinput) {
if (NF == 1) Lsys[$1] = 1;
if (NF == 2) gateway[$1] = $2;
next;
}
}
/^From:/{
n = split($2, address, "@");
if (n != 2) next;
hostname = address[2];
n = split(hostname, domain, ".");
if (n > 1 && domain[n] != "UUCP" && domain[n] != "uucp")
print $2;
next;
}
/^Path:/{
#
# This is where we get a return address from. Do path slicing to shorten it.
# One day we will run pathparse and generate something reasonable.
#
start = 1;
altgate = 0;
n = split($2, path, "!");
if (n == 2) {
addr = path[2];
print addr;
next;
}
for(i = 1; i < n; i++) {
if (Lsys[path[i]]) start = i;
if (gateway[path[i]]) altgate = i;
}
#
# To shorten things further, we recognize other internet gateways to UUCP
# and abuse their good names in return addresses too...
#
if (altgate < start) {
addr = path[start];
for(i = start + 1; i <= n; i++) {
addr = addr "!" path[i];
}
} else {
rmthost = gateway[path[altgate]];
altgate++;
if (altgate == n) {
addr = path[n] "@" rmthost;
} else {
addr = path[altgate];
for(i = altgate + 1; i <= n; i++) {
addr = addr "!" path[i];
}
addr = addr "@" rmthost;
}
}
#
# Hell and damnation. Why are decwrl and psuecl putting "@" in Path?
#
n = split(addr, parts, "@");
if (n > 2) {
addr = parts[1];
for(i = 2; i < n; i++) {
addr = addr "%" parts[i];
}
addr = addr "@" parts[n];
}
print addr;
next;
}'` < ${tmp}
More information about the Comp.unix.wizards
mailing list