/[mws]/trunk/mbox2index.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /trunk/mbox2index.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 27 - (hide annotations)
Sat May 8 20:34:26 2004 UTC (20 years ago) by dpavlin
File MIME type: text/plain
File size: 1888 byte(s)
this is 0.9-rc1:
- scripts now accept configuration file as parametar, if none is specified,
  they will use global.conf in current directory
- more css design
- how to install using PAR
- mbox2index can now call swish-e by itself, swish-e configuration
  moved to MWS_swish.pm
- httpd server now shows 30 newest messages in this year when accessed
  through root URL

1 dpavlin 12 #!/usr/bin/perl -w
2    
3     use MWS;
4     use Data::Dumper;
5 dpavlin 13 use Date::Parse;
6     use POSIX qw(strftime);
7 dpavlin 27 use Getopt::Long;
8 dpavlin 12
9 dpavlin 27 # are we called from this script?
10     my $recursive = 0;
11 dpavlin 12
12 dpavlin 27 my $r = GetOptions("recursive" => \$recursive);
13    
14     my $config_file = shift @ARGV || 'global.conf';
15    
16     if (! -f $config_file) {
17     print qq{Usage: $0 [/path/to/local.conf]
18    
19     If local.conf is not specified, global.conf in current directory will
20     be used.
21     };
22     exit 1;
23     }
24    
25     my $mws = MWS->new($config_file);
26    
27     $mws->create_index if (! $recursive);
28    
29     print STDERR "starting indexing...";
30    
31 dpavlin 12 my $debug = 1;
32    
33     foreach my $mbox ($mws->{config}->Parameters('folders')) {
34     my $mbox_path = $mws->{config}->val('folders', $mbox);
35    
36     print STDERR "working on $mbox [$mbox_path]\n" if ($debug);
37    
38     my $folder = $mws->open_folder($mbox);
39    
40 dpavlin 14 print STDERR $folder->size," bytes\n" if ($debug);
41    
42 dpavlin 12 foreach my $message ($folder->messages) {
43    
44     my $id = $message->messageId;
45    
46     my $document = {
47     id => $id,
48     folder => $mbox,
49     };
50    
51     foreach my $direction (qw(to from cc bcc)) {
52 dpavlin 13 foreach my $part (qw(phrase address comment)) {
53 dpavlin 14 $document->{$direction.'_'.$part} = join("##", $mws->unroll($message,$direction,$part));
54 dpavlin 12 }
55     }
56    
57 dpavlin 17 $document->{'subject'} = $mws->decode_qp($message->subject) || 'no subject';
58 dpavlin 12
59 dpavlin 14 $document->{'body'} = $mws->plain_text_body($message);
60 dpavlin 13
61     my $utime = str2time($message->date);
62    
63     $document->{'date_utime'} = $utime;
64     $document->{'date'} = strftime("%Y-%m-%d %H:%M:%S", localtime($utime));
65    
66 dpavlin 12 # print Dumper($document);
67 dpavlin 14 $mws->add_index("$mbox $id" => $document);
68 dpavlin 12
69 dpavlin 14 # clear internal MWS cache to keep memory usage down
70     # (this should be replaced by garbage collector in MWS,
71     # but without it this is the best solution to keep machine
72     # alive while indexing)
73     $mws->{cache} = {};
74 dpavlin 12
75 dpavlin 15 # this is not complete solution. see mailbox-destruct.diff
76     $message->destruct();
77 dpavlin 12
78     }
79    
80 dpavlin 14 $mws->close_folder($mbox);
81 dpavlin 15
82 dpavlin 12 }
83    
84     $mws->close_index;

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26