2 |
|
|
3 |
use MWS; |
use MWS; |
4 |
use Data::Dumper; |
use Data::Dumper; |
5 |
use XML::Simple; |
use Date::Parse; |
6 |
use Text::Iconv; |
use POSIX qw(strftime); |
|
|
|
|
my $iso2utf = Text::Iconv->new('ISO-8859-2','UTF-8'); |
|
7 |
|
|
8 |
my $mws = MWS->new('global.conf'); |
my $mws = MWS->new('global.conf'); |
9 |
|
|
16 |
|
|
17 |
my $folder = $mws->open_folder($mbox); |
my $folder = $mws->open_folder($mbox); |
18 |
|
|
19 |
|
print STDERR $folder->size," bytes\n" if ($debug); |
20 |
|
|
21 |
foreach my $message ($folder->messages) { |
foreach my $message ($folder->messages) { |
22 |
|
|
23 |
my $id = $message->messageId; |
my $id = $message->messageId; |
|
print STDERR "## $id\n"; |
|
24 |
|
|
25 |
my $document = { |
my $document = { |
26 |
id => $id, |
id => $id, |
28 |
}; |
}; |
29 |
|
|
30 |
foreach my $direction (qw(to from cc bcc)) { |
foreach my $direction (qw(to from cc bcc)) { |
31 |
foreach my $f ($message->$direction) { |
foreach my $part (qw(phrase address comment)) { |
32 |
# print STDERR "$direction: "; |
$document->{$direction.'_'.$part} = join("##", $mws->unroll($message,$direction,$part)); |
|
foreach my $part (qw(phrase address comment)) { |
|
|
next if (! $f->$part); |
|
|
# print STDERR "[$part]",$f->$part," "; |
|
|
$document->{$direction.'_'.$part} .= $f->$part."\n"; |
|
|
} |
|
|
# print STDERR "\n"; |
|
|
# push @{$document->$d.'_phrase'}, $f->phrase, |
|
|
# push @{$document->$d.'_address'}, $f->address, |
|
|
## push @{$document->$d.'_comment'}, $f->comment, |
|
33 |
} |
} |
34 |
} |
} |
35 |
|
|
36 |
$document->{'subject'} = $message->get('Subject') || 'no subject'; |
$document->{'subject'} = $message->get('Subject') || 'no subject'; |
37 |
|
|
38 |
$document->{'body'} = $mws->plain_text_body($message); |
$document->{'body'} = $mws->plain_text_body($message); |
39 |
|
|
40 |
# print Dumper($document); |
my $utime = str2time($message->date); |
|
# $mws->add_index("$mbox $id" => $document); |
|
41 |
|
|
42 |
# my $xml = XMLout($document); |
$document->{'date_utime'} = $utime; |
43 |
|
$document->{'date'} = strftime("%Y-%m-%d %H:%M:%S", localtime($utime)); |
44 |
|
|
45 |
my $xml = qq{<message>}; |
# print Dumper($document); |
46 |
foreach my $tag (keys %$document) { |
$mws->add_index("$mbox $id" => $document); |
|
$xml .= "<$tag><![CDATA[".$document->{$tag}."]]></$tag>\n"; |
|
|
} |
|
|
$xml .= qq{</message>}; |
|
47 |
|
|
48 |
$xml = $iso2utf->convert($xml); |
# clear internal MWS cache to keep memory usage down |
49 |
use bytes; # as opposed to chars |
# (this should be replaced by garbage collector in MWS, |
50 |
print "Path-Name: $mbox $id\n"; |
# but without it this is the best solution to keep machine |
51 |
print "Content-Length: ".(length($xml)+1)."\n"; |
# alive while indexing) |
52 |
print "Document-Type: XML\n\n$xml\n"; |
$mws->{cache} = {}; |
53 |
|
|
54 |
|
# this is not complete solution. see mailbox-destruct.diff |
55 |
|
$message->destruct(); |
56 |
|
|
57 |
} |
} |
58 |
|
|
59 |
$folder->close; |
$mws->close_folder($mbox); |
60 |
|
|
61 |
} |
} |
62 |
|
|
63 |
$mws->close_index; |
$mws->close_index; |