15 |
use Data::Dumper; |
use Data::Dumper; |
16 |
|
|
17 |
my $d = HTTP::Daemon->new( Reuse => 1, LocalPort => 6969 ) || die; |
my $d = HTTP::Daemon->new( Reuse => 1, LocalPort => 6969 ) || die; |
|
print "Please contact me at: <URL:", $d->url, ">\n"; |
|
|
|
|
18 |
my $cgi = new CGI::Lite; |
my $cgi = new CGI::Lite; |
19 |
my $mws = MWS->new('global.conf'); |
my $mws = MWS->new('global.conf'); |
20 |
my $tt = Template->new({ |
my $tt = Template->new({ |
21 |
INCLUDE_PATH => $mws->{config}->val('global', 'templates'), |
INCLUDE_PATH => $mws->{config}->val('global', 'templates'), |
22 |
FILTERS => { |
FILTERS => { |
23 |
'body5' => \&body5_filter, |
'body5' => \&body5_filter, |
24 |
|
'subject_search' => \&subject_search_filter, |
25 |
}, |
}, |
26 |
}); |
}); |
27 |
|
|
28 |
|
print "Web server ready at: ", $d->url, "\n"; |
29 |
|
|
30 |
|
|
31 |
while ( my $c = $d->accept ) { |
while ( my $c = $d->accept ) { |
32 |
while ( my $r = $c->get_request ) { |
while ( my $r = $c->get_request ) { |
70 |
# XXX LOG |
# XXX LOG |
71 |
print $r->method," ",$url,Dumper($param); |
print $r->method," ",$url,Dumper($param); |
72 |
|
|
73 |
# generate HTML |
# template file name (use ?format=html as default) |
74 |
|
my $tpl_file = 'master.'; |
75 |
|
$tpl_file .= $param->{'format'} || 'html'; |
76 |
|
|
77 |
|
# |
78 |
|
# implement functionality and generate HTML |
79 |
|
# |
80 |
my $html; |
my $html; |
81 |
|
|
82 |
my $s=$param->{'search'}; |
if ($param->{'search_val'} && $param->{'search_fld'} && !$param->{'search'}) { |
83 |
|
$param->{'search'} = $param->{'search_fld'}.":".$param->{'search_val'}; |
84 |
|
} |
85 |
|
|
86 |
if ($s) { |
my $tpl_var = { |
87 |
|
param => $param |
88 |
|
}; |
89 |
|
|
90 |
print STDERR "search: $s\n"; |
# show search results |
91 |
|
# ?search=foo:bar |
92 |
|
if ($param->{'search'}) { |
93 |
|
|
94 |
my $results = $mws->search($s); |
print STDERR "search: ",$param->{'search'},"\n"; |
95 |
|
|
96 |
|
my $results = $mws->search($param->{'search'}); |
97 |
my @res = $mws->fetch_all_results(); |
my @res = $mws->fetch_all_results(); |
98 |
|
|
99 |
my $tpl_file = 'master.'; |
$tpl_var->{results} = \@res; |
|
$tpl_file .= $param->{'format'} || 'html'; |
|
100 |
|
|
101 |
$tt->process($tpl_file, { |
|
102 |
query => $s, |
# |
103 |
results => \@res, |
# ?show_id=XXXXxxxx___message_id___xxxxXXXX |
104 |
param => $param, |
} elsif ($param->{'show_id'}) { |
105 |
}, \$html) || die $tt->error(); |
|
106 |
|
my $row = $mws->fetch_result_by_id($param->{'show_id'}); |
107 |
|
$tpl_var->{message} = $row; |
108 |
} |
} |
109 |
|
|
110 |
|
$tt->process($tpl_file, $tpl_var, \$html) || die $tt->error(); |
111 |
|
|
112 |
|
# |
113 |
|
# send HTMLto client |
114 |
|
# |
115 |
|
|
116 |
my $res = HTTP::Response->new(RC_OK); |
my $res = HTTP::Response->new(RC_OK); |
117 |
$res->header( 'Content-type' => 'text/html; charset=iso-8859-2' ); |
$res->header( 'Content-type' => 'text/html; charset=ISO-8859-2' ); |
118 |
$res->content($html); |
$res->content($html); |
119 |
$c->send_response($res); |
$c->send_response($res); |
120 |
|
|
125 |
|
|
126 |
# template toolkit filter |
# template toolkit filter |
127 |
|
|
128 |
|
#use Text::Context::EitherSide; |
129 |
|
|
130 |
sub body5_filter { |
sub body5_filter { |
131 |
my $text = shift; |
my $text = shift; |
132 |
$text =~ s/^\s+//gs; |
$text =~ s/^\s+//gs; |
133 |
$text =~ s/^(.*?[\n\r]+){5}.*$/$1/s; |
$text =~ s/^[\>:\|=]+\s*.*?$//msg; # remove quoted text |
134 |
|
$text =~ s/[\n\r]+/\n/gs; # compress cr/lf |
135 |
|
if ($text =~ s,^((?:.*?[\n\r]){5}).*$,$1,s) { |
136 |
|
$text =~ s/[\n\r]*$/ .../; |
137 |
|
} |
138 |
|
$text =~ s/[\n\r]+--\s*[\n\r]+.*$//s; |
139 |
|
|
140 |
|
# my $context = Text::Context::EitherSide->new($text, context => 5); |
141 |
|
# return $context->as_string("perl"); |
142 |
|
|
143 |
return $text; |
return $text; |
144 |
} |
} |
145 |
|
|
146 |
|
sub subject_search_filter { |
147 |
|
my $s = shift; |
148 |
|
# remove re: fdw: [list] preffixes from e-mail |
149 |
|
while ( $s =~ s/^\s*\[(?:re|fwd):\s+(.+)\]\s*$/$1/ig || |
150 |
|
$s =~ s/^\s*(?:re|fwd):\s+(.+?)\s*$/$1/ig || |
151 |
|
$s =~ s/^\[\w+\]\s*//ig |
152 |
|
) { }; |
153 |
|
return $s; |
154 |
|
} |