summaryrefslogtreecommitdiff
path: root/fml/lib/Mail/ThreadTrack
diff options
context:
space:
mode:
authorfukachan <fukachan>2001-11-10 09:04:27 +0000
committerfukachan <fukachan>2001-11-10 09:04:27 +0000
commit59b3fd872ca15e60fc55c7214ef7655e555132bf (patch)
tree6587fe83f2f7d194e0416f65c63c099d221a094d /fml/lib/Mail/ThreadTrack
parent4d9b6032da532bce9f0f27ee504fa2ff05eceb39 (diff)
downloadfml8-59b3fd872ca15e60fc55c7214ef7655e555132bf.tar.gz
fml8-59b3fd872ca15e60fc55c7214ef7655e555132bf.tar.bz2
fml8-59b3fd872ca15e60fc55c7214ef7655e555132bf.zip
clean up summary() mode for both text and html modes.
print() method knows what should it do for text/html mode.
Diffstat (limited to 'fml/lib/Mail/ThreadTrack')
-rw-r--r--fml/lib/Mail/ThreadTrack/Print.pm100
-rw-r--r--fml/lib/Mail/ThreadTrack/Print/HTML.pm129
-rw-r--r--fml/lib/Mail/ThreadTrack/Print/Message.pm47
3 files changed, 134 insertions, 142 deletions
diff --git a/fml/lib/Mail/ThreadTrack/Print.pm b/fml/lib/Mail/ThreadTrack/Print.pm
index 777cc7de..66d7fe95 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.12 2001/11/09 12:08:45 fukachan Exp $
+# $FML: Print.pm,v 1.13 2001/11/09 15:09:03 fukachan Exp $
#
package Mail::ThreadTrack::Print;
@@ -113,23 +113,21 @@ sub _load_library
sub _do_summary
{
- my ($self) = @_;
- my ($tid, $status, $thread_id);
- my $mode = $self->get_mode || 'text';
- my $fd = $self->{ _fd } || \*STDOUT;
+ my ($thread) = @_;
+ my $mode = $thread->get_mode || 'text';
- # rh: thread id list, which is ARRAY REFERENCE tied to db_dir/*db's
- $thread_id = $self->list_up_thread_id();
+ # rh: thread id list picked at status databsae.
+ my $thread_id_list = $thread->list_up_thread_id();
- if (@$thread_id) {
+ if (@$thread_id_list) {
# sort the thread output order by cost and
# print the thread summary in that order.
- $self->sort_thread_id($thread_id);
- $self->_print_thread_summary($thread_id);
+ $thread->sort_thread_id($thread_id_list);
+ $thread->_print_thread_summary($thread_id_list);
# show short summary for each message
unless ($mode eq 'html') {
- $self->_print_message_summary($thread_id);
+ $thread->_print_message_summary($thread_id_list);
}
}
}
@@ -143,18 +141,20 @@ sub _print_thread_summary
my $rh_age = $self->{ _age } || {};
my $fd = $self->{ _fd } || \*STDOUT;
my $rh = $self->{ _hash_table };
- my $format = "%10s %5s %8s %-20s %s\n";
+ my $format = "%-20s %10s %5s %8s %s\n";
if ($mode eq 'text') {
- printf($fd $format, 'date', 'age', 'status', 'thread id', 'articles');
+ printf($fd $format, 'id', 'date', 'age', 'status', 'articles');
print $fd "-" x60;
print $fd "\n";
}
else {
print $fd "<TABLE BORDER=4>\n";
- print "<TD>action\n";
- print "<TD>date\n"."<TD>age\n"."<TD>status\n"."<TD>thread id\n";
- print "<TD>article summary\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";
}
my ($tid, @article_id, $article_id, $date, $age, $status) = ();
@@ -177,10 +177,17 @@ sub _print_thread_summary
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,
- $date, $age, $status, $tid, $rh->{ _articles }->{ $tid });
+ printf($fd $format, $tid, $date, $age, $status,
+ _format_list(25, $rh->{ _articles }->{ $tid }));
}
}
@@ -190,6 +197,24 @@ sub _print_thread_summary
}
+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) = @_;
@@ -232,7 +257,7 @@ sub _print_message_summary
$aid = $aid[0];
$file = File::Spec->catfile($spool_dir, $aid);
if (-f $file) {
- print $fd $self->message_summary($file);
+ $self->print( $self->message_summary($file) );
}
}
}
@@ -290,7 +315,7 @@ sub _do_review
my $file = File::Spec->catfile($spool_dir, $aid);
if (-f $file) {
- print $fd $self->message_summary($file);
+ $self->print( $self->message_summary($file) );
print $fd "\n";
}
}
@@ -300,4 +325,39 @@ sub _do_review
}
+=head2 print()
+
+=cut
+
+
+sub print
+{
+ my ($self, $str) = @_;
+ my $mode = $self->get_mode || 'text';
+ my $fd = $self->{ _fd } || \*STDOUT;
+
+ if ($mode eq 'text') {
+ print $fd $str;
+ }
+ elsif ($mode eq 'html') {
+ $str = &_quote($str);
+ $str =~ s/\n/<BR>\n/g;
+ print $fd $str;
+ }
+}
+
+
+sub _quote
+{
+ my ($str) = @_;
+
+ $str =~ s/&/&amp;/g;
+ $str =~ s/</&lt;/g;
+ $str =~ s/>/&gt;/g;
+ $str =~ s/\"/&quot;/g;
+
+ return $str;
+}
+
+
1;
diff --git a/fml/lib/Mail/ThreadTrack/Print/HTML.pm b/fml/lib/Mail/ThreadTrack/Print/HTML.pm
index 41476bc9..2112abcf 100644
--- a/fml/lib/Mail/ThreadTrack/Print/HTML.pm
+++ b/fml/lib/Mail/ThreadTrack/Print/HTML.pm
@@ -6,16 +6,6 @@ use Carp;
use Mail::ThreadTrack::Print::Utils qw(decode_mime_string STR2EUC);
-sub STR2EUC
-{
- my ($str) = @_;
-
- use Jcode;
- &Jcode::convert(\$str, 'euc');
- return $str;
-}
-
-
sub show_articles_for_thread
{
my ($self, $thread_id) = @_;
@@ -23,8 +13,6 @@ sub show_articles_for_thread
my $config = $self->{ _config };
my $spool_dir = $config->{ spool_dir };
- $self->db_open();
-
my $articles = $self->{ _hash_table }->{ _articles }->{ $thread_id };
print "<B>";
@@ -55,46 +43,9 @@ sub show_articles_for_thread
}
print "</PRE>";
-
- $self->db_close();
-}
-
-
-sub cgi_top_menu
-{
- my ($self) = @_;
- my $config = $self->{ _config };
- my $action = 'fmlthread.cgi';
- my $target = $config->{ thread_cgi_target_window } || 'ThreadCGIWindow';
-
- use DirHandle;
- my $dh = new DirHandle $config->{ ml_home_prefix };
- my @dirlist;
- my $prefix = $config->{ ml_home_prefix };
- while ($_ = $dh->read()) {
- next if /^\./;
- next if /^\@/;
- push(@dirlist, $_) if -f "$prefix/$_/config.cf";
- }
- $dh->close;
-
- if ($self->get_mode eq 'html') {
- require 'ctime.pl';
- my $time = ctime(time);
- my $ml_name = $config->{ ml_name };
- print "[$time] the brief summary for \"$ml_name\" ML<BR>";
- }
-
- use CGI qw/:standard/;
- print start_form(-action=>$action, -target=>$target);
- print "mailing list: ",
- popup_menu(-name => 'ml_name', -values => \@dirlist),
- submit(-name => 'go'),
- end_form;
}
-
# This shows summary on C<$thread_id> in HTML language.
# It is used in C<FML::CGI::ThreadSystem>.
sub _show_thread_by_html_table
@@ -108,7 +59,6 @@ sub _show_thread_by_html_table
# printf($fd $format,
# $date, $age, $status, $tid, $rh->{ _articles }->{ $tid });
- my $format = $optargs->{ format };
my $date = $optargs->{ date };
my $age = $optargs->{ age };
my $status = $optargs->{ status };
@@ -125,77 +75,30 @@ sub _show_thread_by_html_table
$action .= "&thread_id=$xtid&article_id=$aid";
print "<TR>\n";
+ print "<TD>$tid\n";
+ print "<TD>";
+
+ # summary
+ if (defined $articles) {
+ $aid = (split(/\s+/, $articles))[0];
+ my $f = File::Spec->catfile($spool_dir, $aid);
+ if (-f $f) {
+ my $buf = $self->message_summary($f);
+ $self->print( STR2EUC($buf) );
+ }
+ }
+
+ 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";
- print "<TD>$date\n";
- print "<TD>$age\n";
- print "<TD>$status\n";
- print "<TD>$tid\n";
- print "<TD>";
-
- $aid = (split(/\s+/, $articles))[0];
- my $buf = $self->_article_summary(File::Spec->catfile($spool_dir, $aid));
- print STR2EUC($buf);
-}
-
-
-=head2 C<run_cgi()>
-
-execute CGI.
-
-=cut
-
-sub run_cgi
-{
- my ($self) = @_;
- my $config = $self->{ _config };
- my $title = $config->{ thread_cgi_title } || 'thread system interface';
- my $color = $config->{ thread_cgi_bgcolor } || '#E6E6FA';
- # XXX $ml_name may change by HTTP request
- $config->{ ml_name } = param('ml_name') if param('ml_name');
-
- # ensure the current mode
- $self->mode('html');
-
- # load standard CGI routines
- use CGI qw/:standard/;
-
- # get action parameter via HTTP
- my $action = param('action') || 'list';
- my $thread_id = param('thread_id');
-
- # o.k start html
- print start_html(-title=>$title,-BGCOLOR=>$color), "\n";
-
- if ($action eq 'close') {
- $self->set_status({
- thread_id => $thread_id,
- status => 'close',
- });
- }
-
- if ($action eq 'show') {
- Log("run.cgi.show_articles for $thread_id");
- $self->show_articles_for_thread($thread_id);
- }
- else {
- # menu at the top of scrren
- $self->cgi_top_menu();
-
- # show summary
- $self->show_summary();
- }
-
- # o.k. end of html
- print end_html;
- print "\n";
+ print "\n\n";
}
1;
-1;
diff --git a/fml/lib/Mail/ThreadTrack/Print/Message.pm b/fml/lib/Mail/ThreadTrack/Print/Message.pm
index af338db1..9b6c448a 100644
--- a/fml/lib/Mail/ThreadTrack/Print/Message.pm
+++ b/fml/lib/Mail/ThreadTrack/Print/Message.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: Message.pm,v 1.1 2001/11/09 11:30:31 fukachan Exp $
+# $FML: Message.pm,v 1.2 2001/11/09 13:30:38 fukachan Exp $
#
package Mail::ThreadTrack::Print::Message;
@@ -110,6 +110,7 @@ sub _delete_subject_tag_like_string
sub header_summary
{
my ($self, $args) = @_;
+ my $date = $args->{ header }->get('date');
my $from = $args->{ header }->get('from');
my $subject = $args->{ header }->get('subject');
my $padding = $args->{ padding };
@@ -117,18 +118,46 @@ sub header_summary
$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' });
+ $subject =~ s/[\s\n]*$//g;
+ $from = $self->_who_of_address( $from );
$from =~ s/\n/ /g;
-
- my $br = $self->get_mode eq 'html' ? '<BR>' : '';
+ $from =~ s/[\s\n]*$//g;
# return buffer
- my $r = '';
- $r .= STR2EUC( $padding. " From: ". $from ."$br\n" );
- $r .= STR2EUC( $padding. "Subject: ". $subject ."$br\n" );
+ my $r = $padding. $date;
+ $r .= $padding. "$subject, $from\n";
+ return STR2EUC( $r );
+}
+
- return $r;
+sub _who_of_address
+{
+ my ($self, $address) = @_;
+ my ($user);
+
+ use Mail::Address;
+ my (@addrs) = Mail::Address->parse($address);
+
+ for my $addr (@addrs) {
+ if (defined( $addr->phrase() )) {
+ my $phrase = decode_mime_string( $addr->phrase(), {
+ charset => 'euc-japan',
+ });
+
+ if ($phrase) {
+ return($phrase);
+ }
+ }
+
+ $user = $addr->user();
+ }
+
+ if ($self->get_mode() eq 'html') {
+ return( $user ? "$user\@xxx.xxx.xxx.xxx" : $address );
+ }
+ else {
+ return $address;
+ }
}