summaryrefslogtreecommitdiff
path: root/fml/lib/Mail/ThreadTrack
diff options
context:
space:
mode:
authorfukachan <fukachan>2001-11-09 11:30:30 +0000
committerfukachan <fukachan>2001-11-09 11:30:30 +0000
commitcea0308fc2d0348d7160811b634c24c8bae9b8c1 (patch)
treef3f16101f95b976a66bb7ae4cf26de1364c2f974 /fml/lib/Mail/ThreadTrack
parentd70afc7a664bdba418a3bc1fe6c3b96834d85620 (diff)
downloadfml8-cea0308fc2d0348d7160811b634c24c8bae9b8c1.tar.gz
fml8-cea0308fc2d0348d7160811b634c24c8bae9b8c1.tar.bz2
fml8-cea0308fc2d0348d7160811b634c24c8bae9b8c1.zip
clean up inheritence for further refactoring
Diffstat (limited to 'fml/lib/Mail/ThreadTrack')
-rw-r--r--fml/lib/Mail/ThreadTrack/Print.pm249
-rw-r--r--fml/lib/Mail/ThreadTrack/Print/Message.pm135
2 files changed, 218 insertions, 166 deletions
diff --git a/fml/lib/Mail/ThreadTrack/Print.pm b/fml/lib/Mail/ThreadTrack/Print.pm
index ea7ba4d0..22a580a5 100644
--- a/fml/lib/Mail/ThreadTrack/Print.pm
+++ b/fml/lib/Mail/ThreadTrack/Print.pm
@@ -4,7 +4,7 @@
# All rights reserved. This program is free software; you can
# redistribute it and/or modify it under the same terms as Perl itself.
#
-# $FML: Print.pm,v 1.9 2001/11/08 14:17:39 fukachan Exp $
+# $FML: Print.pm,v 1.10 2001/11/09 10:42:07 fukachan Exp $
#
package Mail::ThreadTrack::Print;
@@ -25,6 +25,8 @@ Mail::ThreadTrack::Print - print out thread relation
=head1 METHODS
+=head2 review()
+
=head2 C<summary(>)
top level entrance for routines to show the thread summary.
@@ -63,86 +65,61 @@ It is also larger if $status is C<open>.
=cut
-sub review
+sub _load_library
{
- my ($self, $str, $min, $max) = @_;
- my $config = $self->{ _config };
- my $spool_dir = $config->{ spool_dir };
- my $fd = $self->{ _fd } || \*STDOUT;
- my %uniq = ();
-
- # modify Print parameters
- $self->{ _article_summary_lines } = 5;
-
- $self->db_open();
- my $rh = $self->{ _hash_table };
-
- use Mail::Message::MH;
- my $ra = Mail::Message::MH->expand($str, $min, $max);
- my $first = 0;
+ my ($self) = @_;
- if (defined $config->{ reverse_order }) { @$ra = reverse @$ra;}
+ require Mail::ThreadTrack::Print::Message;
+ require Mail::ThreadTrack::Print::Sort;
+ unshift(@ISA, qw(
+ Mail::ThreadTrack::Print::Message
+ Mail::ThreadTrack::Print::Sort
+ ));
+}
- for my $id (@$ra) {
- if ($id =~ /^\d+$/) {
- my $tid = $self->_create_thread_id_strings($id);
- # check thread id $tid exists really ?
- if (defined $rh->{ _articles }->{ $tid }) {
- printf $fd "\n>Thread-Id: %-10s %s\n", $tid;
- # change treatment for the fisrt article in this thread
- $first = 1;
+sub summary
+{
+ my ($self, @opts) = @_;
- # show all articles in this thread
- ARTICLE:
- for my $aid (split(/\s+/, $rh->{ _articles }->{ $tid })) {
- # ensure uniquness
- next ARTICLE if $uniq{ $aid };
- $uniq{ $aid } = 1;
+ $self->_load_library();
+ $self->db_open();
+ $self->do_summary(@opts);
+ $self->db_close();
+}
- if ($first) {
- undef $self->{ _no_header_summary };
- $first = 0;
- }
- else {
- $self->{ _no_header_summary } = 1;
- }
- my $file = File::Spec->catfile($spool_dir, $aid);
- if (-f $file) {
- print $fd $self->__article_summary($file);
- print $fd "\n";
- }
- }
- }
- }
- }
+sub review
+{
+ my ($self, @opts) = @_;
+ $self->_load_library();
+ $self->db_open();
+ $self->do_review(@opts);
$self->db_close();
}
-sub summary
+
+sub do_summary
{
my ($self) = @_;
my ($tid, $status, $thread_id);
my $mode = $self->get_mode || 'text';
+ my $fd = $self->{ _fd } || \*STDOUT;
# rh: thread id list, which is ARRAY REFERENCE tied to db_dir/*db's
$thread_id = $self->list_up_thread_id();
- # self->{ _hash_table } is tied to DB's.
- $self->db_open();
-
if (@$thread_id) {
# sort the thread output order it out by cost
# and print the thread summary in that order.
$self->sort($thread_id);
if ($mode eq 'html') {
- print "<TABLE BORDER=4>\n" if $mode eq 'html';
+ print $fd "<TABLE BORDER=4>\n";
$self->_print_thread_summary($thread_id);
- print "</TABLE>\n" if $mode eq 'html';
+ print $fd "</TABLE>\n";
}
else {
$self->_print_thread_summary($thread_id);
@@ -151,9 +128,6 @@ sub summary
$self->_print_article_summary($thread_id);
}
}
-
- # self->{ _hash_table } is untied from DB's.
- $self->db_close();
}
@@ -245,133 +219,76 @@ sub _print_article_summary
}
# show only the first article of this thread $tid
- (@aid) = split(/\s+/, $rh->{ _articles }->{ $tid });
- $aid = $aid[0];
- $file = File::Spec->catfile($spool_dir, $aid);
- if (-f $file) {
- print $fd $self->__article_summary($file);
- }
- }
- }
-}
-
-
-sub __article_summary
-{
- my ($self, $file) = @_;
- my (@header) = ();
- my $buf = '';
- my $line = $self->{ _article_summary_lines } || 3;
- my $mode = $self->get_mode || 'text';
- my $padding = $mode eq 'text' ? ' ' : '';
-
- use FileHandle;
- my $fh = new FileHandle $file;
-
- if (defined $fh) {
- LINE:
- while (<$fh>) {
- # nuke useless lines
- next LINE if /^\>/;
- next LINE if /^\-/;
-
- # header
- if (1 ../^$/) {
- push(@header, $_);
- }
- # body part
- else {
- next LINE if /^\s*$/;
-
- # ignore mail header like patterns
- next LINE if /^X-[-A-Za-z0-9]+:/i;
- next LINE if /^Return-[-A-Za-z0-9]+:/i;
- next LINE if /^Mime-[-A-Za-z0-9]+:/i;
- next LINE if /^Content-[-A-Za-z0-9]+:/i;
- next LINE if /^(To|From|Subject|Reply-To|Received):/i;
- next LINE if /^(Message-ID|Date):/i;
-
- # pick up effetive the first $line lines
- if (_valid_buf($_)) {
- $line--;
- $buf .= $padding. $_;
+ if (defined $rh->{ _articles }->{ $tid }) {
+ (@aid) = split(/\s+/, $rh->{ _articles }->{ $tid });
+ $aid = $aid[0];
+ $file = File::Spec->catfile($spool_dir, $aid);
+ if (-f $file) {
+ print $fd $self->message_summary($file);
}
- last LINE if $line < 0;
}
}
- close($fh);
-
- if (defined $self->{ _no_header_summary }) {
- return STR2EUC( $buf );
- }
- else {
- use Mail::Header;
- my $h = new Mail::Header \@header;
- my $header_info = $self->_header_summary({
- header => $h,
- padding => $padding,
- });
- return STR2EUC( $header_info ."\n". $buf );
- }
- }
- else {
- return undef;
}
}
-sub _valid_buf
+sub do_review
{
- my ($str) = @_;
- $str = STR2EUC( $str );
-
- if ($str =~ /^[\>\#\|\*\:\;]/) {
- return 0;
- }
- elsif ($str =~ /^in /) { # quotation ?
- return 0;
- }
- elsif ($str =~ /\w+\@\w+/) { # mail address ?
- return 0;
- }
- elsif ($str =~ /^\S+\>/) { # quotation ?
- return 0;
- }
+ my ($self, $str, $min, $max) = @_;
+ my $config = $self->{ _config };
+ my $spool_dir = $config->{ spool_dir };
+ my $fd = $self->{ _fd } || \*STDOUT;
+ my $rh = $self->{ _hash_table };
+ my %uniq = ();
- return 1;
-}
+ # modify Print parameters
+ $self->{ _article_summary_lines } = 5;
+ use Mail::Message::MH;
+ my $ra = Mail::Message::MH->expand($str, $min, $max);
+ my $first = 0;
-sub _delete_subject_tag_like_string
-{
- my ($str) = @_;
- use Mail::Message::Utils;
- return Mail::Message::Utils::remove_subject_tag_like_string($str);
-}
+ if (defined $config->{ reverse_order }) { @$ra = reverse @$ra;}
+ ID_LIST:
+ for my $id (@$ra) {
+ next ID_LIST unless defined $id;
-sub _header_summary
-{
- my ($self, $args) = @_;
- my $from = $args->{ header }->get('from');
- my $subject = $args->{ header }->get('subject');
- my $padding = $args->{ padding };
+ if ($id =~ /^\d+$/) {
+ # create thread identifier string: e.g. 100 -> elena/100
+ my $tid = $self->_create_thread_id_strings($id);
- $subject = decode_mime_string($subject, { charset => 'euc-japan' });
- $subject =~ s/\n/ /g;
- $subject = _delete_subject_tag_like_string($subject);
+ # check thread id $tid exists really ?
+ if (defined $rh->{ _articles }->{ $tid }) {
+ printf $fd "\n>Thread-Id: %-10s %s\n", $tid;
- $from = decode_mime_string($from, { charset => 'euc-japan' });
- $from =~ s/\n/ /g;
+ # different treatment for the fisrt article in this thread
+ $first = 1;
- my $br = $self->get_mode eq 'html' ? '<BR>' : '';
+ # show all articles in this thread
+ ARTICLE:
+ for my $aid (split(/\s+/, $rh->{ _articles }->{ $tid })) {
+ # ensure uniquness
+ next ARTICLE if $uniq{ $aid };
+ $uniq{ $aid } = 1;
- # return buffer
- my $r = '';
- $r .= STR2EUC( $padding. " From: ". $from ."$br\n" );
- $r .= STR2EUC( $padding. "Subject: ". $subject ."$br\n" );
+ if ($first) {
+ undef $self->{ _no_header_summary };
+ $first = 0;
+ }
+ else {
+ $self->{ _no_header_summary } = 1;
+ }
- return $r;
+ my $file = File::Spec->catfile($spool_dir, $aid);
+ if (-f $file) {
+ print $fd $self->message_summary($file);
+ print $fd "\n";
+ }
+ }
+ }
+ }
+ }
}
diff --git a/fml/lib/Mail/ThreadTrack/Print/Message.pm b/fml/lib/Mail/ThreadTrack/Print/Message.pm
new file mode 100644
index 00000000..ff078c34
--- /dev/null
+++ b/fml/lib/Mail/ThreadTrack/Print/Message.pm
@@ -0,0 +1,135 @@
+#-*- perl -*-
+#
+# Copyright (C) 2001 Ken'ichi Fukamachi
+# All rights reserved. This program is free software; you can
+# redistribute it and/or modify it under the same terms as Perl itself.
+#
+# $FML: Utils.pm,v 1.1 2001/11/09 10:37:06 fukachan Exp $
+#
+
+package Mail::ThreadTrack::Print::Message;
+use strict;
+use vars qw(@ISA @EXPORT @EXPORT_OK $AUTOLOAD);
+use Carp;
+use Mail::ThreadTrack::Print::Utils qw(decode_mime_string STR2EUC);
+
+sub message_summary
+{
+ my ($self, $file) = @_;
+ my (@header) = ();
+ my $buf = '';
+ my $line = $self->{ _article_summary_lines } || 3;
+ my $mode = $self->get_mode || 'text';
+ my $padding = $mode eq 'text' ? ' ' : '';
+
+ use FileHandle;
+ my $fh = new FileHandle $file;
+
+ if (defined $fh) {
+ LINE:
+ while (<$fh>) {
+ # nuke useless lines
+ next LINE if /^\>/;
+ next LINE if /^\-/;
+
+ # header
+ if (1 ../^$/) {
+ push(@header, $_);
+ }
+ # body part
+ else {
+ next LINE if /^\s*$/;
+
+ # ignore mail header like patterns
+ next LINE if /^X-[-A-Za-z0-9]+:/i;
+ next LINE if /^Return-[-A-Za-z0-9]+:/i;
+ next LINE if /^Mime-[-A-Za-z0-9]+:/i;
+ next LINE if /^Content-[-A-Za-z0-9]+:/i;
+ next LINE if /^(To|From|Subject|Reply-To|Received):/i;
+ next LINE if /^(Message-ID|Date):/i;
+
+ # pick up effetive the first $line lines
+ if (_valid_buf($_)) {
+ $line--;
+ $buf .= $padding. $_;
+ }
+ last LINE if $line < 0;
+ }
+ }
+ close($fh);
+
+ if (defined $self->{ _no_header_summary }) {
+ return STR2EUC( $buf );
+ }
+ else {
+ use Mail::Header;
+ my $h = new Mail::Header \@header;
+ my $header_info = $self->header_summary({
+ header => $h,
+ padding => $padding,
+ });
+ return STR2EUC( $header_info ."\n". $buf );
+ }
+ }
+ else {
+ return undef;
+ }
+}
+
+
+sub _valid_buf
+{
+ my ($str) = @_;
+ $str = STR2EUC( $str );
+
+ if ($str =~ /^[\>\#\|\*\:\;]/) {
+ return 0;
+ }
+ elsif ($str =~ /^in /) { # quotation ?
+ return 0;
+ }
+ elsif ($str =~ /\w+\@\w+/) { # mail address ?
+ return 0;
+ }
+ elsif ($str =~ /^\S+\>/) { # quotation ?
+ return 0;
+ }
+
+ return 1;
+}
+
+
+sub _delete_subject_tag_like_string
+{
+ my ($str) = @_;
+ use Mail::Message::Utils;
+ return Mail::Message::Utils::remove_subject_tag_like_string($str);
+}
+
+
+sub header_summary
+{
+ my ($self, $args) = @_;
+ my $from = $args->{ header }->get('from');
+ my $subject = $args->{ header }->get('subject');
+ my $padding = $args->{ padding };
+
+ $subject = decode_mime_string($subject, { charset => 'euc-japan' });
+ $subject =~ s/\n/ /g;
+ $subject = _delete_subject_tag_like_string($subject);
+
+ $from = decode_mime_string($from, { charset => 'euc-japan' });
+ $from =~ s/\n/ /g;
+
+ my $br = $self->get_mode eq 'html' ? '<BR>' : '';
+
+ # return buffer
+ my $r = '';
+ $r .= STR2EUC( $padding. " From: ". $from ."$br\n" );
+ $r .= STR2EUC( $padding. "Subject: ". $subject ."$br\n" );
+
+ return $r;
+}
+
+
+1;