home *** CD-ROM | disk | FTP | other *** search
- :
- # gatemail - accept a mail message and gate it to a newsgroup
- # Clay Luther, 1990, Version 1
- # cluther@supernet.haus.com
- # usage: gatemail group newsgroup < mailfile
-
- # Check for a parameter
- if [ $# -ne 2 ]
- then
- echo "Usage: gatemail newsgroup < mailfile"
- exit 1
- fi
-
- TMP="/tmp/gm$$"
- cat > $TMP
-
- F="/tmp/GM$$"
- INEWS='/usr/lib/news/inews.new'
- GROUPNAME=$1
- GROUP=$2
- NEWSDIR='/usr/lib/news'
- LOG="$NEWSDIR/gatemail.log"
- NEWS='news'
- MAILNAME="$NEWSDIR/mailname"
- HOST=`cat $MAILNAME`
- ORG="Gated to News by $HOST"
- POST="/tmp/post$$"
-
- if [ ! -f $LOG ]
- then
- echo "" | cat > $LOG
- chmod +rw $LOG
- chown $NEWS $LOG
- fi
-
- XGATE=`grep "^X-Gateway:.*$HOST" $TMP`
-
- if [ ! "$XGATE" ]
- then
-
- FROM=`grep "^From:" $TMP | awk '{ \
- size=split($0,s)
- for (i=2;i<=size;i++) {
- printf("%s ",s[i])
- }
- printf("%s","\n")
- }'`
-
- REPLY=`grep "^Reply-To:" $TMP | awk '{ \
- size=split($0,s)
- for (i=2;i<=size;i++) {
- printf("%s ",s[i])
- }
- printf("%s","\n")
- }'`
-
- SUBJ=`grep "^Subject:" $TMP | awk '{ \
- size=split($0,s)
- for (i=2;i<=size;i++) {
- printf("%s ",s[i])
- }
- printf("%s","\n")
- }'`
-
- # Strip away the headers
- awk '\
- BEGIN {
- x=0
- }
- {
- if ( x == 0 ) {
- if ( NF == 0 ) {
- x=1
- }
- } else {
- print $0
- }
- }' $TMP > $F
-
- # call inews to mail it
- LINES=`wc -l $F | awk '{print $1}'`
- LINES=`expr $LINES + 7`
- (
- echo "Newsgroups: $GROUP"
- echo "From: $FROM"
- #echo "From: $REPLY"
- echo "Subject: $SUBJ"
- #echo "Reply-To: $REPLY"
- echo "Reply-To: $FROM"
- echo "Organization: $ORG"
- echo "Path: $GROUPNAME"
- echo "Sender: $REPLY"
- echo "Lines: $LINES"
- echo ""
- cat $F
- ) | cat > $POST
-
- $INEWS -z -h $POST
-
- DATE=`date`
- # Log it
- echo "$DATE $GROUP: $FROM [$SUBJ]" >> $LOG
-
- fi # this was gated from news by us and echoed by the target
-
- #Clean up
- rm -f $TMP $F $POST
-
- # Clean up the log if it is too long
- LENGTH=`wc -l $LOG | awk '{print $1}'`
- if [ $LENGTH -gt 1000 ]
- then
- tail -1000 $LOG > $TMP
- mv $TMP $LOG
- fi
-