/[mws]/trunk/MWS.pm
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/MWS.pm

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 14  use Text::Iconv; Line 14  use Text::Iconv;
14  use Text::Unaccent;  use Text::Unaccent;
15  use Date::Parse;  use Date::Parse;
16  use POSIX qw(strftime);  use POSIX qw(strftime);
17    use MIME::Base64;
18    
19  #use MWS_plucene;  #use MWS_plucene;
20  use MWS_swish;  use MWS_swish;
# Line 65  sub normalize_string { Line 66  sub normalize_string {
66          $v = join('',sort split(/\s+/,$v));          $v = join('',sort split(/\s+/,$v));
67          $v =~ s/\W+//g;          $v =~ s/\W+//g;
68    
69          return $v;          return lc($v);
70  }  }
71    
72  # reset tables for search results  # reset tables for search results
# Line 205  sub fetch_message { Line 206  sub fetch_message {
206  sub search {  sub search {
207          my $self = shift;          my $self = shift;
208    
209          my $s = shift || carp "search called without argument!";          carp "search called without argument!" if (! @_);
210    
211          $self->reset_counters;          $self->reset_counters;
212    
213          print STDERR "search_index($s)\n" if ($debug == 2);          print STDERR "search(",join(" ",@_),")\n" if ($debug == 2);
214          my @index_ids = $self->search_index($s);          my @index_ids = $self->search_index(@_);
215    
216          $self->{'index_ids'} = \@index_ids;          $self->{'index_ids'} = \@index_ids;
217    
# Line 221  sub search { Line 222  sub search {
222    
223          $self->{'curr_result'} = 0;          $self->{'curr_result'} = 0;
224    
225            $self->reset_counters;
226    
227          print STDERR "$results results\n" if ($debug == 2);          print STDERR "$results results\n" if ($debug == 2);
228    
229          return $results || 'error';          return $results || 'error';
# Line 231  sub decode_qp($) { Line 234  sub decode_qp($) {
234    
235          my $tmp = shift || return;          my $tmp = shift || return;
236    
237          sub decode($$) {          sub decode($$$) {
238                  my ($cp,$qp) = @_;                  my ($cp,$enc,$qp) = @_;
239          print STDERR "decode($cp,$qp) -> " if ($debug == 2);  
240                  $qp =~ s/=([a-f0-9][a-f0-9])/chr(hex($1))/ieg;                  print STDERR "decode($cp,$qp) -> " if ($debug == 2);
241                  $qp =~ s/_/ /g;  
242          print STDERR "$qp -> " if ($debug == 2);                  if (uc($enc) eq "Q") {
243                            $qp =~ s/=([a-f0-9][a-f0-9])/chr(hex($1))/ieg;
244                            $qp =~ s/_/ /g;
245                    } elsif (uc($enc) eq "B") {
246                            $qp = decode_base64($qp);
247                    } else {
248                            croak "unsupported encoding '$enc' in decode_qp\n";
249                            return $qp;
250                    }
251    
252                    print STDERR "$qp\n" if ($debug == 2);
253    
254                  my $iconv = Text::Iconv->new($cp,'ISO-8859-2');                  my $iconv = Text::Iconv->new($cp,'ISO-8859-2');
255                  return $iconv->convert($qp) || '';                  return $iconv->convert($qp) || '';
256          }          }
257    
258          $tmp =~ s/=\?([^\?]+)\?Q\?(.+?)\?=/decode($1,$2)/ge;          $tmp =~ s/=\?([^\?]+)\?([QB])\?(.+?)\?=/decode($1,$2,$3)/ige;
259          $tmp =~ s/^\s*["']+(.*?)["']+\s*$/$1/g;          $tmp =~ s/^\s*["']+(.*?)["']+\s*$/$1/g;
260          #print STDERR "$tmp\n" if ($debug == 2);          #print STDERR "$tmp\n" if ($debug == 2);
261          return $tmp;          return $tmp;
# Line 316  sub plain_text_body { Line 330  sub plain_text_body {
330                  }                  }
331          }          }
332    
333            if (! $body) {
334                    $body = "[body of this message not found]\n" if ($debug == 2);
335                    $body .= $message->decoded->string;
336            }
337    
338          # reformat with Text::Autoformat          # reformat with Text::Autoformat
339          my $wrap = $self->{wrap_margin};          my $wrap = $self->{wrap_margin};
340          if ($wrap && $body && $body =~ m/^.{$wrap}..*$/m) {          if ($wrap && $body && $body =~ m/^.{$wrap}..*$/m) {
341                  $body =~ s/[\r\n]/\n/gs;                  $body = autoformat($body, {right=>$wrap, all=>1});
342                  $body = autoformat($body, {right=>$wrap});                  print "reformatted [$wrap]:\n$body\n" if ($debug == 2);
343                  $body .="\n[reformated using autoformat, margin at $wrap]" if ($debug == 2);                  $body .="\n[reformated using autoformat, margin at $wrap]" if ($debug == 2);
344          }          }
345    
# Line 344  sub fetch_result_by_id { Line 363  sub fetch_result_by_id {
363                  $row->{'id'} = $id;                  $row->{'id'} = $id;
364    
365                  foreach my $p (qw(from to cc bcc)) {                  foreach my $p (qw(from to cc bcc)) {
366                          foreach my $v ($self->unroll($message,'from','phrase')) {                          foreach my $v ($self->unroll($message,$p,'phrase')) {
367                                  push @{$row->{$p}},$v;                                  push @{$row->{$p}},$v;
368                                  $self->add_counter($p,$v);                                  $self->add_counter($p,$v);
369                          }                          }
# Line 363  sub fetch_result_by_id { Line 382  sub fetch_result_by_id {
382                  print STDERR "$id stored in cache\n" if ($debug == 2);                  print STDERR "$id stored in cache\n" if ($debug == 2);
383          } else {          } else {
384                  print STDERR "fetch_result_by_id($id) in cache\n" if ($debug == 2);                  print STDERR "fetch_result_by_id($id) in cache\n" if ($debug == 2);
385                    foreach my $p (qw(from to cc bcc)) {
386                            foreach my $v (@{$row->{$p}}) {
387                                    $self->add_counter($p,$v);
388                            }
389                    }
390    
391                    $self->add_counter_calendar($row->{date_utime});
392          }          }
393    
394          return $row;          return $row;

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

  ViewVC Help
Powered by ViewVC 1.1.26