#!/bin/sh

#	Newsgroup moderators can pipe e-mail submissions into this script
#	to reject articles back to the sender.  The author's version of this
#	script is available from:
#
#		ftp://ftp.cccd.edu/pub/usenet/innmodr
# 
#       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

#	Create a temporary file to hold the article extracted from the
#	mail message.

artfile=/tmp/innmodn.$$
export artfile

if [ -f $artfile ]; then
	rm -f $artfile
fi

#	Ignore everything until the Path: header.  Remove Status: headers
#	generated by the mail client.  Set some environment variables
#	containing article header contents.

eval `awk '\
  BEGIN		{ art=0; hdr=0; hfrom=""; hreply=""; hsubject=""; hto="" } \
  art==0 && /^To:/		{ hto=$0; sub(/^To:/,"",hto) } \
  /^Path:/			{ art=1; hdr=1 } \
  hdr==1 && /^From:/	 	{ hfrom=$0; sub(/^From:/,"",hfrom) } \
  hdr==1 && /^Reply-To:/ 	{ hreply=$0; sub(/^Reply-To:/,"",hreply) } \
  hdr==1 && /^Status:/		{ next } \
  hdr==1 && /^Subject:/ 	{ hsubject=$0; sub(/^Subject/,"Re",hsubject) } \
  hdr==1 && length==0		{ hdr=0 } \
  art==1			{ print $0 >>ENVIRON["artfile"]} \
  END	{ printf "hsubject=\047%s\047;",hsubject; \
	  printf "hto=\047%s\047;",hto; \
	  if ( length(hreply) > 0 ) hfrom=hreply; \
	  printf "hfrom=\047%s\047;",hfrom }'`

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

cat - $artfile <<EOF | /usr/lib/sendmail -t -f $hto
To: $hfrom
Subject: $hsubject

The newsgroup moderator has rejected your article as being inappropriate for
one or more of the newsgroups listed in the Newsgroups: header.  Your entire 
rejected article is included below:

EOF

rm -f $artfile
