/[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 19 by dpavlin, Fri May 7 20:52:34 2004 UTC revision 20 by dpavlin, Fri May 7 23:35:39 2004 UTC
# Line 12  use POSIX qw(strftime); Line 12  use POSIX qw(strftime);
12  use Text::Autoformat;  use Text::Autoformat;
13  use Text::Iconv;  use Text::Iconv;
14  use Text::Unaccent;  use Text::Unaccent;
15    use Date::Parse;
16    use POSIX qw(strftime);
17    
18  #use MWS_plucene;  #use MWS_plucene;
19  use MWS_swish;  use MWS_swish;
# Line 88  sub add_counter($$) { Line 90  sub add_counter($$) {
90          return $self->{counter}->{$c}->{$k}->{usage}++;          return $self->{counter}->{$c}->{$k}->{usage}++;
91  }  }
92    
93    sub yyyymmdd {
94            my $self = shift;
95    
96            my $t = shift || time;
97    
98            my (undef,undef,undef,$dd,$mm,$yyyy) = localtime($t);
99            $mm++;
100            $yyyy+=1900;
101            return ($yyyy,$mm,$dd);
102    }
103    
104    sub fmtdate {
105            my $self = shift;
106    
107            my @out;
108            my @formats = qw(%04d %02d %02d);
109            while (my $v = shift) {
110                    my $f = shift @formats;
111                    push @out, sprintf($f, $v);
112            }
113    
114    print STDERR "fmtdate: ",join('|',@out),"\n";
115    
116            return (wantarray ? @out : join("-",@out));
117    }
118    
119    sub add_counter_calendar($) {
120            my $self = shift;
121    
122            my $t = shift || croak "add_counter_calendar without argument!";
123            
124            my ($yyyy,$mm,$dd) = $self->fmtdate($self->yyyymmdd($t));
125    
126            return $self->{counter}->{calendar}->{"$yyyy-$mm"}->{$dd}++;
127    }
128    
129    
130  sub counter {  sub counter {
131          my $self = shift;          my $self = shift;
132    
# Line 194  sub decode_qp($) { Line 233  sub decode_qp($) {
233    
234          sub decode($$) {          sub decode($$) {
235                  my ($cp,$qp) = @_;                  my ($cp,$qp) = @_;
                 my $iconv = Text::Iconv->new($cp,'ISO-8859-2');  
236          print STDERR "decode($cp,$qp) -> " if ($debug == 2);          print STDERR "decode($cp,$qp) -> " if ($debug == 2);
237                  $qp =~ s/=([a-f0-9][a-f0-9])/chr(hex($1))/ieg;                  $qp =~ s/=([a-f0-9][a-f0-9])/chr(hex($1))/ieg;
238                  $qp =~ s/_/ /g;                  $qp =~ s/_/ /g;
239          print STDERR "$qp\n" if ($debug == 2);          print STDERR "$qp -> " if ($debug == 2);
240                  return $iconv->convert($qp) || $qp;                  my $iconv = Text::Iconv->new($cp,'ISO-8859-2');
241                    return $iconv->convert($qp) || '';
242          }          }
243    
244          $tmp =~ s/=\?([^\?]+)\?Q\?(.+?)\?=/decode($1,$2)/ex;          $tmp =~ s/=\?([^\?]+)\?Q\?(.+?)\?=/decode($1,$2)/ge;
245          $tmp =~ s/^\s*["']+(.*?)["']+\s*$/$1/g;          $tmp =~ s/^\s*["']+(.*?)["']+\s*$/$1/g;
246            #print STDERR "$tmp\n" if ($debug == 2);
247          return $tmp;          return $tmp;
248  }  }
249    
# Line 311  sub fetch_result_by_id { Line 351  sub fetch_result_by_id {
351                  }                  }
352                  $row->{'subject'} = $self->decode_qp($message->subject);                  $row->{'subject'} = $self->decode_qp($message->subject);
353                  $row->{'body'} = $self->plain_text_body($message);                  $row->{'body'} = $self->plain_text_body($message);
354                  $row->{'date'} = $message->date;                  my $utime = str2time($message->date);
355    
356                    $row->{'date_utime'} = $utime;
357    
358                    $row->{'date'} = strftime("%Y-%m-%d %H:%M:%S", localtime($utime));
359                    $self->add_counter_calendar($utime);
360    
361                  # XXX store in cache?                  # XXX store in cache?
362                  $self->{cache}->{$id} = $row;                  $self->{cache}->{$id} = $row;

Legend:
Removed from v.19  
changed lines
  Added in v.20

  ViewVC Help
Powered by ViewVC 1.1.26