/[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 27 by dpavlin, Sat May 8 20:34:26 2004 UTC revision 28 by dpavlin, Sat May 8 22:18:38 2004 UTC
# Line 35  my $tt = Template->new({ Line 35  my $tt = Template->new({
35          INCLUDE_PATH => $mws->{config}->val('global', 'templates'),          INCLUDE_PATH => $mws->{config}->val('global', 'templates'),
36          FILTERS => {          FILTERS => {
37                  'body5' => \&body5_filter,                  'body5' => \&body5_filter,
38                    'body' => \&body_filter,
39          },          },
40          EVAL_PERL => 1,          EVAL_PERL => 1,
41  });  });
# Line 138  while ( my $c = $d->accept ) { Line 139  while ( my $c = $d->accept ) {
139                  if ($url eq "/" && !$param->{'search'}) {                  if ($url eq "/" && !$param->{'search'}) {
140                          # if first access, go to current year                          # if first access, go to current year
141                          $date_limit = $mws->fmtdate($yyyy);                          $date_limit = $mws->fmtdate($yyyy);
142                          $param->{sort} = "date desc";                          $param->{sort_by} = "date desc";
143                  }                  }
144    
145                  # ?show_id=XXXXxxxx___message_id___xxxxXXXX                  # ?show_id=XXXXxxxx___message_id___xxxxXXXX
# Line 206  while ( my $c = $d->accept ) { Line 207  while ( my $c = $d->accept ) {
207    
208  # template toolkit filter  # template toolkit filter
209    
210    sub html_escape($) {
211            my $text = shift;
212    
213            # Escape <, >, & and ", and to produce valid XML
214            my %escape = ('<'=>'&lt;', '>'=>'&gt;', '&'=>'&amp;', '"'=>'&quot;');
215            my $escape_re  = join '|' => keys %escape;
216    
217            $text =~ s/($escape_re)/$escape{$1}/gs;
218            return $text;
219    }
220    
221  #use Text::Context::EitherSide;  #use Text::Context::EitherSide;
222    
223  sub body5_filter {  sub body5_filter {
224          my $text = shift;          my $text = shift;
225          $text =~ s/^\s+//gs;  
226          $text =~ s/^[\>:\|=]+\s*.*?$//msg;      # remove quoted text          # remove quote
227          $text =~ s/[\n\r]+/\n/gs;               # compress cr/lf          $text =~ s/^[\>:\|=]+\s*.*?$/#-q-#/msg;
228            # remove quote author
229            $text =~ s/[\n\r]+[^\n\r]+:\s*(:?#-q-#[\n\r*])+//gs;
230            $text =~ s/^[^\n\r]+:\s*(:?#-q-#[\n\r]*)+//gs;
231            # outlook quoting
232            $text =~ s/(\s*--+\s*Original\s+Message\s*--+.*)$//si;
233            $text =~ s/(\s*--+\s*Forwarded\s+message\s*from\s+.+\s*--+.*)$//si;
234    
235            # remove signature
236            $text =~ s/[\n\r]+--\s*[\n\r]+.*$//s;
237    
238            # compress cr/lf
239            $text =~ s/[\n\r]+/\n/gs;
240    
241            # remove whitespaces
242            $text =~ s/^\n+//gs;
243            $text =~ s/[\s\n]+$//gs;
244    
245            # cut to 5 lines;
246          if ($text =~ s,^((?:.*?[\n\r]){5}).*$,$1,s) {          if ($text =~ s,^((?:.*?[\n\r]){5}).*$,$1,s) {
247                  $text =~ s/[\n\r]*$/ .../;                  $text =~ s/[\n\r]*$/ .../;
248          }          }
         $text =~ s/[\n\r]+--\s*[\n\r]+.*$//s;  
249    
250  #       my $context = Text::Context::EitherSide->new($text, context => 5);  #       my $context = Text::Context::EitherSide->new($text, context => 5);
251  #       return $context->as_string("perl");  #       return $context->as_string("perl");
252    
253            return html_escape($text);
254    }
255    
256    sub body_filter {
257            my $text = shift;
258    
259            my $sig = '';
260    
261            # remove signature
262            if ($text =~ s/([\n\r]+)(--\s*[\n\r]+.*)$//s) {
263                    $sig = "$1#-#signature##$2##signature#-#";
264            }
265    
266            # find quoted text
267            $text =~ s/^([\>:\|=]+\s*.*?)$/#-#quote##$1##quote#-#/msg;
268            $text =~ s/(--+\s*Original\s+Message\s*--+.*)$/#-#quote##$1##quote#-#/si || $text =~ s/(--+\s*Forwarded\s+message\s*from\s+.+\s*--+.*)$/#-#quote##$1##quote#-#/si;
269    
270            $text = html_escape($text . $sig);
271            $text =~ s/#-#(quote|signature)##(.+?)##(\1)#-#/<span class="$1">$2<\/span>/gs;
272          return $text;          return $text;
273  }  }
274    

Legend:
Removed from v.27  
changed lines
  Added in v.28

  ViewVC Help
Powered by ViewVC 1.1.26