/[mws]/trunk/lib/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/lib/MWS.pm

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

trunk/MWS.pm revision 41 by dpavlin, Mon May 10 20:26:17 2004 UTC trunk/lib/MWS.pm revision 53 by dpavlin, Fri Jun 18 14:56:40 2004 UTC
# Line 20  use MIME::Base64; Line 20  use MIME::Base64;
20    
21  our $VERSION = '1.00';  our $VERSION = '1.00';
22    
 my $folder;     # placeholder for folders  
   
23  my $debug = 1;  my $debug = 1;
24    
25    my @counters = qw(from to cc bcc folder);
26    
27  sub new {  sub new {
28          my $class = shift;          my $class = shift;
29          my $self = {@_};          my $self = {@_};
# Line 81  sub add_counter($$) { Line 81  sub add_counter($$) {
81          my ($c,$v) = @_;          my ($c,$v) = @_;
82          my $k = $self->normalize_string($v);          my $k = $self->normalize_string($v);
83    
84          $self->{counter}->{$c}->{$k}->{name} = $v;          $self->{counter}->{$c}->{$k}->{name} = $v || return;
85          return $self->{counter}->{$c}->{$k}->{usage}++;          return $self->{counter}->{$c}->{$k}->{usage}++;
86  }  }
87    
# Line 114  sub fmtdate { Line 114  sub fmtdate {
114  sub add_counter_calendar($) {  sub add_counter_calendar($) {
115          my $self = shift;          my $self = shift;
116    
117          my $t = shift || croak "add_counter_calendar without argument!";          my $t = shift || return;
118                    
119          my ($yyyy,$mm,$dd) = $self->fmtdate($self->yyyymmdd($t));          my ($yyyy,$mm,$dd) = $self->fmtdate($self->yyyymmdd($t));
120    
# Line 150  sub open_folder { Line 150  sub open_folder {
150    
151                  print STDERR "about to open_folder($mbox)\n" if ($debug == 2);                  print STDERR "about to open_folder($mbox)\n" if ($debug == 2);
152    
153                  $self->{folder}->{$mbox} = $self->{mgr}->open($mbox_path) || croak "can't open folder $mbox at '$mbox_path': $!";                  my $folder;
154    
155                    # is this maildir (no locking anyway)
156                    if (-d $mbox_path) {
157                            $folder = $self->{mgr}->open($mbox_path);
158                    } else {
159                            $folder = $self->{mgr}->open($mbox_path, lock_type=>'none' );
160                    }
161    
162                    $self->{folder}->{$mbox} = $folder || croak "can't open folder $mbox at '$mbox_path': $!";
163    
164                  print STDERR "open_folder($mbox) ok\n" if ($debug);                  print STDERR "open_folder($mbox) ok\n" if ($debug);
165          }          }
# Line 245  sub decode_qp($) { Line 254  sub decode_qp($) {
254    
255                  print STDERR "$qp\n" if ($debug == 2);                  print STDERR "$qp\n" if ($debug == 2);
256    
257                  my $iconv = Text::Iconv->new($cp,'ISO-8859-2');                  my $iconv;
258                  return $iconv->convert($qp) || '';                  eval '$iconv = Text::Iconv->new($cp,"ISO-8859-2")';
259                    if ($iconv) {
260                            return $iconv->convert($qp) || '';
261                    } else {
262                            return $qp;
263                    }
264          }          }
265    
266          $tmp =~ s/=\?([^\?]+)\?([QB])\?(.+?)\?=/decode($1,$2,$3)/ige;          $tmp =~ s/=\?([^\?]+)\?([QB])\?(.+?)\?=/decode($1,$2,$3)/ige;
# Line 333  sub plain_text_body { Line 347  sub plain_text_body {
347          # reformat with Text::Autoformat          # reformat with Text::Autoformat
348          my $wrap = $self->{wrap_margin};          my $wrap = $self->{wrap_margin};
349          if ($wrap && $body && $body =~ m/^.{$wrap}..*$/m) {          if ($wrap && $body && $body =~ m/^.{$wrap}..*$/m) {
350                  $body = autoformat($body, {right=>$wrap, all=>1});                  eval '$body = autoformat($body, {right=>$wrap, all=>1});';
351                  $body .="\n[reformated using autoformat, margin at $wrap]" if ($debug == 2);                  $body .="\n[reformated using autoformat, margin at $wrap]" if ($debug == 2);
352          }          }
353    
# Line 356  sub fetch_result_by_id { Line 370  sub fetch_result_by_id {
370    
371                  $row->{'id'} = $id;                  $row->{'id'} = $id;
372    
373                  foreach my $p (qw(from to cc bcc)) {                  foreach my $p (@counters) {
374                          foreach my $v ($self->unroll($message,$p,'phrase')) {                          foreach my $v ($self->unroll($message,$p,'phrase')) {
375                                  push @{$row->{$p}},$v;                                  push @{$row->{$p}},$v;
376                                  $self->add_counter($p,$v);                                  $self->add_counter($p,$v);
377                          }                          }
378                  }                  }
379    
380                    $self->add_counter('folder', $1) if ($id =~ m/^(\S+)\s/);
381    
382                  $row->{'subject'} = $self->decode_qp($message->subject);                  $row->{'subject'} = $self->decode_qp($message->subject);
383                  $row->{'body'} = $self->plain_text_body($message);                  $row->{'body'} = $self->plain_text_body($message);
384                  my $utime = str2time($message->date);                  my $utime = $message->timestamp;
385    
386                  $row->{'date_utime'} = $utime;                  $row->{'date_utime'} = $utime;
387    
# Line 376  sub fetch_result_by_id { Line 393  sub fetch_result_by_id {
393                  print STDERR "$id stored in cache\n" if ($debug == 2);                  print STDERR "$id stored in cache\n" if ($debug == 2);
394          } else {          } else {
395                  print STDERR "fetch_result_by_id($id) in cache\n" if ($debug == 2);                  print STDERR "fetch_result_by_id($id) in cache\n" if ($debug == 2);
396                  foreach my $p (qw(from to cc bcc)) {                  foreach my $p (@counters) {
397                          foreach my $v (@{$row->{$p}}) {                          foreach my $v (@{$row->{$p}}) {
398                                  $self->add_counter($p,$v);                                  $self->add_counter($p,$v);
399                          }                          }
400                  }                  }
401    
402                    $self->add_counter('folder', $1) if ($id =~ m/^(\S+)\s/);
403    
404                  $self->add_counter_calendar($row->{date_utime});                  $self->add_counter_calendar($row->{date_utime});
405          }          }
406    

Legend:
Removed from v.41  
changed lines
  Added in v.53

  ViewVC Help
Powered by ViewVC 1.1.26