14 |
|
|
15 |
use Data::Dumper; |
use Data::Dumper; |
16 |
|
|
17 |
my $d = HTTP::Daemon->new( Reuse => 1, LocalPort => 6969 ) || die; |
my $debug = 1; |
|
print "Please contact me at: <URL:", $d->url, ">\n"; |
|
18 |
|
|
19 |
|
my $d = HTTP::Daemon->new( Reuse => 1, LocalPort => 6969 ) || die; |
20 |
my $cgi = new CGI::Lite; |
my $cgi = new CGI::Lite; |
21 |
my $mws = MWS->new('global.conf'); |
my $mws = MWS->new('global.conf'); |
22 |
my $tt = Template->new({ |
my $tt = Template->new({ |
23 |
INCLUDE_PATH => $mws->{config}->val('global', 'templates'), |
INCLUDE_PATH => $mws->{config}->val('global', 'templates'), |
24 |
FILTERS => { |
FILTERS => { |
25 |
'body5' => \&body5_filter, |
'body5' => \&body5_filter, |
26 |
|
'subject_search' => \&subject_search_filter, |
27 |
}, |
}, |
28 |
}); |
}); |
29 |
|
|
30 |
|
print "Web server ready at: ", $d->url, "\n"; |
31 |
|
|
32 |
|
|
33 |
while ( my $c = $d->accept ) { |
while ( my $c = $d->accept ) { |
34 |
while ( my $r = $c->get_request ) { |
while ( my $r = $c->get_request ) { |
70 |
my $url = $r->url->path; |
my $url = $r->url->path; |
71 |
|
|
72 |
# XXX LOG |
# XXX LOG |
73 |
print $r->method," ",$url,Dumper($param); |
print $r->method," ",$url,"\n",Dumper($param),"\n" if ($debug); |
74 |
|
|
75 |
# template file name (use ?format=html as default) |
# template file name (use ?format=html as default) |
76 |
my $tpl_file = 'master.'; |
my $tpl_file = 'master.'; |
81 |
# |
# |
82 |
my $html; |
my $html; |
83 |
|
|
84 |
|
if ($param->{'search_val'} && $param->{'search_fld'} && !$param->{'search'}) { |
85 |
|
$param->{'search'} = $param->{'search_fld'}.":".$param->{'search_val'}; |
86 |
|
} elsif ($param->{'search'}) { |
87 |
|
($param->{'search_fld'}, $param->{'search_val'}) = split(/:/,$param->{'search'},2); |
88 |
|
} |
89 |
|
|
90 |
|
my $tpl_var = { |
91 |
|
param => $param |
92 |
|
}; |
93 |
|
|
94 |
# show search results |
# show search results |
95 |
# ?search=foo:bar |
# ?search=foo:bar |
96 |
if ($param->{'search'}) { |
if ($param->{'search'}) { |
100 |
my $results = $mws->search($param->{'search'}); |
my $results = $mws->search($param->{'search'}); |
101 |
my @res = $mws->fetch_all_results(); |
my @res = $mws->fetch_all_results(); |
102 |
|
|
103 |
$tt->process($tpl_file, { |
$tpl_var->{results} = \@res; |
104 |
query => $param->{'search'}, |
$tpl_var->{total_hits} = $mws->{total_hits}; |
105 |
results => \@res, |
|
|
param => $param, |
|
|
}, \$html) || die $tt->error(); |
|
106 |
|
|
107 |
# |
# |
108 |
# ?show_id=XXXXxxxx___message_id___xxxxXXXX |
# ?show_id=XXXXxxxx___message_id___xxxxXXXX |
109 |
} elsif ($param->{'show_id'}) { |
} elsif ($param->{'show_id'}) { |
110 |
|
|
111 |
|
$mws->reset_counters; |
112 |
my $row = $mws->fetch_result_by_id($param->{'show_id'}); |
my $row = $mws->fetch_result_by_id($param->{'show_id'}); |
113 |
$tt->process($tpl_file, { |
$tpl_var->{message} = $row; |
114 |
message => $row, |
} |
115 |
}, \$html) || die $tt->error(); |
|
116 |
|
print Dumper($mws->{counter}); |
117 |
|
|
118 |
|
# push counters to template |
119 |
|
foreach my $f (qw(from to cc bcc)) { |
120 |
|
my $h = $mws->counter($f) || next; |
121 |
|
my @a; |
122 |
|
foreach my $k (sort { $h->{$b}->{usage} <=> $h->{$a}->{usage} } keys %$h) { |
123 |
|
push @a, $h->{$k}; |
124 |
|
} |
125 |
|
$tpl_var->{counters}->{$f} = [ @a ] if (@a); |
126 |
} |
} |
127 |
|
|
128 |
|
$tt->process($tpl_file, $tpl_var, \$html) || die $tt->error(); |
129 |
|
|
130 |
# |
# |
131 |
# send HTMLto client |
# send HTMLto client |
132 |
# |
# |
133 |
|
|
134 |
my $res = HTTP::Response->new(RC_OK); |
my $res = HTTP::Response->new(RC_OK); |
135 |
$res->header( 'Content-type' => 'text/html; charset=iso-8859-2' ); |
$res->header( 'Content-type' => 'text/html; charset=ISO-8859-2' ); |
136 |
$res->content($html); |
$res->content($html); |
137 |
$c->send_response($res); |
$c->send_response($res); |
138 |
|
|
143 |
|
|
144 |
# template toolkit filter |
# template toolkit filter |
145 |
|
|
146 |
|
#use Text::Context::EitherSide; |
147 |
|
|
148 |
sub body5_filter { |
sub body5_filter { |
149 |
my $text = shift; |
my $text = shift; |
150 |
$text =~ s/^\s+//gs; |
$text =~ s/^\s+//gs; |
151 |
$text =~ s/[\n\r]+[\>:\|=]+\s*.*?[\n\r]+//sg; # remove quoted text |
$text =~ s/^[\>:\|=]+\s*.*?$//msg; # remove quoted text |
152 |
$text =~ s,^((?:.*?[\n\r]){5}).*$,$1<span style="color:#808080">--8<--[cut]--8<--</span>,s; |
$text =~ s/[\n\r]+/\n/gs; # compress cr/lf |
153 |
|
if ($text =~ s,^((?:.*?[\n\r]){5}).*$,$1,s) { |
154 |
|
$text =~ s/[\n\r]*$/ .../; |
155 |
|
} |
156 |
$text =~ s/[\n\r]+--\s*[\n\r]+.*$//s; |
$text =~ s/[\n\r]+--\s*[\n\r]+.*$//s; |
157 |
|
|
158 |
|
# my $context = Text::Context::EitherSide->new($text, context => 5); |
159 |
|
# return $context->as_string("perl"); |
160 |
|
|
161 |
return $text; |
return $text; |
162 |
} |
} |
163 |
|
|
164 |
|
sub subject_search_filter { |
165 |
|
my $s = shift; |
166 |
|
# remove re: fdw: [list] preffixes from e-mail |
167 |
|
while ( $s =~ s/^\s*\[(?:re|fwd|fw):\s+(.+)\]\s*$/$1/ig || |
168 |
|
$s =~ s/^\s*(?:re|fwd|fw):\s+(.+?)\s*$/$1/ig || |
169 |
|
$s =~ s/^\[\S+\]\s*//ig || |
170 |
|
$s =~ s/^\[[^@]+@\w+\.\w+\s*:\s+(.+)\s*\]\s*$/$1/g || |
171 |
|
$s =~ s/\(fwd\)\s*$//ig || |
172 |
|
$s =~ s/\"//g |
173 |
|
) { }; |
174 |
|
return $s; |
175 |
|
} |