summaryrefslogtreecommitdiffstats
path: root/cgi-bin/get-raw-msg
blob: 737252bfe2d8413f687457b2cad15b6610cb8872 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#! /bin/sh

CONVAWK=/www/sourceware/cgi-bin/conv.awk

HEADER='<body><h1 align="center"><a href="/">GCC</a> raw message request-o-matic</h1>'
FOOTER='<hr><a href="/">Click here</a> to return to the front GCC web page</body></html>'

if [ ! -f /usr/bin/gawk ]
then
     GAWK=gawk
else
     GAWK=/usr/bin/gawk
fi

normalize()
{

   resultstr="`echo $1 | sed 's/+/ /g'`" # first convert +s to spaces
   resultstr=`echo $resultstr | $GAWK -f $CONVAWK`

} # normalize()

##  Expect three parameters, listname, datespec, and msgnum

listname=""
msgnum=""

for i in `echo $QUERY_STRING | awk '-F&' '{for (i = 1 ; i <= NF ; i++)  \
                                    printf "%s\n" , $i }'`
do
   normalize $i     # modifies global var ``resultstr''

   case "$resultstr" in
      listname=*) 
          listname=`echo $resultstr | 
                tr '[A-Z]' '[a-z]' |
                sed -e 's/^listname=//' -e 's,@.*$,,' -e 's,[^-a-zA-Z0-9_+],,g'`
          resultstr="" ;;
      msgnum=*) msgnum=`echo $resultstr | 
                sed -e 's/^msgnum=//' -e 's,[^0-9],,g'`
                resultstr="" ;;
      msgid=*) msgid=`echo $resultstr | 
                sed -e 's/^msgid=//' | tr -d '[:cntrl:]'`
                resultstr="" ;;
      date=*) date=`echo $resultstr | 
                sed -e 's/^date=//' -e 's,[^-0-9q],,g'`
                resultstr="" ;;
      skipmung* | nomung* | dontmung* | mung*=no | mung*=off) skipmunging=yes 
                resultsr="" ;;
          *) resultstr="" ;;
   esac
done

error=0
if [ -d "/www/gcc/ml/$listname/$date/txt" ]
then
  cd "/www/gcc/ml/$listname/$date/txt"
else
  if [ -d "/www/sourceware/ml/$listname/$date/txt" ]
  then
    cd "/www/sourceware/ml/$listname/$date/txt"
  else
    error=1
  fi
fi

if [ -n "$msgid" ]
then
  mtmp=`fgrep -- "$msgid " index | head -1 | cut -d ' ' -f2 | sed 's,[^0-9],,g'`
  if [ -n "$mtmp" ]
  then
    msgnum="$mtmp"
  fi
fi

if [ -n "$skipmunging" ]
then
  if [ "$skipmunging" = yes -o "$skipmunging" = 1 ]
  then
    skipmunging=yes
  else
    skipmunging=no
  fi
else
  skipmunging=no
fi

filename=`printf "msg%05d.txt" $msgnum`

filename_with_ext=""
catter=""

if [ -f "${filename}.bz2" ]
then
  filename_with_ext="${filename}.bz2"
  catter="bzcat"
fi
if [ -f "${filename}.gz" ]
then
  filename_with_ext="${filename}.gz"
  catter="zcat"
fi
if [ -f "${filename}.Z" ]
then
  filename_with_ext="${filename}.Z"
  catter="zcat"
fi
if [ -f "${filename}" ]
then
  filename_with_ext="${filename}"
  catter="cat"
fi

if [ $error -eq 1 -o -z "$date" -o -z "$listname" \
     -o -z "$msgnum" -o -z "$filename_with_ext" -o -z "$catter" ]
then
  echo "Content-type: text/html"
  echo ""
  echo "<HTML>"
  echo "<head>"
  echo "<TITLE>Unable to find message</TITLE>"
  echo "</head>"
  echo $HEADER

  echo "<p>I can't find the requested message - most likely I had some trouble handling this particular message-id."

  echo $FOOTER
  exit 0
fi

# if we have gzipped content, we could send a Content-encoding: x-gzip
# header and splat the compressed content down the pipe.  To be really
# accurate we'd want to check if the client sent us an Accept-Encoding
# header with 'gzip' before doing this.  But hey, maybe it'd be one
# more step to hose harvester programs if we sent gzip without asking...

echo "Content-type: text/plain"
echo ""

# This is a cheesy attempt to munge e-mail addresses in some of the
# common header lines which have e-mail addresses in them.
#
# The bad news is that this munging makes the e-mail note invalid - you
# can't just save it to a file, bring it up in your MUA, and reply to it.
# The good news is that harvesters have to work harder to get our addresses.

if [ "$skipmunging" = yes ]
then
  $catter "$filename_with_ext"
else
  $catter "$filename_with_ext" | awk 'BEGIN {in_header = 1} \
   { \
     if (in_header && $0 == "")
       {
         in_header = 0
       }
     if (in_header == 1) 
       {
         munge_this = 0
         if (munged_last_header && 
             (substr ($0, 0, 1) == " " || substr ($0, 0, 1) == "	"))
           {
             munge_this=1
           }
         if (tolower ($1) == "from") { munge_this = 1 }
         if (tolower ($1) == "return-path:") { munge_this = 1 }
         if (tolower ($1) == "delivered-to:") { munge_this = 1 }
         if (tolower ($1) == "mailing-list:") { munge_this = 1 }
         if (tolower ($1) == "list-subscribe:") { munge_this = 1 }
         if (tolower ($1) == "list-help:") { munge_this = 1 }
         if (tolower ($1) == "list-post:") { munge_this = 1 }
         if (tolower ($1) == "sender:") { munge_this = 1 }
         if (tolower ($1) == "from:") { munge_this = 1 }
         if (tolower ($1) == "to:") { munge_this = 1 }
         if (tolower ($1) == "cc:") { munge_this = 1 }
         if (tolower ($1) == "mail-followup-to:") { munge_this = 1 }
         if (tolower ($1) == "reply-to:") { munge_this = 1 }
         if (tolower ($1) == "in-reply-to:") { munge_this = 1 }
         if (tolower ($1) == "x-authentication-warning:") { munge_this = 1 }

         if (in_header && munge_this)
           {
             gsub ("@", " at ")
             gsub ("\\.", " dot ")
             munged_last_header=1
           }
       }
     print
   }'
fi

exit 0