home *** CD-ROM | disk | FTP | other *** search
- :
- # gatenews - a script to gate news from news to mail
- # Clay Luther, 1990, Version 1
- # cluther@supernet.haus.com
- # Usage: gatenews dest spoolfile from
-
- # Defines
- SPOOL='/usr/spool/news/gatenews'
- NEWSDIR='/usr/lib/news'
-
- if [ $# -ne 3 ]
- then
- echo "Usage: gatenews dest spoolfile from"
- echo " where dest is the address of the destination, and"
- echo " spoolfile is the name of a file in $SPOOL"
- echo " from is the local address to set the from line to"
- exit 1
- fi
-
- DEST=$1
- HIST="$NEWSDIR/gatenews.log"
- SFILE="$SPOOL/$2"
- NEWS='news'
- MAIL='/usr/local/bin/fastmail'
- TMP="/tmp/gate$$"
- MAILNAME="$NEWSDIR/mailname"
- HOST=`cat $MAILNAME`
- ORG="Gated to News by $HOST"
- FNAME="$3@$HOST"
-
-
- if [ ! -f "$SFILE" ]
- then
- exit 0
- fi
-
- if [ ! -f "$HIST" ]
- then
- echo "" | cat > $HIST
- chmod +rw $HIST
- chown $NEWS $HIST
- fi
-
- S=`cat $SFILE`
- rm -f $SFILE
-
- for F in $S
- do
- if [ -f "$F" ]
- then
- # echo $F
- MID=`grep "^Message-ID:" $F` # Obtain Message ID
- if [ "$MID" ]
- then
- INSTR="$MID -> $DEST"
- PREV=`grep "$MID" $HIST` # Check for it in gatehist file
- if [ -z "$PREV" ]
- then # he hasn't been mailed before
-
- # Get the Organization Line - IMPORTANT
- FORG=`grep "^Organization:.*$ORG" $F`
- if [ ! "$FORG" ]
- then # it's ok, we didn't make this!
- #more $F
- # Save the From line
- FROM=`grep "^From:" $F | awk '{ \
- size=split($0,s)
- for (i=2;i<=size;i++) {
- printf("%s ",s[i])
- }
- printf("%s","\n")
- }'`
- # Save the Subject line
- SUBJ=`grep "^Subject:" $F | awk '{ \
- size=split($0,s)
- for (i=2;i<=size;i++) {
- printf("%s ",s[i])
- }
- printf("%s","\n")
- }'`
-
- # Make an entry in $TMP
- (
- echo "X-Gateway: $HOST"
- ) | cat > $TMP
-
- # The above is necessary to catch mail echoed back to us!
-
- # Strip away the news headers and store output in $TMP
- awk '\
- BEGIN {
- x=0
- }
- {
- if ( x == 0 ) {
- if ( NF == 0 ) {
- x=1
- }
- } else {
- print $0
- }
- }' $F >> $TMP
-
- # OK, we have a From line, a Subject Line, and a source file
- # Time to mail it and log it
-
- # This line may need tweaking, depending on your mailer
- $MAIL -r "$FROM" -s "$SUBJ" -f "$FNAME" $TMP $DEST
- # Log the message id
- echo $INSTR | cat >> $HIST
- fi # we didn't make it
- fi # wasn't in hist file
- fi # if grep $MID
- fi # $F existed
- done # with loop
-
- # Clean up
- rm -f $TMP
-
- # Check the $HIST log for being way too long
- LEN=`wc -l $HIST | awk '{print $1}'`
- if [ $LEN -gt 2000 ]
- then
- tail -2000 $HIST > $TMP
- mv $TMP $HIST
- fi
-