/[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 16 by dpavlin, Thu May 6 23:06:08 2004 UTC revision 19 by dpavlin, Fri May 7 20:52:34 2004 UTC
# Line 11  use Config::IniFiles; Line 11  use Config::IniFiles;
11  use POSIX qw(strftime);  use POSIX qw(strftime);
12  use Text::Autoformat;  use Text::Autoformat;
13  use Text::Iconv;  use Text::Iconv;
14    use Text::Unaccent;
15    
16  #use MWS_plucene;  #use MWS_plucene;
17  use MWS_swish;  use MWS_swish;
# Line 47  sub new { Line 48  sub new {
48          $self->{folder} = {};          $self->{folder} = {};
49    
50          $self->{wrap_margin} = $self->{config}->val('global', 'wrap_margin');          $self->{wrap_margin} = $self->{config}->val('global', 'wrap_margin');
51            $self->{max_results} = $self->{config}->val('global', 'max_results') || 100;
52            $self->reset_counters;
53    
54          return $self;          return $self;
55  }  }
56    
57    sub normalize_string {
58            my $self = shift;
59    
60            my $v = shift || return;
61    
62            $v = unac_string('ISO-8859-2', $v);
63            $v = join('',sort split(/\s+/,$v));
64            $v =~ s/\W+//g;
65    
66            return $v;
67    }
68    
69    # reset tables for search results
70    sub reset_counters {
71            my $self = shift;
72    
73            $self->{counter} = {};
74    
75    #       foreach my $c (qw(thread from to cc bcc lists links att)) {
76    #               $self->{counter}->{$c} = {};
77    #       }
78    
79    }
80    
81    sub add_counter($$) {
82            my $self = shift;
83    
84            my ($c,$v) = @_;
85            my $k = $self->normalize_string($v);
86    
87            $self->{counter}->{$c}->{$k}->{name} = $v;
88            return $self->{counter}->{$c}->{$k}->{usage}++;
89    }
90    
91    sub counter {
92            my $self = shift;
93    
94            my $c = shift || return;
95    
96            return if (! $self->{counter}->{$c});
97    
98            return $self->{counter}->{$c};
99    }
100    
101  sub mbox_name2path {  sub mbox_name2path {
102          my $self = shift;          my $self = shift;
103    
# Line 106  sub fetch_message { Line 153  sub fetch_message {
153                  print STDERR "close_folder($mbox) forced on ",$self->{fetch_count},"iteration\n";                  print STDERR "close_folder($mbox) forced on ",$self->{fetch_count},"iteration\n";
154          }          }
155                    
156          return $self->open_folder($mbox)->find($id) ||          my $msg = $self->open_folder($mbox)->find($id);
157            if ($msg) {
158                    return $msg;
159            } else {
160                  print STDERR "can't find message $id in $mbox. Time to re-index?\n";                  print STDERR "can't find message $id in $mbox. Time to re-index?\n";
161                    return;
162            }
163  }  }
164    
165    
# Line 116  sub search { Line 168  sub search {
168    
169          my $s = shift || carp "search called without argument!";          my $s = shift || carp "search called without argument!";
170    
171            $self->reset_counters;
172    
173          print STDERR "search_index($s)\n" if ($debug == 2);          print STDERR "search_index($s)\n" if ($debug == 2);
174          my @index_ids = $self->search_index($s);          my @index_ids = $self->search_index($s);
175    
176          $self->{'index_ids'} = \@index_ids;          $self->{'index_ids'} = \@index_ids;
177    
178          my $results = $#index_ids + 1;          #my $results = $#index_ids + 1;
179          $self->{'results'} = $results;          #$self->{'results'} = $results;
180            
181            my $results = $self->{'total_hits'} || ($#index_ids + 1);
182    
183          $self->{'curr_result'} = 0;          $self->{'curr_result'} = 0;
184    
# Line 143  sub decode_qp($) { Line 199  sub decode_qp($) {
199                  $qp =~ s/=([a-f0-9][a-f0-9])/chr(hex($1))/ieg;                  $qp =~ s/=([a-f0-9][a-f0-9])/chr(hex($1))/ieg;
200                  $qp =~ s/_/ /g;                  $qp =~ s/_/ /g;
201          print STDERR "$qp\n" if ($debug == 2);          print STDERR "$qp\n" if ($debug == 2);
202                  return $iconv->convert($qp);                  return $iconv->convert($qp) || $qp;
203          }          }
204    
205          $tmp =~ s/=\?([^\?]+)\?Q\?(.+)\?=/decode($1,$2)/ex;          $tmp =~ s/=\?([^\?]+)\?Q\?(.+?)\?=/decode($1,$2)/ex;
206            $tmp =~ s/^\s*["']+(.*?)["']+\s*$/$1/g;
207          return $tmp;          return $tmp;
208  }  }
209    
# Line 157  sub unroll($$$) { Line 214  sub unroll($$$) {
214    
215          my @arr;          my @arr;
216    
217            return if (! $message->$part);
218    
219          foreach my $from ($message->$part) {          foreach my $from ($message->$part) {
220                  my $tmp = $from->$sub || next;                  my $tmp = $from->$sub || next;
221    
222                  $tmp = $self->decode_qp($tmp);                  $tmp = $self->decode_qp($tmp);
                 $tmp =~ s/^\s*["'](.*)["']\s*$/$1/;  
223                  push @arr, $tmp;                  push @arr, $tmp;
224          }          }
225    
# Line 181  sub fetch_all_results { Line 239  sub fetch_all_results {
239                  push @arr, $self->fetch_result_by_id($id);                  push @arr, $self->fetch_result_by_id($id);
240          }          }
241    
242    
243          return @arr;          return @arr;
244  }  }
245    
# Line 240  sub fetch_result_by_id { Line 299  sub fetch_result_by_id {
299    
300                  print STDERR "fetch_result_by_id($id) not in cache, hitting disk\n" if ($debug == 2);                  print STDERR "fetch_result_by_id($id) not in cache, hitting disk\n" if ($debug == 2);
301    
302                  my $message = $self->fetch_message($id) || print STDERR "can't fetch message '$id'";                  my $message = $self->fetch_message($id) || return;
303    
304                  $row->{'id'} = $id;                  $row->{'id'} = $id;
305                  @{$row->{'from'}} = $self->unroll($message,'from','phrase');  
306                  @{$row->{'to'}} = $self->unroll($message,'to','phrase');                  foreach my $p (qw(from to cc bcc)) {
307                  @{$row->{'cc'}} = $self->unroll($message,'cc','phrase');                          foreach my $v ($self->unroll($message,'from','phrase')) {
308                                    push @{$row->{$p}},$v;
309                                    $self->add_counter($p,$v);
310                            }
311                    }
312                  $row->{'subject'} = $self->decode_qp($message->subject);                  $row->{'subject'} = $self->decode_qp($message->subject);
313                  $row->{'body'} = $self->plain_text_body($message);                  $row->{'body'} = $self->plain_text_body($message);
314                  $row->{'date'} = $message->date;                  $row->{'date'} = $message->date;

Legend:
Removed from v.16  
changed lines
  Added in v.19

  ViewVC Help
Powered by ViewVC 1.1.26