summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfukachan <fukachan>2001-11-11 00:57:35 +0000
committerfukachan <fukachan>2001-11-11 00:57:35 +0000
commit6349632193b322c6590ab7f3740fa2115471eb73 (patch)
treebe435fd503d5b9aa1f912574ded3b6f41357df22
parent4fad7f6f004c0f1b65c58a979c6fcd2f1d0a50c6 (diff)
downloadfml8-6349632193b322c6590ab7f3740fa2115471eb73.tar.gz
fml8-6349632193b322c6590ab7f3740fa2115471eb73.tar.bz2
fml8-6349632193b322c6590ab7f3740fa2115471eb73.zip
dynamic binding accoding to mode: text or html
-rw-r--r--fml/lib/Mail/ThreadTrack/Print.pm250
-rw-r--r--fml/lib/Mail/ThreadTrack/Print/HTML.pm92
-rw-r--r--fml/lib/Mail/ThreadTrack/Print/Text.pm147
3 files changed, 322 insertions, 167 deletions
diff --git a/fml/lib/Mail/ThreadTrack/Print.pm b/fml/lib/Mail/ThreadTrack/Print.pm
index 66d7fe95..4b453194 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.13 2001/11/09 15:09:03 fukachan Exp $
+# $FML: Print.pm,v 1.14 2001/11/10 09:04:27 fukachan Exp $
#
package Mail::ThreadTrack::Print;
@@ -13,8 +13,6 @@ use vars qw(@ISA @EXPORT @EXPORT_OK $AUTOLOAD);
use Carp;
use Mail::ThreadTrack::Print::Utils qw(decode_mime_string STR2EUC);
-my $is_show_cost_indicate = 0;
-
=head1 NAME
Mail::ThreadTrack::Print - print out thread relation
@@ -25,26 +23,14 @@ Mail::ThreadTrack::Print - print out thread relation
=head1 METHODS
-=head2 review()
-
-=head2 C<summary(>)
-
-top level entrance for routines to show the thread summary.
-
-See L<simple_print()> for more detail.
-Either of
-C<simple_print()>
-or
-C<_summary_print()>
-is used for purposes.
+=head2 summary()
+show the thread summary.
Each row that C<show_summary()> returns has a set of
C<date>, C<age>, C<status>, C<thread-id> and
C<articles>, which is a list of articles with the thread-id.
-=head2 C<simple_print()>
-
-show entries by the thread_id order. For example,
+summary show entries by the thread_id order. For example,
date age status thread id articles
------------------------------------------------------------
@@ -55,16 +41,17 @@ show entries by the thread_id order. For example,
2001/02/07 3.0 going elena_#00000454 814 815
2001/02/10 0.1 open elena_#00000456 821
-=head2 C<_summary_print()>
+=head2 review()
-show entries in the C<cost> larger order.
-The cost is evaluated by $status and $age.
-The cost is larger as $age is larger.
-It is also larger if $status is C<open>.
+show a chain of article summary in each thread.
=cut
+# Descriptions: top level entrance for "show" mode
+# Arguments: $self varargs ...
+# Side Effects: none
+# Return Value: none
sub summary
{
my ($self, @opts) = @_;
@@ -76,6 +63,10 @@ sub summary
}
+# Descriptions: top level entrance for "review" mode
+# Arguments: $self varargs ...
+# Side Effects: none
+# Return Value: none
sub review
{
my ($self, @opts) = @_;
@@ -88,6 +79,10 @@ sub review
+# Descriptions: dynamic loading of sub modules
+# Arguments: $self
+# Side Effects: @INC modified
+# Return Value: none
sub _load_library
{
my ($self) = @_;
@@ -111,180 +106,116 @@ sub _load_library
}
+#
+# SUMMARY MODE
+#
+
+
+# Descriptions: get thread id list with status != 'open' and
+# show summary for the list
+# Arguments: $self
+# Side Effects: none
+# Return Value: none
sub _do_summary
{
my ($thread) = @_;
my $mode = $thread->get_mode || 'text';
- # rh: thread id list picked at status databsae.
+ # rh: thread id list picked from status.db
my $thread_id_list = $thread->list_up_thread_id();
+ # 1. sort the thread output order by cost
+ # 2. print the thread brief summary in that order.
+ # 3. show short summary for each message if needed (mode dependent)
if (@$thread_id_list) {
- # sort the thread output order by cost and
- # print the thread summary in that order.
$thread->sort_thread_id($thread_id_list);
$thread->_print_thread_summary($thread_id_list);
-
- # show short summary for each message
- unless ($mode eq 'html') {
- $thread->_print_message_summary($thread_id_list);
- }
+ $thread->_print_message_summary($thread_id_list);
}
}
+# Descriptions:
+# Arguments: $self $args
+# Side Effects:
+# Return Value: none
sub _print_thread_summary
{
my ($self, $thread_id_list) = @_;
- my $mode = $self->get_mode || 'text';
- my $rh_age = $self->{ _age } || {};
- my $fd = $self->{ _fd } || \*STDOUT;
- my $rh = $self->{ _hash_table };
- my $format = "%-20s %10s %5s %8s %s\n";
+ my $mode = $self->get_mode || 'text';
+ my $db = $self->{ _hash_table };
- if ($mode eq 'text') {
- printf($fd $format, 'id', 'date', 'age', 'status', 'articles');
- print $fd "-" x60;
- print $fd "\n";
- }
- else {
- print $fd "<TABLE BORDER=4>\n";
- print $fd "<TD>id\n";
- print $fd "<TD>summary\n";
- print $fd "<TD>age\n";
- print $fd "<TD>status\n";
- print $fd "<TD>action\n";
- }
+ # guide of presentation
+ $self->__start_thread_summary(); # XXX dynamic binding
- my ($tid, @article_id, $article_id, $date, $age, $status) = ();
- my $dh = new Mail::Message::Date;
- for $tid (@$thread_id_list) {
- next unless defined $rh->{ _articles }->{ $tid };
+ # show brief summary along thread_id list
+ my ($thread_id, @article_id, $article_id, $date, $age, $status) = ();
+ my $date_h = new Mail::Message::Date;
+ for $thread_id (@$thread_id_list) {
+ next unless defined $db->{ _articles }->{ $thread_id };
# get the first $article_id from the article_id list
- (@article_id) = split(/\s+/, $rh->{ _articles }->{ $tid });
+ (@article_id) = split(/\s+/, $db->{ _articles }->{ $thread_id });
$article_id = $article_id[0];
- # determine $date for the $article_id
- # $age and $status for $thread_id
- $date = $dh->YYYYxMMxDD( $rh->{ _date }->{ $article_id } , '/');
- $age = $rh_age->{ $tid };
- $status = $rh->{ _status }->{ $tid };
-
- if ($mode eq 'html') {
- eval q{
- use Mail::ThreadTrack::Print::HTML;
- push(@ISA, qw(Mail::ThreadTrack::Print::HTML));
- };
- $self->_show_thread_by_html_table({
- date => $date,
- age => $age,
- status => $status,
- tid => $tid,
- articles => $rh->{ _articles }->{ $tid },
- });
- }
- else {
- printf($fd $format, $tid, $date, $age, $status,
- _format_list(25, $rh->{ _articles }->{ $tid }));
- }
+ # format $date for the $article_id
+ $date = $date_h->YYYYxMMxDD( $db->{ _date }->{ $article_id } , '/');
+ $age = $self->{ _age }->{ $thread_id };
+ $status = $db->{ _status }->{ $thread_id };
+
+ $self->__print_thread_summary( {
+ date => $date,
+ age => $age,
+ status => $status,
+ thread_id => $thread_id,
+ articles => $db->{ _articles }->{ $thread_id },
+ }); # XXX dynamic binding
}
- if ($mode eq 'html') {
- print $fd "</TABLE>\n";
- }
-}
-
-
-sub _format_list
-{
- my ($max, $str) = @_;
- my (@idlist) = split(/\s+/, $str);
- my $r = '';
-
- for (@idlist) {
- $r .= $_ . " ";
- if (length($r) > $max) {
- $r .= "...";
- last;
- }
- }
-
- return $r;
-}
-
-
-sub _cost_to_indicator
-{
- my ($cost) = @_;
- my $how_bad = 0;
-
- if ($cost =~ /(\w+)\-(\d+)/) {
- $how_bad += $2;
- $how_bad += 2 if $1 =~ /open/;
- $how_bad = "!" x ($how_bad > 6 ? 6 : $how_bad);
- }
+ $self->__end_thread_summary(); # XXX dynamic binding
}
+# Descriptions: show the first few lines of the first message in the thread
+# Arguments: $self $id
+# Side Effects: none
+# Return Value: none
sub _print_message_summary
{
my ($self, $thread_id) = @_;
- my $config = $self->{ _config };
- my $age = $self->{ _age } || {};
- my $cost = $self->{ _cost } || {};
- my $fd = $self->{ _fd } || \*STDOUT;
- my $rh = $self->{ _hash_table };
-
- if (defined $config->{ spool_dir }) {
- my ($aid, @aid, $file);
- my $spool_dir = $config->{ spool_dir };
-
- THREAD_ID_LIST:
- for my $tid (@$thread_id) {
- if ($is_show_cost_indicate) {
- my $how_bad = _cost_to_indicator( $cost->{ $tid } );
- printf $fd "\n%6s %-10s %s\n", $how_bad, $tid;
- }
- else {
- printf $fd "\n>Thread-Id: %-10s %s\n", $tid;
- }
-
- # show only the first article of this thread $tid
- if (defined $rh->{ _articles }->{ $tid }) {
- (@aid) = split(/\s+/, $rh->{ _articles }->{ $tid });
- $aid = $aid[0];
- $file = File::Spec->catfile($spool_dir, $aid);
- if (-f $file) {
- $self->print( $self->message_summary($file) );
- }
- }
- }
- }
+ $self->__print_message_summary($thread_id);
}
+#
+# REVIEW MODE
+#
+
+# Descriptions: show brief summary chain of messages in the thread
+# Arguments: $self $string $min_num $max_num
+# Side Effects:
+# Return Value: none
sub _do_review
{
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 $db = $self->{ _hash_table };
my %uniq = ();
+ my $is_first = 0;
- # modify Print parameters
- $self->{ _article_summary_lines } = 5;
-
+ # translate the given parameter (MH style)
+ # get HASH ARRAY of specified range
use Mail::Message::MH;
- my $ra = Mail::Message::MH->expand($str, $min, $max);
- my $first = 0;
+ my $range = Mail::Message::MH->expand($str, $min, $max);
- if (defined $config->{ reverse_order }) { @$ra = reverse @$ra;}
+ # reverse order (first thread is the latest one) if reverse mode
+ if (defined $config->{ reverse_order }) { @$range = reverse @$range;}
ID_LIST:
- for my $id (@$ra) {
+ for my $id (@$range) {
next ID_LIST unless defined $id;
if ($id =~ /^\d+$/) {
@@ -292,22 +223,23 @@ sub _do_review
my $tid = $self->_create_thread_id_strings($id);
# check thread id $tid exists really ?
- if (defined $rh->{ _articles }->{ $tid }) {
+ if (defined $db->{ _articles }->{ $tid }) {
printf $fd "\n>Thread-Id: %-10s %s\n", $tid;
# different treatment for the fisrt article in this thread
- $first = 1;
+ $is_first = 1;
# show all articles in this thread
ARTICLE:
- for my $aid (split(/\s+/, $rh->{ _articles }->{ $tid })) {
+ for my $aid (split(/\s+/, $db->{ _articles }->{ $tid })) {
# ensure uniquness
next ARTICLE if $uniq{ $aid };
$uniq{ $aid } = 1;
- if ($first) {
+ # show header only for the first message in this thread
+ if ($is_first) {
undef $self->{ _no_header_summary };
- $first = 0;
+ $is_first = 0;
}
else {
$self->{ _no_header_summary } = 1;
@@ -330,6 +262,10 @@ sub _do_review
=cut
+# Descriptions: wrapper of print()
+# Arguments: $self $str
+# Side Effects: quote if needed
+# Return Value: none
sub print
{
my ($self, $str) = @_;
@@ -347,6 +283,10 @@ sub print
}
+# Descriptions: quote for html
+# Arguments: $str
+# Side Effects: quote
+# Return Value: string
sub _quote
{
my ($str) = @_;
diff --git a/fml/lib/Mail/ThreadTrack/Print/HTML.pm b/fml/lib/Mail/ThreadTrack/Print/HTML.pm
index 2112abcf..69e1e960 100644
--- a/fml/lib/Mail/ThreadTrack/Print/HTML.pm
+++ b/fml/lib/Mail/ThreadTrack/Print/HTML.pm
@@ -1,11 +1,26 @@
+#-*- 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: Sort.pm,v 1.4 2001/11/10 08:50:41 fukachan Exp $
+#
+
package Mail::ThreadTrack::Print::HTML;
use strict;
use vars qw(@ISA @EXPORT @EXPORT_OK $AUTOLOAD);
use Carp;
+use CGI qw/:standard/;
+
use Mail::ThreadTrack::Print::Utils qw(decode_mime_string STR2EUC);
+# Descriptions: show articles as HTML in this thread
+# Arguments: $self $str
+# Side Effects: none
+# Return Value: none
sub show_articles_for_thread
{
my ($self, $thread_id) = @_;
@@ -46,9 +61,44 @@ sub show_articles_for_thread
}
-# This shows summary on C<$thread_id> in HTML language.
-# It is used in C<FML::CGI::ThreadSystem>.
-sub _show_thread_by_html_table
+# Descriptions: show guide
+# Arguments: $self $args
+# Side Effects: none
+# Return Value: none
+sub __start_thread_summary
+{
+ my ($self, $args) = @_;
+ my $fd = $self->{ _fd } || \*STDOUT;
+
+ print $fd "<TABLE BORDER=4>\n";
+ print $fd "<TD>id\n";
+ print $fd "<TD>summary\n";
+ print $fd "<TD>age\n";
+ print $fd "<TD>status\n";
+ print $fd "<TD>change\n";
+}
+
+
+# Descriptions: finalize thread list
+# close TABLE tag
+# Arguments: $self $args
+# Side Effects: none
+# Return Value: none
+sub __end_thread_summary
+{
+ my ($self, $args) = @_;
+ my $fd = $self->{ _fd } || \*STDOUT;
+
+ print $fd "</TABLE>\n";
+}
+
+
+# Descriptions: This shows summary on C<$thread_id> in HTML language.
+# It is used in C<FML::CGI::ThreadSystem>.
+# Arguments: $self $args
+# Side Effects: none
+# Return Value: none
+sub __print_thread_summary
{
my ($self, $optargs) = @_;
my $config = $self->{ _config };
@@ -57,12 +107,10 @@ sub _show_thread_by_html_table
my $action = 'fmlthread.cgi';
my $target = $config->{ thread_cgi_target_window } || 'ThreadCGIWindow';
- # printf($fd $format,
- # $date, $age, $status, $tid, $rh->{ _articles }->{ $tid });
my $date = $optargs->{ date };
my $age = $optargs->{ age };
my $status = $optargs->{ status };
- my $tid = $optargs->{ tid };
+ my $tid = $optargs->{ thread_id };
my $articles = $optargs->{ articles };
my $aid = (split(/\s+/, $articles))[0];
@@ -75,7 +123,11 @@ sub _show_thread_by_html_table
$action .= "&thread_id=$xtid&article_id=$aid";
print "<TR>\n";
- print "<TD>$tid\n";
+ print "<TD>";
+ print "<A HREF=\"$action&action=show\"\n\tTARGET=\"$target.show\">";
+ print $tid;
+ print "\n</A>\n";
+
print "<TD>";
# summary
@@ -91,14 +143,30 @@ sub _show_thread_by_html_table
print "<TD>$age\n";
print "<TD>$status\n";
print "<TD>";
- print "<A HREF=\"$action&action=close\" TARGET=\"$target.close\">";
- print "[close]</A>\n";
- print "<BR>\n";
- print "<A HREF=\"$action&action=show\" TARGET=\"$target.show\">";
- print "[see articles]</A>\n";
+ my $name = "change-status=$tid";
+ my $values = ['open', 'analyzed', 'closed'];
+ my $default = $status;
+ print checkbox_group(-name=>$name,
+ -values=>$values,
+ -defaults=>$default,
+ -linebreak=>'true',
+ );
+
+ # print "<A HREF=\"$action&action=close\" TARGET=\"$target.close\">";
+ # print "[close]</A>\n";
print "\n\n";
}
+# Descriptions: dummy
+# Arguments: none
+# Side Effects: none
+# Return Value: none
+sub __print_message_summary
+{
+ ;
+}
+
+
1;
diff --git a/fml/lib/Mail/ThreadTrack/Print/Text.pm b/fml/lib/Mail/ThreadTrack/Print/Text.pm
index 0afc6045..2bd5895d 100644
--- a/fml/lib/Mail/ThreadTrack/Print/Text.pm
+++ b/fml/lib/Mail/ThreadTrack/Print/Text.pm
@@ -1 +1,148 @@
+#-*- 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: Sort.pm,v 1.4 2001/11/10 08:50:41 fukachan Exp $
+#
+
+package Mail::ThreadTrack::Print::Text;
+use strict;
+use vars qw(@ISA @EXPORT @EXPORT_OK $AUTOLOAD);
+use Carp;
+
+my $is_show_cost_indicate = 0;
+
+my $format = "%-20s %10s %5s %8s %s\n";
+
+
+# Descriptions: show guide line
+# Arguments: $self $args
+# Side Effects: none
+# Return Value: none
+sub __start_thread_summary
+{
+ my ($self, $args) = @_;
+ my $fd = $self->{ _fd } || \*STDOUT;
+
+ printf($fd $format, 'id', 'date', 'age', 'status', 'articles');
+ print $fd "-" x60;
+ print $fd "\n";
+}
+
+
+# Descriptions: print formated brief summary
+# Arguments: $self $args
+# Side Effects: none
+# Return Value: none
+sub __print_thread_summary
+{
+ my ($self, $optargs) = @_;
+ my $fd = $self->{ _fd } || \*STDOUT;
+ my $date = $optargs->{ date };
+ my $age = $optargs->{ age };
+ my $status = $optargs->{ status };
+ my $thread_id = $optargs->{ thread_id };
+ my $articles = $optargs->{ articles };
+ my $aid = (split(/\s+/, $articles))[0];
+
+ printf($fd $format, $thread_id, $date, $age, $status,
+ _format_list(25, $articles));
+}
+
+
+# Descriptions:
+# Arguments: $self $args
+# Side Effects:
+# Return Value: none
+sub __end_thread_summary
+{
+ my ($self, $args) = @_;
+ my $fd = $self->{ _fd } || \*STDOUT;
+}
+
+
+# Descriptions: create a string of "a b c .." style up to $num bytes
+# Arguments: $num $str
+# Side Effects: none
+# Return Value: string
+sub _format_list
+{
+ my ($max, $str) = @_;
+ my (@idlist) = split(/\s+/, $str);
+ my $r = '';
+
+ for (@idlist) {
+ $r .= $_ . " ";
+ if (length($r) > $max) {
+ $r .= "...";
+ last;
+ }
+ }
+
+ return $r;
+}
+
+
+# Descriptions: print message summary
+# Arguments: $self $args
+# Side Effects: none
+# Return Value: none
+sub __print_message_summary
+{
+ my ($self, $thread_id) = @_;
+ my $config = $self->{ _config };
+ my $age = $self->{ _age } || {};
+ my $cost = $self->{ _cost } || {};
+ my $fd = $self->{ _fd } || \*STDOUT;
+ my $rh = $self->{ _hash_table };
+
+ if (defined $config->{ spool_dir }) {
+ my ($aid, @aid, $file);
+ my $spool_dir = $config->{ spool_dir };
+
+ THREAD_ID_LIST:
+ for my $thread_id (@$thread_id) {
+ if ($is_show_cost_indicate) {
+ my $how_bad = _cost_to_indicator( $cost->{ $thread_id } );
+ printf $fd "\n%6s %-10s %s\n", $how_bad, $thread_id;
+ }
+ else {
+ printf $fd "\n>Thread-Id: %-10s %s\n", $thread_id;
+ }
+
+ # show only the first article of this thread $thread_id
+ if (defined $rh->{ _articles }->{ $thread_id }) {
+ (@aid) = split(/\s+/, $rh->{ _articles }->{ $thread_id });
+ $aid = $aid[0];
+ $file = File::Spec->catfile($spool_dir, $aid);
+ if (-f $file) {
+ $self->print( $self->message_summary($file) );
+ }
+ }
+ }
+ }
+}
+
+
+# Descriptions: ( broken now ;-)
+# Arguments: $string
+# Side Effects: none
+# Return Value: string
+sub _cost_to_indicator
+{
+ my ($cost) = @_;
+ my $how_bad = 0;
+
+ if ($cost =~ /(\w+)\-(\d+)/) {
+ $how_bad += $2;
+ $how_bad += 2 if $1 =~ /open/;
+ $how_bad = "!" x ($how_bad > 6 ? 6 : $how_bad);
+ }
+
+ $how_bad;
+}
+
+
1;