Put all the logic of BODY in a separate nntp_body.cgi - gophercgis - Collection of gopher CGI/DCGI for geomyidae
 (HTM) hg clone https://bitbucket.org/iamleot/gophercgis
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) changeset 24230ba94e36956f2afc0acfe297bb9d1de75c20
 (DIR) parent b7125513610aacec23597988701ffe56139255ee
 (HTM) Author: Leonardo Taccari <iamleot@gmail.com>
       Date:   Mon, 13 Aug 2018 02:40:52 
       
       Put all the logic of BODY in a separate nntp_body.cgi
       
       In this way it is no longer needed to gph-ize the BODY and it can be easily
       served as a `0' item.
       
       Diffstat:
        nntp/nntp_body.cgi |  68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
        1 files changed, 68 insertions(+), 0 deletions(-)
       ---
       diff -r b7125513610a -r 24230ba94e36 nntp/nntp_body.cgi
       --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
       +++ b/nntp/nntp_body.cgi        Mon Aug 13 02:40:52 2018 +0200
       @@ -0,0 +1,68 @@
       +#!/bin/sh
       +
       +NNTP_SERVER="news.gmane.org"
       +NNTP_PORT="119"
       +NNTP_CMD="nc ${NNTP_SERVER} ${NNTP_PORT}"
       +
       +
       +case "$2" in
       +*/[0-9]*)
       +       # BODY (show) of article `msg'
       +       group="${2%%/*}"
       +       msg="${2##*/}"
       +       ;;
       +esac
       +
       +
       +#
       +# BODY (and headers) of the selected `msg'
       +#
       +nntp_body()
       +{
       +       g="$1"
       +       msg="$2"
       +
       +       { echo "group ${g}"; echo "over ${msg}"; echo "body ${msg}"; echo "quit"; } |
       +               ${NNTP_CMD} |
       +               awk '
       +                       BEGIN {
       +                               FS = "\t"
       +                               body = 1
       +                               over = 1
       +                       }
       +
       +                       /^\.\r$/ {
       +                               if (over && body) {
       +                                       over = 0
       +                               } else {
       +                                       body = 0
       +                               }
       +                               next
       +                       }
       +
       +                       NR > 3 && over {
       +                               id = $1
       +                               subject = $2
       +                               from = $3
       +                               date = $4
       +                               print "Date:    " date
       +                               print "To:      " "'"${g}"'"
       +                               print "From:    " from
       +                               print "Subject: " subject
       +                               print ""
       +                       }
       +
       +                       NR > 6 && body {
       +                               print $0
       +                       }
       +               '
       +}
       +
       +
       +#
       +# <group>/<msg>: show the article
       +#
       +if [ "${msg}" ] && [ "${msg}" -gt 0 ]; then
       +       nntp_body "${group}" "${msg}"
       +       exit 0
       +fi