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

Diff of /trunk/MWS.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3 by dpavlin, Tue May 4 14:00:03 2004 UTC revision 4 by dpavlin, Tue May 4 15:47:14 2004 UTC
# Line 8  use Carp; Line 8  use Carp;
8    
9  use Plucene::Simple;  use Plucene::Simple;
10  use Mail::Box::Manager;  use Mail::Box::Manager;
11    use Config::IniFiles;
12    
13  require Exporter;  require Exporter;
14    
# Line 29  sub new { Line 30  sub new {
30          my $self = {};          my $self = {};
31          bless($self, $class);          bless($self, $class);
32    
33          my $index_file = shift || die "need index file";          my $config_file = shift || die "need index file";
34    
35          $self->{index} = Plucene::Simple->open($index_file) || die "can't open index '$index_file': $!";          $self->{config} = new Config::IniFiles( -file => $config_file );
36    
37            my $index_file = $self->{config}->val('global', 'index') || croak "can't find [index] section in config file with path of index";
38    
39            $self->{index} = Plucene::Simple->open($index_file) || croak "can't open index '$index_file': $!";
40    
41          $self->{mgr} = Mail::Box::Manager->new;          $self->{mgr} = Mail::Box::Manager->new;
42    
# Line 49  sub fetch_message { Line 54  sub fetch_message {
54          my ($mbox,$id) = split(/ /,$mbox_id);          my ($mbox,$id) = split(/ /,$mbox_id);
55    
56          if (! $self->{folder}->{$mbox}) {          if (! $self->{folder}->{$mbox}) {
57                  $self->{folder}->{$mbox} = $self->{mgr}->open($mbox);                  my $mbox_path = $self->{config}->val('folders', $mbox) || croak "comeone removed folder $mbox from config?";
58                    $self->{folder}->{$mbox} = $self->{mgr}->open($mbox_path) || croak "can't open folder $mbox at '$mbox_path': $!";
59                  print STDERR "## open($mbox)\n" if ($debug);                  print STDERR "## open($mbox)\n" if ($debug);
60          }          }
61    
# Line 87  sub unroll($$$) { Line 93  sub unroll($$$) {
93          }          }
94          return \@arr;          return \@arr;
95  }  }
96            
97    sub fetch_all_results {
98            my $self = shift;
99    
100            croak "results called before search!" if (! $self->{'index_ids'});
101    
102            my @arr;
103    
104            foreach my $id (@{$self->{'index_ids'}}) {
105                    push @arr, $self->fetch_result_by_id($id);
106            }
107    
108            return @arr;
109    }
110    
111  sub fetch_result {  sub fetch_result {
112          my $self = shift;          my $self = shift;
113    
# Line 99  sub fetch_result { Line 119  sub fetch_result {
119    
120          my $id = $self->{'index_ids'}->[$curr];          my $id = $self->{'index_ids'}->[$curr];
121    
122          return if (! $id);          return $self->fetch_result_by_id($id);
123    }
124    
125    sub fetch_result_by_id {
126            my $self = shift;
127    
128            my $id = shift || return;
129    
130          my $message = $self->fetch_message($id);          my $message = $self->fetch_message($id);
131    

Legend:
Removed from v.3  
changed lines
  Added in v.4

  ViewVC Help
Powered by ViewVC 1.1.26