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
---
nntp_body.cgi
---
1 #!/bin/sh
2
3 . ../common/config.sh
4
5 NNTP_SERVER="news.gmane.org"
6 NNTP_PORT="119"
7 NNTP_CMD="nc ${NNTP_SERVER} ${NNTP_PORT}"
8
9
10 case "$2" in
11 */[0-9]*)
12 # BODY (show) of article `msg'
13 group="${2%%/*}"
14 msg="${2##*/}"
15 ;;
16 esac
17
18
19 #
20 # BODY (and headers) of the selected `msg'
21 #
22 nntp_body()
23 {
24 g="$1"
25 msg="$2"
26
27 { echo "group ${g}"; echo "over ${msg}"; echo "body ${msg}"; echo "quit"; } |
28 ${NNTP_CMD} |
29 awk '
30 BEGIN {
31 FS = "\t"
32 body = 1
33 over = 1
34 }
35
36 /^\.\r$/ {
37 if (over && body) {
38 over = 0
39 } else {
40 body = 0
41 }
42 next
43 }
44
45 NR > 3 && over {
46 id = $1
47 subject = $2
48 from = $3
49 date = $4
50 print "Date: " date
51 print "To: " "'"${g}"'"
52 print "From: " from
53 print "Subject: " subject
54 print ""
55 }
56
57 NR > 6 && body {
58 print $0
59 }
60 '
61 }
62
63
64 #
65 # <group>/<msg>: show the article
66 #
67 if [ "${msg}" ] && [ "${msg}" -gt 0 ]; then
68 nntp_body "${group}" "${msg}"
69 exit 0
70 fi