summaryrefslogtreecommitdiff
path: root/fml/lib/Mail/ThreadTrack
diff options
context:
space:
mode:
authorfukachan <fukachan>2001-11-09 11:28:41 +0000
committerfukachan <fukachan>2001-11-09 11:28:41 +0000
commitd70afc7a664bdba418a3bc1fe6c3b96834d85620 (patch)
tree1866a5e9dd0ef9803941aa19a6a39c525f4d6727 /fml/lib/Mail/ThreadTrack
parentc8c9d60e344c33000fba46c5997120f659e09b8e (diff)
downloadfml8-d70afc7a664bdba418a3bc1fe6c3b96834d85620.tar.gz
fml8-d70afc7a664bdba418a3bc1fe6c3b96834d85620.tar.bz2
fml8-d70afc7a664bdba418a3bc1fe6c3b96834d85620.zip
move sorting function to Mail::ThreadTrack::Print::Sort
Diffstat (limited to 'fml/lib/Mail/ThreadTrack')
-rw-r--r--fml/lib/Mail/ThreadTrack/Print/Sort.pm83
1 files changed, 83 insertions, 0 deletions
diff --git a/fml/lib/Mail/ThreadTrack/Print/Sort.pm b/fml/lib/Mail/ThreadTrack/Print/Sort.pm
new file mode 100644
index 00000000..062ead50
--- /dev/null
+++ b/fml/lib/Mail/ThreadTrack/Print/Sort.pm
@@ -0,0 +1,83 @@
+#-*- 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::Sort;
+use strict;
+use vars qw(@ISA @EXPORT @EXPORT_OK $AUTOLOAD);
+use Carp;
+
+
+=head2 sort($thread_id_list)
+
+=cut
+
+
+# Descriptions:
+# Arguments: $self $args
+# Side Effects:
+# Return Value: none
+sub sort
+{
+ my ($self, $thread_id_list) = @_;
+
+ # get age HASH TABLE
+ my ($age, $cost) = $self->_calculate_age($thread_id_list);
+ $self->{ _age } = $age;
+ $self->{ _cost } = $cost;
+
+ $self->_sort_thread_id($thread_id_list, $cost);
+}
+
+
+# Descriptions:
+# Arguments: $self $args
+# Side Effects:
+# Return Value: none
+sub _sort_thread_id
+{
+ my ($self, $thread_id_list, $cost) = @_;
+
+ @$thread_id_list = sort {
+ $cost->{$b} cmp $cost->{$a};
+ } @$thread_id_list;
+}
+
+
+# Descriptions:
+# Arguments: $self $args
+# Side Effects:
+# Return Value: none
+sub _calculate_age
+{
+ my ($self, $thread_id_list) = @_;
+ my (%age, %cost) = ();
+ my $now = time; # save the current UTC for convenience
+ my $rh = $self->{ _hash_table } || {};
+ my $day = 24*3600;
+
+ # $age hash referehence = { $thread_id => $age };
+ my (@aid, $last, $age, $date, $status, $tid) = ();
+ for $tid (sort @$thread_id_list) {
+ # $last: get the latest one of article_id's
+ (@aid) = split(/\s+/, $rh->{ _articles }->{ $tid });
+ $last = $aid[ $#aid ] || 0;
+
+ # how long this thread is not concerned ?
+ $age = sprintf("%2.1f%s", ($now - $rh->{ _date }->{ $last })/$day);
+ $age{ $tid } = $age;
+
+ # evaluate cost hash table which is { $thread_id => $cost }
+ $cost{ $tid } = $rh->{ _status }->{ $tid }.'-'. $age;
+ }
+
+ return (\%age, \%cost);
+}
+
+
+1;