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; |
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; |
$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 |
|
|
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 |
|
|
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 |
|
|
302 |
my $message = $self->fetch_message($id) || return; |
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; |