4 |
|
|
5 |
use strict; |
use strict; |
6 |
use warnings; |
use warnings; |
|
use Carp; |
|
7 |
|
|
8 |
|
use lib '.'; |
9 |
|
|
10 |
|
use Carp; |
11 |
use Mail::Box::Manager; |
use Mail::Box::Manager; |
12 |
use Config::IniFiles; |
use Config::IniFiles; |
13 |
use POSIX qw(strftime); |
use POSIX qw(strftime); |
18 |
use POSIX qw(strftime); |
use POSIX qw(strftime); |
19 |
use MIME::Base64; |
use MIME::Base64; |
20 |
|
|
|
#use MWS_plucene; |
|
|
use MWS_swish; |
|
|
|
|
|
require Exporter; |
|
|
|
|
|
our @ISA = qw(Exporter); |
|
|
|
|
|
our %EXPORT_TAGS = (); |
|
|
our @EXPORT_OK; |
|
|
our @EXPORT; |
|
|
|
|
21 |
our $VERSION = '1.00'; |
our $VERSION = '1.00'; |
22 |
|
|
|
my $folder; # placeholder for folders |
|
|
|
|
23 |
my $debug = 1; |
my $debug = 1; |
24 |
|
|
25 |
|
my @counters = qw(from to cc bcc folder); |
26 |
|
|
27 |
sub new { |
sub new { |
28 |
my $class = shift; |
my $class = shift; |
29 |
my $self = {}; |
my $self = {@_}; |
30 |
bless($self, $class); |
bless($self, $class); |
31 |
|
|
|
my $config_file = shift || die "need index file"; |
|
32 |
|
|
33 |
$self->{config} = new Config::IniFiles( -file => $config_file ); |
my $config_name = $self->{config_file} || croak "need config_file"; |
34 |
|
$config_name =~ s/\.conf.*$//; |
35 |
|
$self->{config_name} = $config_name; |
36 |
|
|
37 |
$self->{config_file} = $config_file; |
$self->{config} = new Config::IniFiles( -file => $self->{config_file} ); |
|
$config_file =~ s/\.conf.*$//; |
|
|
$self->{config_name} = $config_file; |
|
38 |
|
|
39 |
my $index_dir = $self->{config}->val('global', 'index') || croak "can't find [index] section in config file with path of index"; |
my $index_dir = $self->{config}->val('global', 'index') || croak "can't find [index] section in config file with path of index"; |
40 |
|
|
81 |
my ($c,$v) = @_; |
my ($c,$v) = @_; |
82 |
my $k = $self->normalize_string($v); |
my $k = $self->normalize_string($v); |
83 |
|
|
84 |
$self->{counter}->{$c}->{$k}->{name} = $v; |
$self->{counter}->{$c}->{$k}->{name} = $v || return; |
85 |
return $self->{counter}->{$c}->{$k}->{usage}++; |
return $self->{counter}->{$c}->{$k}->{usage}++; |
86 |
} |
} |
87 |
|
|
150 |
|
|
151 |
print STDERR "about to open_folder($mbox)\n" if ($debug == 2); |
print STDERR "about to open_folder($mbox)\n" if ($debug == 2); |
152 |
|
|
153 |
$self->{folder}->{$mbox} = $self->{mgr}->open($mbox_path) || croak "can't open folder $mbox at '$mbox_path': $!"; |
my $folder; |
154 |
|
|
155 |
|
# is this maildir (no locking anyway) |
156 |
|
if (-d $mbox_path) { |
157 |
|
$folder = $self->{mgr}->open($mbox_path); |
158 |
|
} else { |
159 |
|
$folder = $self->{mgr}->open($mbox_path, lock_type=>'none' ); |
160 |
|
} |
161 |
|
|
162 |
|
$self->{folder}->{$mbox} = $folder || croak "can't open folder $mbox at '$mbox_path': $!"; |
163 |
|
|
164 |
print STDERR "open_folder($mbox) ok\n" if ($debug); |
print STDERR "open_folder($mbox) ok\n" if ($debug); |
165 |
} |
} |
365 |
|
|
366 |
$row->{'id'} = $id; |
$row->{'id'} = $id; |
367 |
|
|
368 |
foreach my $p (qw(from to cc bcc)) { |
foreach my $p (@counters) { |
369 |
foreach my $v ($self->unroll($message,$p,'phrase')) { |
foreach my $v ($self->unroll($message,$p,'phrase')) { |
370 |
push @{$row->{$p}},$v; |
push @{$row->{$p}},$v; |
371 |
$self->add_counter($p,$v); |
$self->add_counter($p,$v); |
372 |
} |
} |
373 |
} |
} |
374 |
|
|
375 |
|
$self->add_counter('folder', $1) if ($id =~ m/^(\S+)\s/); |
376 |
|
|
377 |
$row->{'subject'} = $self->decode_qp($message->subject); |
$row->{'subject'} = $self->decode_qp($message->subject); |
378 |
$row->{'body'} = $self->plain_text_body($message); |
$row->{'body'} = $self->plain_text_body($message); |
379 |
my $utime = str2time($message->date); |
my $utime = str2time($message->date); |
388 |
print STDERR "$id stored in cache\n" if ($debug == 2); |
print STDERR "$id stored in cache\n" if ($debug == 2); |
389 |
} else { |
} else { |
390 |
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); |
391 |
foreach my $p (qw(from to cc bcc)) { |
foreach my $p (@counters) { |
392 |
foreach my $v (@{$row->{$p}}) { |
foreach my $v (@{$row->{$p}}) { |
393 |
$self->add_counter($p,$v); |
$self->add_counter($p,$v); |
394 |
} |
} |
395 |
} |
} |
396 |
|
|
397 |
|
$self->add_counter('folder', $1) if ($id =~ m/^(\S+)\s/); |
398 |
|
|
399 |
$self->add_counter_calendar($row->{date_utime}); |
$self->add_counter_calendar($row->{date_utime}); |
400 |
} |
} |
401 |
|
|