home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / N / CNEWS / _CNEWS.TAR / usr / lib / newsbin / inject / pnews < prev    next >
Encoding:
Text File  |  1994-09-02  |  3.1 KB  |  101 lines

  1. #! /bin/sh
  2. # pnews [prefix] - prepare user's article on stdin for posting via relaynews
  3. #    prefix is for tear; if given, output will also be in
  4. #    ${prefix}hdr & ${prefix}body
  5.  
  6. # =()<. ${NEWSCONFIG-@<NEWSCONFIG>@}>()=
  7. . ${NEWSCONFIG-/var/lib/news/bin/config}
  8. export NEWSCTL NEWSBIN NEWSARTS NEWSPATH NEWSUMASK NEWSMASTER NEWSCONFIG
  9. PATH=$NEWSCTL/bin:$NEWSBIN/inject:$NEWSBIN:$NEWSPATH; export PATH
  10. prefix=/tmp/pn$$        # default prefix
  11. hdrs=/tmp/pn$$hdrs        # 1036-conformant headers
  12. rmlist="$inhdrs $inbody $hdrs"    # remove hdr & body files by default
  13.  
  14. umask $NEWSUMASK
  15.  
  16. # argument procesing
  17. case $# in
  18. 0)    ;;
  19. 1)
  20.     prefix="$1"
  21.     rmlist="$hdrs"        # only remove scratch file(s)
  22.     ;;
  23. *)
  24.     echo "usage: $0 [prefix]" >&2
  25.     exit 1
  26.     ;;
  27. esac
  28. inhdrs=${prefix}hdr        # generated by tear: headers
  29. inbody=${prefix}body        # generated by tear: body
  30.  
  31. tear $prefix        # output in $inhdrs and $inbody ** takes 0.4 seconds
  32.  
  33. # generate new headers and bash old headers ** takes 2.1 seconds
  34.  
  35. # touch up headers & rewrite dates to make them 1036-compliant.
  36. # canonicalise header keyword capitalisation;
  37. # greps for Control: and Approved: later assume this, as does defhdrs.awk,
  38. # so $inhdrs needs to stick around and be canonicalised.
  39. if canonhdr -dm <$inhdrs >$hdrs; then    # dredge up defaults ** takes 0.1 secs
  40.     # get time & pid from the server
  41.     me="` hostname `"
  42.     server="` cat $NEWSCTL/server 2>/dev/null `"
  43.     case "$server" in
  44.     "")    server="$me" ;;        # if no server file, assume this is it
  45.     esac
  46.     case "$me" in
  47.     $server) args= ;;
  48.     *)    args="`
  49.             (echo PATH=$PATH
  50.              echo 'echo -p $$ -t'
  51.              echo getdate now) |
  52.                 rsh $server /bin/sh
  53.         `" ;;
  54.     esac
  55.  
  56.     # POLICY: msgid format; usg gcos?
  57.     # tailor: add -u for USG GCOS fields
  58.     eval ` defaults $args `        # sets def* variables
  59.     case "$defname" in
  60.     "")    fullname="" ;;        # no full name, leave it off
  61.     *)    fullname=" ($defname)" ;;
  62.     esac
  63.  
  64.     # badsites="pucc.bitnet!"  # tailor, syntax is "host1!host2!...host3!"
  65.     awk -f $NEWSBIN/inject/defhdrs.awk \
  66.      defpath="$badsites$defuser" \
  67.      deffrom="$defuser@$defmailname$fullname" deforg="$deforg" \
  68.      defmsgid="$defmsgid" me="$defhostname" $hdrs >$inhdrs
  69.     status=$?
  70. else    status=$? # shouldn't be needed, but some major shells get it wrong
  71. fi
  72.  
  73. # pad zero-line articles, since old B [ir]news are confused by them
  74. # and the news readers generate zero-line control messages, alas.
  75. if test ! -s $inbody; then
  76.     (echo '';
  77.      echo This article was probably generated by a buggy news reader.) \
  78.      >$inbody
  79. fi
  80.  
  81. # output begins here
  82. (
  83. # POLICY: don't generate Lines: because it is optional, munged in transit
  84. # by B News to make the count incorrect, and not pulling its weight.
  85. # If you just *have* to generate Lines: headers, uncomment line A and comment
  86. # out line B.
  87. # . lines                # NB: reads $inbody # line A
  88. firstline="` sed 1q $inbody `"            # line B
  89. case "$firstline" in                # line B
  90. '')    cat $inhdrs $inbody ;;            # emit the article  # line B
  91. *)    echo | cat $inhdrs - $inbody ;;        # insert blank line # line B
  92. esac                        # line B
  93.  
  94. if test -r $HOME/.signature; then
  95.     # POLICY: chop .sigs at 4 lines
  96.     echo "-- "; sed 4q $HOME/.signature    # glue on first bit of signature
  97. fi
  98. ) | stripinvis
  99. rm -f $rmlist
  100. exit $status
  101.