7
$MIME_DECODE = "-m -e";
10
# $CONV = "w3m -dump -e";
12
$MIME_DECODE = "@NKF@ -m -e";
14
$MIME_TYPE = "$ENV{'HOME'}/.mime.types";
16
$SCRIPT_NAME = $ENV{'SCRIPT_NAME'} || $0;
17
$CGI = "file://$SCRIPT_NAME";
19
if ($ENV{'REQUEST_METHOD'} eq 'POST') {
20
sysread(STDIN, $query, $ENV{'CONTENT_LENGTH'});
21
} elsif (defined($ENV{'QUERY_STRING'})) {
22
$query = $ENV{'QUERY_STRING'};
24
if (defined($query)) {
25
for (split('&', $query)) {
29
$file = &form_decode($v{'file'});
30
$boundary = &form_decode($v{'boundary'});
37
(-f $file) || exit(1);
38
open(F, "< $file") || exit(1);
41
if (defined($boundary)) {
44
($_ eq "--$boundary") && last;
45
($_ eq "--$boundary--") && ($end = 1, last);
59
if (defined($v{'count'})) {
61
while($count < $v{'count'}) {
64
($_ eq "--$boundary") && last;
77
$_ = &decode($_, $MIME_DECODE);
79
if (s/^(\S+)\s*:\s*//) {
81
if ($h =~ /^w3m-control/i) {
94
$type = $header{"content-type"};
95
$dispos = $header{"content-disposition"};
96
if ($type =~ /application\/octet-stream/) {
97
if ($type =~ /type\=gzip/) {
98
print "Content-Encoding: x-gzip\n";
100
if ($type =~ /name=\"?([^\"]+)\"?/ ||
101
$dispos =~ /filename=\"?([^\"]+)\"?/) {
102
$type = &guess_type($1);
104
print "Content-Type: $type; name=\"$1\"\n";
106
print "Content-Type: text/plain; name=\"$1\"\n";
115
($_ eq "--$boundary") && last;
116
if ($_ eq "--$boundary--") {
125
$qcgi = &html_quote($CGI);
126
$qfile = &html_quote($file);
127
$qboundary = &html_quote($boundary);
129
if ($mbody =~ /\S/) {
147
$_ = &decode($_, $MIME_DECODE);
149
if (s/^(\S+)\s*:\s*//) {
160
$type = $header{"content-type"};
161
$dispos = $header{"content-disposition"};
164
if (! $dispos || $dispos =~ /^inline/i) {
165
if (! $type || $type =~ /^text\/plain/i) {
167
} elsif ($type =~ /^image\//i) {
174
($_ eq "--$boundary") && last;
175
if ($_ eq "--$boundary--") {
193
if ($type =~ /name=\"?([^\"]+)\"?/ ||
194
$dispos =~ /filename=\"?([^\"]+)\"?/) {
199
print "<form action=\"$qcgi\">\n";
200
print "<input type=hidden name=file value=\"$qfile\">\n";
201
print "<input type=hidden name=boundary value=\"$qboundary\">\n";
202
print "<input type=hidden name=count value=\"$count\">\n";
204
print "<input type=image name=submit src=\"$qcgi?file=",
205
&html_quote(&form_encode($file)),
207
&html_quote(&form_encode($boundary)),
208
"&count=$count\" alt=\"",
209
&html_quote($name), "\">\n";
211
print "<input type=submit name=submit value=\"",
212
&html_quote($name), "\">\n";
217
$body = &decode($body, $CONV);
233
local($body, $opt) = @_;
234
return nkf($opt, $body);
236
local($body, @cmd) = @_;
247
open(STDOUT, ">&W2");
271
s/[<>&"]/$QUOTE{$&}/g;
278
s/%([\da-f][\da-f])/pack('c', hex($1))/egi;
284
s/[\000-\040\+:#?&%<>"\177-\377]/sprintf('%%%02X', unpack('C', $&))/eg;
291
/\.(\w+)$/ || return "";
294
%mime_type = &load_mime_type($MIME_TYPE);
300
local(%m, $a, @b, $_);
302
open(M, "< $file") || return ();
306
(($a, @b) = split(" ")) >= 2 || next;