--- trunk/MWS.pm 2004/05/07 23:35:39 20 +++ trunk/MWS.pm 2004/05/09 00:09:32 30 @@ -14,6 +14,7 @@ use Text::Unaccent; use Date::Parse; use POSIX qw(strftime); +use MIME::Base64; #use MWS_plucene; use MWS_swish; @@ -30,7 +31,7 @@ my $folder; # placeholder for folders -my $debug = 2; +my $debug = 1; sub new { my $class = shift; @@ -41,10 +42,14 @@ $self->{config} = new Config::IniFiles( -file => $config_file ); - my $index_file = $self->{config}->val('global', 'index') || croak "can't find [index] section in config file with path of index"; + $self->{config_file} = $config_file; + $config_file =~ s/\.conf.*$//; + $self->{config_name} = $config_file; + + my $index_dir = $self->{config}->val('global', 'index') || croak "can't find [index] section in config file with path of index"; $self->{mgr} = Mail::Box::Manager->new(access => 'r'); - $self->{index_file} = $index_file; + $self->{index_dir} = $index_dir; # placeholder for opened folders $self->{folder} = {}; @@ -65,7 +70,7 @@ $v = join('',sort split(/\s+/,$v)); $v =~ s/\W+//g; - return $v; + return lc($v); } # reset tables for search results @@ -111,7 +116,7 @@ push @out, sprintf($f, $v); } -print STDERR "fmtdate: ",join('|',@out),"\n"; + print STDERR "fmtdate: ",join('|',@out),"\n" if ($debug == 2); return (wantarray ? @out : join("-",@out)); } @@ -205,12 +210,12 @@ sub search { my $self = shift; - my $s = shift || carp "search called without argument!"; + carp "search called without argument!" if (! @_); $self->reset_counters; - print STDERR "search_index($s)\n" if ($debug == 2); - my @index_ids = $self->search_index($s); + print STDERR "search(",join(" ",@_),")\n" if ($debug == 2); + my @index_ids = $self->search_index(@_); $self->{'index_ids'} = \@index_ids; @@ -221,6 +226,8 @@ $self->{'curr_result'} = 0; + $self->reset_counters; + print STDERR "$results results\n" if ($debug == 2); return $results || 'error'; @@ -231,17 +238,28 @@ my $tmp = shift || return; - sub decode($$) { - my ($cp,$qp) = @_; - print STDERR "decode($cp,$qp) -> " if ($debug == 2); - $qp =~ s/=([a-f0-9][a-f0-9])/chr(hex($1))/ieg; - $qp =~ s/_/ /g; - print STDERR "$qp -> " if ($debug == 2); + sub decode($$$) { + my ($cp,$enc,$qp) = @_; + + print STDERR "decode($cp,$qp) -> " if ($debug == 2); + + if (uc($enc) eq "Q") { + $qp =~ s/=([a-f0-9][a-f0-9])/chr(hex($1))/ieg; + $qp =~ s/_/ /g; + } elsif (uc($enc) eq "B") { + $qp = decode_base64($qp); + } else { + croak "unsupported encoding '$enc' in decode_qp\n"; + return $qp; + } + + print STDERR "$qp\n" if ($debug == 2); + my $iconv = Text::Iconv->new($cp,'ISO-8859-2'); return $iconv->convert($qp) || ''; } - $tmp =~ s/=\?([^\?]+)\?Q\?(.+?)\?=/decode($1,$2)/ge; + $tmp =~ s/=\?([^\?]+)\?([QB])\?(.+?)\?=/decode($1,$2,$3)/ige; $tmp =~ s/^\s*["']+(.*?)["']+\s*$/$1/g; #print STDERR "$tmp\n" if ($debug == 2); return $tmp; @@ -316,11 +334,16 @@ } } + if (! $body) { + $body = "[plain/text body not found]" if ($debug == 2); + print STDERR "plain/text body not found\n" if ($debug); + return; + } + # reformat with Text::Autoformat my $wrap = $self->{wrap_margin}; if ($wrap && $body && $body =~ m/^.{$wrap}..*$/m) { - $body =~ s/[\r\n]/\n/gs; - $body = autoformat($body, {right=>$wrap}); + $body = autoformat($body, {right=>$wrap, all=>1}); $body .="\n[reformated using autoformat, margin at $wrap]" if ($debug == 2); } @@ -344,7 +367,7 @@ $row->{'id'} = $id; foreach my $p (qw(from to cc bcc)) { - foreach my $v ($self->unroll($message,'from','phrase')) { + foreach my $v ($self->unroll($message,$p,'phrase')) { push @{$row->{$p}},$v; $self->add_counter($p,$v); } @@ -363,6 +386,13 @@ print STDERR "$id stored in cache\n" if ($debug == 2); } else { print STDERR "fetch_result_by_id($id) in cache\n" if ($debug == 2); + foreach my $p (qw(from to cc bcc)) { + foreach my $v (@{$row->{$p}}) { + $self->add_counter($p,$v); + } + } + + $self->add_counter_calendar($row->{date_utime}); } return $row;