1 |
#!/usr/bin/perl -w |
#!/usr/bin/perl -w |
2 |
|
|
3 |
use Mail::Box::Manager; |
use MWS; |
|
use Plucene::Simple; |
|
4 |
use Data::Dumper; |
use Data::Dumper; |
5 |
|
|
6 |
my $mbox="test"; |
my $mws = MWS->new('global.conf'); |
|
my $index = Plucene::Simple->open( "index" ) || die "can't open index: $!"; |
|
7 |
|
|
8 |
my $mgr = Mail::Box::Manager->new; |
my $debug = 1; |
|
my $folder = $mgr->open($mbox, extract => 'LAZY'); |
|
|
foreach my $message ($folder->messages) { |
|
|
|
|
|
my $id = $message->messageId; |
|
|
print "## $id\n"; |
|
|
|
|
|
my $document = { |
|
|
id => $id, |
|
|
folder => $mbox, |
|
|
}; |
|
9 |
|
|
10 |
|
foreach my $mbox ($mws->{config}->Parameters('folders')) { |
11 |
|
my $mbox_path = $mws->{config}->val('folders', $mbox); |
12 |
|
|
13 |
|
print STDERR "working on $mbox [$mbox_path]\n" if ($debug); |
14 |
|
|
15 |
foreach my $direction (qw(to from cc bcc)) { |
my $folder = $mws->{mgr}->open($mbox_path, extract => 'LAZY'); |
16 |
foreach my $f ($message->$direction) { |
foreach my $message ($folder->messages) { |
17 |
print "$direction: "; |
|
18 |
foreach my $part (qw(phrase address comment)) { |
my $id = $message->messageId; |
19 |
next if (! $f->$part); |
print "## $id\n"; |
20 |
print "[$part]",$f->$part," "; |
|
21 |
$document->{$direction.'_'.$part} .= $f->$part."\n"; |
my $document = { |
22 |
|
id => $id, |
23 |
|
folder => $mbox, |
24 |
|
}; |
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
foreach my $direction (qw(to from cc bcc)) { |
29 |
|
foreach my $f ($message->$direction) { |
30 |
|
print "$direction: "; |
31 |
|
foreach my $part (qw(phrase address comment)) { |
32 |
|
next if (! $f->$part); |
33 |
|
print "[$part]",$f->$part," "; |
34 |
|
$document->{$direction.'_'.$part} .= $f->$part."\n"; |
35 |
|
} |
36 |
|
print "\n"; |
37 |
|
# push @{$document->$d.'_phrase'}, $f->phrase, |
38 |
|
# push @{$document->$d.'_address'}, $f->address, |
39 |
|
## push @{$document->$d.'_comment'}, $f->comment, |
40 |
} |
} |
|
print "\n"; |
|
|
# push @{$document->$d.'_phrase'}, $f->phrase, |
|
|
# push @{$document->$d.'_address'}, $f->address, |
|
|
## push @{$document->$d.'_comment'}, $f->comment, |
|
41 |
} |
} |
|
} |
|
42 |
|
|
43 |
$document->{'subject'} = $message->get('Subject') || 'no subject'; |
$document->{'subject'} = $message->get('Subject') || 'no subject'; |
44 |
|
|
45 |
print Dumper($document); |
# print Dumper($document); |
46 |
$index->add("$mbox $id" => $document); |
$mws->{index}->add("$mbox $id" => $document); |
47 |
|
|
48 |
|
} |
49 |
|
|
50 |
|
$folder->close; |
51 |
} |
} |
52 |
|
|
53 |
$folder->close; |
$mws->{index}->optimize; |
|
$index->optimize; |
|