home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2371 / gatemail < prev    next >
Encoding:
Text File  |  1990-12-28  |  2.4 KB  |  116 lines

  1. :
  2. # gatemail - accept a mail message and gate it to a newsgroup
  3. # Clay Luther, 1990, Version 1
  4. # cluther@supernet.haus.com
  5. # usage: gatemail group newsgroup < mailfile
  6.  
  7. # Check for a parameter
  8. if [ $# -ne 2 ]
  9. then
  10.   echo "Usage: gatemail newsgroup < mailfile"
  11.   exit 1
  12. fi
  13.  
  14. TMP="/tmp/gm$$"
  15. cat > $TMP
  16.  
  17. F="/tmp/GM$$"
  18. INEWS='/usr/lib/news/inews.new'
  19. GROUPNAME=$1
  20. GROUP=$2
  21. NEWSDIR='/usr/lib/news'
  22. LOG="$NEWSDIR/gatemail.log"
  23. NEWS='news'
  24. MAILNAME="$NEWSDIR/mailname"
  25. HOST=`cat $MAILNAME`
  26. ORG="Gated to News by $HOST"
  27. POST="/tmp/post$$"
  28.  
  29. if [ ! -f $LOG ]
  30. then
  31.   echo "" | cat > $LOG
  32.   chmod +rw $LOG
  33.   chown $NEWS $LOG
  34. fi
  35.  
  36. XGATE=`grep "^X-Gateway:.*$HOST" $TMP`
  37.  
  38. if [ ! "$XGATE" ]
  39. then
  40.  
  41. FROM=`grep "^From:" $TMP | awk '{ \
  42.                             size=split($0,s)
  43.                             for (i=2;i<=size;i++) {
  44.                               printf("%s ",s[i])
  45.                             }
  46.                             printf("%s","\n")
  47.                             }'`
  48.  
  49. REPLY=`grep "^Reply-To:" $TMP | awk '{ \
  50.                             size=split($0,s)
  51.                             for (i=2;i<=size;i++) {
  52.                               printf("%s ",s[i])
  53.                             }
  54.                             printf("%s","\n")
  55.                             }'`
  56.  
  57. SUBJ=`grep "^Subject:" $TMP | awk '{ \
  58.                             size=split($0,s)
  59.                             for (i=2;i<=size;i++) {
  60.                               printf("%s ",s[i])
  61.                             }
  62.                             printf("%s","\n")
  63.                             }'`
  64.  
  65. # Strip away the headers
  66. awk '\
  67.        BEGIN {
  68.          x=0
  69.        }
  70.        {
  71.          if ( x == 0 ) {
  72.            if ( NF == 0 ) {
  73.              x=1
  74.            }
  75.          } else {
  76.            print $0
  77.          }
  78.        }' $TMP > $F 
  79.  
  80. # call inews to mail it
  81. LINES=`wc -l $F | awk '{print $1}'`
  82. LINES=`expr $LINES + 7`
  83. (
  84. echo "Newsgroups: $GROUP"
  85. echo "From: $FROM"
  86. #echo "From: $REPLY"
  87. echo "Subject: $SUBJ"
  88. #echo "Reply-To: $REPLY"
  89. echo "Reply-To: $FROM"
  90. echo "Organization: $ORG"
  91. echo "Path: $GROUPNAME"
  92. echo "Sender: $REPLY"
  93. echo "Lines: $LINES"
  94. echo ""
  95. cat $F
  96. ) | cat > $POST
  97.  
  98. $INEWS -z -h $POST
  99.  
  100. DATE=`date`
  101. # Log it
  102. echo "$DATE $GROUP: $FROM [$SUBJ]" >> $LOG
  103.  
  104. fi # this was gated from news by us and echoed by the target
  105.  
  106. #Clean up
  107. rm -f $TMP $F $POST
  108.  
  109. # Clean up the log if it is too long
  110. LENGTH=`wc -l $LOG | awk '{print $1}'`
  111. if [ $LENGTH -gt 1000 ]
  112. then
  113.   tail -1000 $LOG > $TMP
  114.   mv $TMP $LOG
  115. fi
  116.