/[mws]/trunk/httpd.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/httpd.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 20 by dpavlin, Fri May 7 23:35:39 2004 UTC revision 25 by dpavlin, Sat May 8 16:06:58 2004 UTC
# Line 11  use IO::String; Line 11  use IO::String;
11  use CGI::Lite;  use CGI::Lite;
12  use Template;  use Template;
13  use MWS;  use MWS;
14    use URI::Escape;
15    
16  use Data::Dumper;  use Data::Dumper;
17    
# Line 23  my $tt = Template->new({ Line 24  my $tt = Template->new({
24          INCLUDE_PATH => $mws->{config}->val('global', 'templates'),          INCLUDE_PATH => $mws->{config}->val('global', 'templates'),
25          FILTERS => {          FILTERS => {
26                  'body5' => \&body5_filter,                  'body5' => \&body5_filter,
                 'subject_search' => \&subject_search_filter,  
27          },          },
28          EVAL_PERL => 1,          EVAL_PERL => 1,
29  });  });
30    
31    my $static_html = $mws->{config}->val('global', 'static_html');
32    
33  print "Web server ready at: ", $d->url, "\n";  print "Web server ready at: ", $d->url, "\n";
34    
35    
# Line 73  while ( my $c = $d->accept ) { Line 75  while ( my $c = $d->accept ) {
75                  # XXX LOG                  # XXX LOG
76                  print $r->method," ",$url,"\n",Dumper($param),"\n" if ($debug);                  print $r->method," ",$url,"\n",Dumper($param),"\n" if ($debug);
77    
78                    # is this static page?
79                    if ($static_html && -f "$static_html/$url") {
80                            print "static file: $static_html/$url\n" if ($debug);
81                            $c->send_file_response("$static_html/$url");
82                            $c->close;
83                            next;
84                    }
85    
86                  # template file name (use ?format=html as default)                  # template file name (use ?format=html as default)
87                  my $tpl_file = 'master.';                  my $tpl_file = 'master.';
88                  $tpl_file .= $param->{'format'} || 'html';                  $tpl_file .= $param->{'format'} || 'html';
# Line 110  while ( my $c = $d->accept ) { Line 120  while ( my $c = $d->accept ) {
120                          yyyy    => $yyyy,                          yyyy    => $yyyy,
121                          mm      => $mm,                          mm      => $mm,
122                          dd      => $dd,                          dd      => $dd,
123                            date_limit => $date_limit,
124                  };                  };
125    
126                  if ($date_limit) {                  #
127                          $param->{'search'} .= "and " if ($param->{'search'});                  # ?show_id=XXXXxxxx___message_id___xxxxXXXX
128                          $param->{'search'} .= $date_limit;                  if ($param->{'show_id'}) {
                 }  
129    
130                  # show search results                          $mws->reset_counters;
131                  # ?search=foo:bar                          my $row = $mws->fetch_result_by_id($param->{'show_id'});
132                  if ($param->{'search'}) {                          $tpl_var->{message} = $row;
133                    } elsif ($param->{'search'} || $date_limit) {
134    
135                          print STDERR "search: ",$param->{'search'},"\n";                          # show search results
136                            # ?search=foo:bar
137    
138                          my $results = $mws->search($param->{'search'});                          my @search = ( $param->{'search'} );
                         my @res = $mws->fetch_all_results();  
139    
140                          $tpl_var->{results} = \@res if (@res);                          if ($date_limit) {
141                          $tpl_var->{total_hits} = $mws->{total_hits};                                  push @search, "and" if (@search);
142                                    push @search, "date:\"$date_limit\"";
143                            }
144    
145                            if ($param->{sort_by}) {
146                                    push @search, "sort:".$param->{sort_by};
147                            }
148    
149                  #                          print STDERR "search: ",join(" ",@search),"\n";
150                  # ?show_id=XXXXxxxx___message_id___xxxxXXXX  
151                  } elsif ($param->{'show_id'}) {                          my $results = $mws->search(@search);
152                            my @res = $mws->fetch_all_results();
153    
154                            $tpl_var->{results} = \@res if (@res);
155                            $tpl_var->{total_hits} = $mws->{total_hits} || 0;
156    
                         $mws->reset_counters;  
                         my $row = $mws->fetch_result_by_id($param->{'show_id'});  
                         $tpl_var->{message} = $row;  
157                  }                  }
158    
 print Dumper($mws->{counter});  
159    
160                  # push counters to template                  # push counters to template
161                  foreach my $f (qw(from to cc bcc)) {                  foreach my $f (qw(from to cc bcc)) {
# Line 190  sub body5_filter { Line 206  sub body5_filter {
206          return $text;          return $text;
207  }  }
208    
 sub subject_search_filter {  
         my $s = shift;  
         # remove re: fdw: [list] preffixes from e-mail  
         while ( $s =~ s/^\s*\[(?:re|fwd|fw):\s+(.+)\]\s*$/$1/ig ||  
                 $s =~ s/^\s*(?:re|fwd|fw):\s+(.+?)\s*$/$1/ig ||  
                 $s =~ s/^\[\S+\]\s*//ig ||  
                 $s =~ s/^\[[^@]+@\w+\.\w+\s*:\s+(.+)\s*\]\s*$/$1/g ||  
                 $s =~ s/\(fwd\)\s*$//ig ||  
                 $s =~ s/\"//g  
         ) { };  
         return $s;  
 }  

Legend:
Removed from v.20  
changed lines
  Added in v.25

  ViewVC Help
Powered by ViewVC 1.1.26