/[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 2 by dpavlin, Mon May 3 21:28:46 2004 UTC revision 4 by dpavlin, Tue May 4 15:47:14 2004 UTC
# Line 6  use strict; Line 6  use strict;
6  use warnings;  use warnings;
7  use Carp;  use Carp;
8    
9    use Plucene::Simple;
10    use Mail::Box::Manager;
11    use Config::IniFiles;
12    
13  require Exporter;  require Exporter;
14    
15  our @ISA = qw(Exporter);  our @ISA = qw(Exporter);
# Line 26  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->{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) || die "can't open index '$index_file': $!";          $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 46  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 84  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    
114            my $args = {@_};
115    
116          croak "results called before search!" if (! $self->{'index_ids'});          croak "results called before search!" if (! $self->{'index_ids'});
117    
118          my $curr = $self->{'curr_result'}++;          my $curr = $self->{'curr_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    
# Line 102  sub fetch_result { Line 133  sub fetch_result {
133    
134          $row->{'from'} = unroll($message,'from','phrase');          $row->{'from'} = unroll($message,'from','phrase');
135          $row->{'subject'} = $message->get('Subject');          $row->{'subject'} = $message->get('Subject');
136            if (! $message->isMultipart) {
137                    $row->{'body'} = $message->decoded->string;
138            } else {
139                    foreach my $part ($message->parts) {
140                            if ($part->body->mimeType eq 'text/plain') {
141                                    $row->{'body'} = $part->decoded->string;
142                                    last;
143                            }
144                    }
145            }
146    
147          return $row;          return $row;
148                    

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

  ViewVC Help
Powered by ViewVC 1.1.26