/[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

Diff of /trunk/mbox2index.pl

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

revision 12 by dpavlin, Thu May 6 12:40:11 2004 UTC revision 14 by dpavlin, Thu May 6 19:46:58 2004 UTC
# Line 2  Line 2 
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    
# Line 18  foreach my $mbox ($mws->{config}->Parame Line 16  foreach my $mbox ($mws->{config}->Parame
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,
# Line 29  foreach my $mbox ($mws->{config}->Parame Line 28  foreach my $mbox ($mws->{config}->Parame
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);
47                          $xml .= "<$tag><![CDATA[".$document->{$tag}."]]></$tag>\n";  
48                  }                  # clear internal MWS cache to keep memory usage down
49                  $xml .= qq{</message>};                  # (this should be replaced by garbage collector in MWS,
50                    # but without it this is the best solution to keep machine
51                    # alive while indexing)
52                    $mws->{cache} = {};
53    
54                  $xml = $iso2utf->convert($xml);                  undef $message;
                 use bytes;      # as opposed to chars  
                 print "Path-Name: $mbox $id\n";  
                 print "Content-Length: ".(length($xml)+1)."\n";  
                 print "Document-Type: XML\n\n$xml\n";  
55    
56          }          }
57    
58          $folder->close;          $mws->close_folder($mbox);
59            #$folder->close;
60  }  }
61    
62  $mws->close_index;  $mws->close_index;

Legend:
Removed from v.12  
changed lines
  Added in v.14

  ViewVC Help
Powered by ViewVC 1.1.26