#!/bin/sh
# Version 1.3, updated September 1st, 1994
#   still better comments
#   configuration variables to set the e-mail From: header
# Version 1.2, updated August 8th, 1994
#   updated comments
# Version 1.1, updated March 9th, 1994
#   strip single quotes from evaluated headers to prevent eval errors
#   return at most 10 lines of user text to prevent multi-megabyte mail bombs
#   log eval or sendmail problems to stdout (and thus INN's errlog)
#   explanation now includes Reply-To: redirection to *.test newsgroups
#   explanation now says why control messages are responded to

#	This script is called by innd to send e-mail replies in response to
#	postings in *.test newsgroups.  The following newsfeeds entries are
#	used here at CCCD:
#
#	ME\
#		:!cccd.*,!ccmisc.*,!control,!junk,!to.*\
#		/alt,ba,bionet,bit,biz,ca,cccd,ccmisc,cerf,chico,comp,ddn,gnu,\
#		inet,info,la,local,misc,na,news,oc,rec,sac,sba,sci,scruz,sdnet,\
#		soc,socal,talk,uc,us,usa,world::
#
#	autoresponder\
#		:*.test\
#		:Tp\
#		:/usr/local/bin/innautorespond /innspool/%s
#
#	Beware!  Note that any inclusive patterns specified in your ME entry
#	will be prepended to your autoresponder *.test patterns.  It's quite
#	easy to wind up sending autoresponses to "*,*.test" by accident.
#	Don't laugh!  This has happened to more than one site that has tried
#	to use this script.
#
#	Be sure to customize the autoresponder message text to be specific to
#	your own site.  Please remove *all* references to CCCD, with the
#	possible exception of the ftp site.
#
#	The author's version of this script is available from:
#
#		ftp://ftp.cccd.edu/pub/usenet/innautorespond

#	Permission is freely granted to modify and redistribute this code as
#	long as credit is given to the author:
#
#		Mark Bixby
#		Coast Community College District
#		District Information Services
#		1370 Adams Avenue
#		Costa Mesa, CA  92626
#		USA
#		e-mail: markb@cccd.edu
#		phone: +1 714 432 5064

#	Set configuration variables.  Note that there are additional CCCD
#	references in the reply text that will have to be edited manually.

mailname="CCCD Autoresponder"
mailaddr=usenet@news.cccd.edu

#	Verify that the article file exists.

if [ -r $1 ]; then
#	Set environment variables containing the From:/Reply-To: and Subject:
#	headers.  Count the number of header lines, and include up to 10 lines
#	of user text.  Strip single quotes while we're looking at headers.

awkvars=`awk '\
  BEGIN		{ hdr=1; hcount=0; hfrom=""; hreply=""; hsubject="" } \
  hdr==1 && length>0		{ hcount=hcount+1; gsub("\047","") } \
  hdr==1 && /^From:/	 	{ hfrom=$0; sub(/^From:/,"",hfrom) } \
  hdr==1 && /^Reply-To:/ 	{ hreply=$0; sub(/^Reply-To:/,"",hreply) } \
  hdr==1 && /^Subject:/ 	{ hsubject=$0; sub(/^Subject/,"Re",hsubject) } \
  hdr==1 && length==0		{ hdr=0 } \
  END	{ printf "hsubject=\047%s\047;",hsubject; \
	  if ( length(hreply) > 0 ) hfrom=hreply; \
	  printf "hfrom=\047%s\047;",hfrom; \
	  printf "hcount=%s;",hcount+11 }' $1`

eval $awkvars
if [ $? -ne 0 ]; then
  echo $0 eval failed: $1 $awkvars
fi

#	Don't respond if "ignore" is in the Subject: header.

if echo "$hsubject"|grep -i ignore >/dev/null ; then
	exit 0
fi

#	Mail the rejection notice along with a copy of the original article.

(cat - <<EOF; head -n $hcount $1) | /usr/lib/sendmail -t -f $mailaddr
To: $hfrom
Subject: $hsubject
From: $mailname <$mailaddr>
Precedence: junk

DO NOT PANIC!  REMAIN CALM!  READ *ALL* OF THIS MESSAGE BEFORE GETTING UPSET!

Your Usenet test article was received here at the news gateway machine for
the Coast Community College District in Costa Mesa, California, USA.  We are 
located at 117 54' 53'' W / 33 40' 27'' N.  The CCCD newsadmins can be reached 
via e-mail at $mailaddr.  Please note that we do not offer news
access to sites outside of our organization.

If you're a newsadmin and you'd like to run your own autoresponder, this one
is available from ftp://ftp.cccd.edu/pub/usenet/innautorespond.

If you want to suppress this message in the future, include the word "ignore" 
in the Subject: header of any subsequent articles posted to *.test.  You could
also post your test articles with a Distribution: header of "local" to prevent
them from leaving your local machine, or you could also ask your local 
newsadmin to create a local *.test group that will not propagate outside of 
your organization.

There are typically 5 possible reasons why you were sent this e-mail message:

1) You intentionally posted a Usenet news article to a *.test newsgroup.  
These newsgroups exist so you can verify that your articles are being 
propagated correctly.  When your article arrives here, we send you this message
as confirmation.  We will only send you ONE e-mail reply for each of your test
articles that we see.

2) You unintentionally posted a Usenet news article to a *.test newsgroup.  
This is a bit of net.childishness caused by a Followup-To: header directing all
replies into a *.test newsgroup.  This is done by somebody upset with the
content of a discussion thread who wants to "punish" anybody who replies to his
message.  Your reply will be sent to *.test instead of the original newsgroup,
and you will start receiving autoresponder messages similar to this one that
you didn't ask for.  To avoid this in the future, look for a Followup-To:
header and make sure it's appropriate before replying to any articles.

3) You were a victim of a Reply-To: header directing your e-mail into a *.test
newsgroup via a mail->news gateway.  Similar to 2) above.

4) Somebody has forged a posting in your name to one of the *.test newsgroups.
To avoid this in the future, use better net.etiquette and you will make fewer
net.enemies.  If you want to try and identify the forger, use the following
procedure.  Make a legitimate posting to the same *.test newsgroup that the
forger used.  We will send you an e-mail reply.  Compare the Path: header from
this legitimate reply with the Path: header from the forgery.  The front
part of the two headers will be the same or topologically similar path to
your site.  Where the forged header becomes substantially different can
provide clues to where the forger lives.  Note that if you receive multiple
newsfeeds you may need to repeat this process several times so you can discover
all legitimate paths between our site and yours.  Once you think you've
identified the forger's site, try sending POLITE e-mail to the newsadmin/
sysadmin/postmaster explaining the situation.

5) You issued a cancel control message to a *.test newsgroup.  Some users
dislike autoresponses for cancel messages, but the newsadmins here think it
can be a valuable diagnostic tool for verifying cancel propagation.  If you
don't like it, use the "delete" key in your mail client!

All headers plus at most 10 lines of user text from your original article are
reproduced below for your perusal:

EOF
if [ $? -ne 0 ]; then
  echo $0 sendmail failed: $1 $awkvars
fi

fi
