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 ) { |
81 |
|
|
82 |
if ($param->{'search_val'} && $param->{'search_fld'} && !$param->{'search'}) { |
if ($param->{'search_val'} && $param->{'search_fld'} && !$param->{'search'}) { |
83 |
$param->{'search'} = $param->{'search_fld'}.":".$param->{'search_val'}; |
$param->{'search'} = $param->{'search_fld'}.":".$param->{'search_val'}; |
84 |
|
} elsif ($param->{'search'}) { |
85 |
|
($param->{'search_fld'}, $param->{'search_val'}) = split(/:/,$param->{'search'},2); |
86 |
} |
} |
87 |
|
|
88 |
|
my $tpl_var = { |
89 |
|
param => $param |
90 |
|
}; |
91 |
|
|
92 |
# show search results |
# show search results |
93 |
# ?search=foo:bar |
# ?search=foo:bar |
94 |
if ($param->{'search'}) { |
if ($param->{'search'}) { |
98 |
my $results = $mws->search($param->{'search'}); |
my $results = $mws->search($param->{'search'}); |
99 |
my @res = $mws->fetch_all_results(); |
my @res = $mws->fetch_all_results(); |
100 |
|
|
101 |
$tt->process($tpl_file, { |
$tpl_var->{results} = \@res; |
102 |
query => $param->{'search'}, |
|
|
results => \@res, |
|
|
param => $param, |
|
|
}, \$html) || die $tt->error(); |
|
103 |
|
|
104 |
# |
# |
105 |
# ?show_id=XXXXxxxx___message_id___xxxxXXXX |
# ?show_id=XXXXxxxx___message_id___xxxxXXXX |
106 |
} elsif ($param->{'show_id'}) { |
} elsif ($param->{'show_id'}) { |
107 |
|
|
108 |
my $row = $mws->fetch_result_by_id($param->{'show_id'}); |
my $row = $mws->fetch_result_by_id($param->{'show_id'}); |
109 |
$tt->process($tpl_file, { |
$tpl_var->{message} = $row; |
|
message => $row, |
|
|
}, \$html) || die $tt->error(); |
|
110 |
} |
} |
111 |
|
|
112 |
|
$tt->process($tpl_file, $tpl_var, \$html) || die $tt->error(); |
113 |
|
|
114 |
# |
# |
115 |
# send HTMLto client |
# send HTMLto client |
116 |
# |
# |
117 |
|
|
118 |
my $res = HTTP::Response->new(RC_OK); |
my $res = HTTP::Response->new(RC_OK); |
119 |
$res->header( 'Content-type' => 'text/html; charset=iso-8859-2' ); |
$res->header( 'Content-type' => 'text/html; charset=ISO-8859-2' ); |
120 |
$res->content($html); |
$res->content($html); |
121 |
$c->send_response($res); |
$c->send_response($res); |
122 |
|
|
134 |
$text =~ s/^\s+//gs; |
$text =~ s/^\s+//gs; |
135 |
$text =~ s/^[\>:\|=]+\s*.*?$//msg; # remove quoted text |
$text =~ s/^[\>:\|=]+\s*.*?$//msg; # remove quoted text |
136 |
$text =~ s/[\n\r]+/\n/gs; # compress cr/lf |
$text =~ s/[\n\r]+/\n/gs; # compress cr/lf |
137 |
$text =~ s,^((?:.*?[\n\r]){5}).*$,$1<span style="color:#808080">--8<--[cut]--8<--</span>,s; |
if ($text =~ s,^((?:.*?[\n\r]){5}).*$,$1,s) { |
138 |
|
$text =~ s/[\n\r]*$/ .../; |
139 |
|
} |
140 |
$text =~ s/[\n\r]+--\s*[\n\r]+.*$//s; |
$text =~ s/[\n\r]+--\s*[\n\r]+.*$//s; |
141 |
|
|
142 |
# my $context = Text::Context::EitherSide->new($text, context => 5); |
# my $context = Text::Context::EitherSide->new($text, context => 5); |
145 |
return $text; |
return $text; |
146 |
} |
} |
147 |
|
|
148 |
|
sub subject_search_filter { |
149 |
|
my $s = shift; |
150 |
|
# remove re: fdw: [list] preffixes from e-mail |
151 |
|
while ( $s =~ s/^\s*\[(?:re|fwd|fw):\s+(.+)\]\s*$/$1/ig || |
152 |
|
$s =~ s/^\s*(?:re|fwd|fw):\s+(.+?)\s*$/$1/ig || |
153 |
|
$s =~ s/^\[\S+\]\s*//ig || |
154 |
|
$s =~ s/^\[[^@]+@\w+\.\w+\s*:\s+(.+)\s*\]\s*$/$1/g |
155 |
|
) { }; |
156 |
|
return $s; |
157 |
|
} |