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