head	1.4;
access;
symbols;
locks;
comment	@# @;


1.4
date	94.07.20.06.51.15;	author ken;	state Exp;
branches;
next	1.3;

1.3
date	94.07.20.06.46.19;	author ken;	state Exp;
branches;
next	1.2;

1.2
date	92.11.19.16.06.06;	author edwin;	state Exp;
branches;
next	1.1;

1.1
date	92.11.19.16.02.03;	author edwin;	state Exp;
branches;
next	;


desc
@distribute
@


1.4
log
@Added some of Edwin's changes back.
@
text
@#!/bin/sh
#
# $Header: /local/src/zmailer/utils/RCS/distribute,v 1.3 1994/07/20 06:46:19 ken Exp $
#
# Distribute stdin (presumed to be a digest or direct-mail article from
# a mailing list) according to the following flags
#
# -n newsgroup		post article to specified newsgroup.
# -a file		append to the file specified.
# -m people		remail to people, people may be a filename
#			in which case the contents will be assumed
#			to be a list of recipients, one to a line.
#			note that in the case of a file all recipients
#			will appear on the headers, and therefore
#			an alias is best used for large lists.
#			If a file named "people" is found in the PEOPLE
#			directory, then that is used.
# -d directory		store into a file named by volume and
#			issue under "directory".  Useful for digests.
# -am name		shorthand for '-a name -m /local/share/mail/lists/name'
# -dm name		shorthand for '-d name -m /local/share/mail/lists/name'
#
# Notes:
# - If invoked from sendmail, all arguments will be lowercase only!
#
# Rayan Zachariassen - rayan@@cs.toronto.edu
# Jean-Francois Lamy - lamy@@cs.toronto.edu

#exec >> /tmp/dist.trace 2>&1
#set -x
PATH=/local/bin:/usr/ucb:/usr/bin:/bin
export PATH
umask 022

USAGE='distribute [-n newsgroup] [-a archivefile] [-d archivedir] [-m mailto]'

# get the zmailer configuration
. /etc/zmailer.conf

# could be the same site, though not necessarily
thissite=cs.toronto.edu
newsserver=news-server.csri.toronto.edu
# machine to uux the article to.
newsuucp=utjarvis
# program to use for logging each message -- gets newsgroup and messageid
# as arguments
logger="logger -p local4.notice -t"

# we keep the archives under our anonymous FTP directory so other people
# can get at them.
archdir=/local/ftp
cd $archdir

# this person receives bounces and such like.  Make it an alias as it
# will appear on the sender: line of messages.
admin=list-admin

PEOPLE=$MAILVAR/lists

Mail=/usr/ucb/Mail
sendmail=/usr/lib/sendmail
# This program should be suid daemon, so that sensitive files can be
# protected.  Only needed if you have an old flakey sendmail, really.
blankcat=$MAILBIN/bin/appendfile

#
# Parse arguments
#
ARTICLE=/tmp/dist$$
newsgroup=""
newsgroups=""
file=""
directory=""
mailto=""
case $# in
0|1)	echo Usage: $USAGE
	exit 1 ;;
esac
state=x
for i in $@@
do
	case "$i" in
	-*)	state=$i ;;
	*)	case $state in
		-n)	newsgroup="$i"
			newsgroups=${newsgroup}${newsgroups:+",$newsgroups"}
			distribution="`expr $newsgroup : '\([a-z]*\)\.*'`"
			;;
		-n*)	newsgroup="$i"
			newsgroups=${newsgroup}${newsgroups:+",$newsgroups"}
			distribution="`expr $state : '-n\(.*\)'`"
			;;
		-a)	file="$i" ;;
		-d)	directory="$i" ;;
		-m)	if [ -f $PEOPLE/$i ]; then
				mailto="$PEOPLE/$i"
			else
				mailto="$i"
			fi
			;;
		-am)	file="$i"
			mailto="$PEOPLE/$i" ;;
		-dm)	directory="$i"
			mailto="$PEOPLE/$i" ;;
		x)	echo Usage: $USAGE
			exit 2 ;;
		esac
		state=x ;;
	esac
done
#
case "${newsgroup}${file}${directory}${mailto}" in
# zmailer adds a spurious blank line at the bottom. sigh.
# delete such a line if one is found.  one should revert to using
#  cat - > $ARTICLE
# after the bug is fixed!!!
?*)	sed -e ':a
$b e
n
b a
:e
/^$/d' > $ARTICLE ;;
*)	exec $Mail -s "No options to $MAILBIN/bin/distribute" list-admin
	exec /bin/mail list-admin
	exit 4 ;;
esac
#cp $ARTICLE /tmp/distart

case $file in
?*)	$blankcat -lists/"${file}" $ARTICLE ;;
esac
case "$directory" in
?*)	eval `sed 40q $ARTICLE \
	| fgrep -i digest \
	| sed -n \
	-e 's/.*Vol[^0-9]*\([0-9][0-9]*\)[^0-9][^0-9]*\([0-9][0-9]*\)[^0-9]*/VOL=\1 NUM=\2/p'`
	$blankcat "-$directory/V${VOL}.${NUM}" $ARTICLE ;;
*)	directory="$archdir" ;;
esac

# extract return path from article.
ed - $ARTICLE <<EOF
1s/From \\([^ ]*\\) .*/\\1/
1w $ARTICLE.from
1d
w
q
EOF

# forwarding via mail
if [ -s $ARTICLE.from ]; then
	path="`cat $ARTICLE.from`"
	case "$mailto" in
	*/*)	( cd $directory ;
		if [ -s $mailto ]; then
			$sendmail -f "$path" `cat $mailto` < $ARTICLE
		fi
		)
		;;
	?*)	$sendmail -f "$path" $mailto < $ARTICLE
		;;
	esac
else
	path="$newsserver!news"
fi

# forwarding to newsgroups
case "$newsgroup" in
?*)	case "$path" in
	*!*!*)	path=`expr "$path" : '.*!\([^!]*![^!]*\)$'`;;
	esac
	case "$path" in
	*.*!*)	;;
	*!*)	path=`echo "$path" | sed 's/!/.uucp&/'` ;;
	esac
	# Stick our name on.  Note that this means the article will not
	# get fed back to us, which shouldn't be a problem.
	path="$thissite!$path"
	lines=`sed -e '1,/^[ 	]*$/d' $ARTICLE|wc -l`
# All this does is massage the headers so they look like what news
# software expects.  To:, Cc: and Resent-*: headers are masked.
# So are Newsgroups: headers, in case we're gatewaying from a 
# mailing list that is itself a gateway!
# Reply-To: is turned into references, which is questionable (could
# just as well be dropped.
#
# The From: line is rewritten to use the "address (comments)" form
# instead of "phrase <route>" form our mailer uses.  Also, addresses
# with no "@@domainname" are assumed to originate locally, and so are
# given a domain.
#
# The Sender: field below reflects the address of the person who
# maintains our mailing lists.  The Approved: field is in a special
# form, so that we can do bidirectional gatewaying.  Any message
# in a newsgroup that bears this stamp will not be fed into the
# matching mailing list.
	sed -n -e "1{i\\
		Path: $path
		}" \
	    -e ":a
		/^Newsgroups:/s/^/Original-/
		/^[Rr]eceived:/b r
		/^[Tt][Oo]:/s/^/Original-/
		/^[Cc][Cc]:/s/^/Original-/
		/^[Rr][Ee][Ss][Ee][Nn][Tt]-.*/s/^/Original-/
		s/^[Ii]n-[Rr]eply-[Tt]o:/References:/
		/^From:/{
			s/<\([^@@]*\)>\$/<\1@@$thissite>/
			s/^From:[ 	][	]*\(.*\)  *<\(.*\)>\$/From: \2 (\1)/
			}
		s/-[Ii]d:/-ID:/
		s/^\([^:]*:\)[	 ]*/\1 /
		/^\$/{i\\
			Newsgroups: $newsgroups\\
			Distribution: $distribution\\
			Sender: $admin@@$thissite\\
			Approved: $newsgroup@@mail.cs.toronto.edu\\
			Lines: $lines
			b e
		}
		p
		n
		b a
		:r
		s/.*//g
		n
		/^[ 	]/b r
		b a
		:e
		p
		n
		b e" < $ARTICLE |
		uux - $newsuucp!rnews > /tmp/disterr$$ 2>&1
		if test -s /tmp/disterr$$; then
			$Mail -s 'distribute error' $admin < /tmp/disterr$$
		else
			# update the logs
			messageid=`egrep -i '^message-id:[ 	]' $ARTICLE`
			messageid=`expr "$messageid" : '..........:[ 	]\(.*\)'`
			$logger "$newsgroups" "$messageid"
		fi
		rm -f /tmp/disterr$$
		;;
esac
rm -f $ARTICLE $ARTICLE.from
exit 0
@


1.3
log
@ANT version.
@
text
@d3 1
a3 1
# $Header: /export/local/sun4/lib/mail/bin/RCS/distribute,v 1.23 90/12/25 17:56:51 root Exp $
d37 3
d58 1
a58 1
PEOPLE=/local/share/mail/lists
a61 2
cat=/bin/cat
rm=/bin/rm
d64 1
a64 1
blankcat=/local/lib/mail/bin/appendfile
d123 1
a123 1
*)	exec $Mail -s "No options to /local/lib/mail/distribute" list-admin
d245 1
a245 1
$rm -f $ARTICLE $ARTICLE.from
@


1.2
log
@Changes for CSRI servers:
- changed logging to use syslog logger.
- uses zmailer configuration file for access to $MAIL{BIN,SHARE}.

- Changed some hard coded locations to use $MAIL{BIN,SHARE}, etc.
- Changed jarvis.csri to news-server.csri.
- Removed an occurance of a 'tee' command.
@
text
@d3 1
a3 1
# $Header: /tmp_mnt/csri6Serv.csri/csri6/src/local.lib/zmailer.csri/utils/RCS/distribute,v 1.2 92/04/28 14:29:00 edwin Exp $
d16 2
a23 2
# - When using -a or -m alone, a full path is required, which does differ
#   with what -am and -dm expect (the name of the mailing list only).
d26 2
a27 2
# Rayan Zachariassen - rayan@@ai.toronto.edu
# Jean-Francois Lamy - lamy@@ai.toronto.edu
d29 1
a29 1
#exec 2>&1
d31 2
a36 3
# get the zmailer configuration
. /etc/zmailer.conf

d38 1
a38 1
thissite=`domainname`.toronto.edu
d40 5
d55 1
a55 2
PEOPLE=$MAILSHARE/lists
logger="logger -p local4.notice -t"
d63 1
a63 1
blankcat=$MAILBIN/bin/appendfile
d70 1
d85 1
d89 1
d94 6
a99 1
		-m)	mailto="$i" ;;
d122 1
a122 1
*)	exec $Mail -s "No options to $MAILBIN/bin/distribute" list-admin
d126 1
d129 1
a129 1
?*)	$blankcat -lists/${file} $ARTICLE ;;
d131 4
a134 4
case $directory in
?*)	eval `/usr/ucb/head -40 $ARTICLE \
	| /usr/bin/fgrep -i digest \
	| /bin/sed -n \
d140 2
a141 2
# extract return path from article
/local/bin/ed - $ARTICLE <<EOF
d152 1
a152 1
	case $mailto in
d155 1
a155 1
			$sendmail -f $path `cat $mailto` < $ARTICLE
d159 1
a159 1
	?*)	$sendmail -f $path $mailto < $ARTICLE
d167 3
a169 9
case $newsgroup in
?*)	case $path in
	*!*!*)	path="`expr $path : '.*!\([^!]*![^!]*\)$'`"
		case $path in
		*.*!*)	;;
		*)	path="`echo $path | sed 's/!/.uucp&/'`" ;;
		esac ;;
	*!*)	;;
	*)	path="`hostname`.toronto.edu!$path" 
d171 8
a178 1
lines=`sed -e '1,/^[ 	]*$/d' $ARTICLE|wc -l`
d181 2
d200 1
d213 1
a213 1
			Newsgroups: $newsgroup\\
d231 12
a242 19
		b e" < $ARTICLE > ${ARTICLE}.news
# ${ARTICLE}.news is the article to be posted.  Any method could
# be used to do it, normally invoking "inews" or even "relaynews" 
# directly would work.  Our setup is peculiar in that the news server
# is another machine, for historical (hysterical?) reasons.
# It turns out that invoking nntp on each article puts more load on
# the news server than making up a fake batch and mailing it to them,
# so we do just that.
		set - `wc -c ${ARTICLE}.news`
		(echo "#! rnews $1" ; cat ${ARTICLE}.news) |
			sed -e 's/^/N/' |
			$sendmail -f"$admin" recnews@@news-server.csri
#
# update the logs
#
		messageid=`egrep -i '^message-id:[ 	]' $ARTICLE`
		messageid=`expr "$messageid" : '..........:[ 	]\(.*\)'`
		time=`date | awk '{print $2,$3,$4}'`
		$logger "$newsgroup" "$messageid"
d244 1
a244 1
$rm -f $ARTICLE $ARTICLE.from $ARTICLE.news
@


1.1
log
@Initial revision
@
text
@d3 1
a3 1
# $Header: distribute,v 1.18 88/09/18 22:26:23 lamy Exp $
d35 3
d40 1
a40 1
newsserver=jarvis.csri.toronto.edu
d51 2
a52 2
PEOPLE=/local/share/mail/lists
LOG=/var/log/distribute
d60 1
a60 1
blankcat=/local/lib/mail/bin/appendfile
d111 1
a111 1
*)	exec $Mail -s "No options to /local/lib/mail/distribute" list-admin
d225 2
a226 2
			sed -e 's/^/N/' | tee /tmp/newsbath/$$ |
			$sendmail -f"$admin" recnews@@jarvis.csri
d233 1
a233 1
		echo $time $newsgroup $messageid >> $LOG
@
