diff options
| author | fukachan <fukachan> | 2004-10-31 08:33:59 +0000 |
|---|---|---|
| committer | fukachan <fukachan> | 2004-10-31 08:33:59 +0000 |
| commit | dd0fc21b3f07198a486223cb55c5939c053d488c (patch) | |
| tree | a473787afc591d58774fb810e8158dc081ba19ec /fml/lib | |
| parent | aee4335b1611fe5b9d210967851d3456f193f852 (diff) | |
| download | fml8-dd0fc21b3f07198a486223cb55c5939c053d488c.tar.gz fml8-dd0fc21b3f07198a486223cb55c5939c053d488c.tar.bz2 fml8-dd0fc21b3f07198a486223cb55c5939c053d488c.zip | |
sort, clean up.
Diffstat (limited to 'fml/lib')
| -rw-r--r-- | fml/lib/FML/Article/Thread.pm | 431 |
1 files changed, 216 insertions, 215 deletions
diff --git a/fml/lib/FML/Article/Thread.pm b/fml/lib/FML/Article/Thread.pm index 65bd25f8..bb8c1791 100644 --- a/fml/lib/FML/Article/Thread.pm +++ b/fml/lib/FML/Article/Thread.pm @@ -3,7 +3,7 @@ # Copyright (C) 2003,2004 Ken'ichi Fukamachi # All rights reserved. # -# $FML: Thread.pm,v 1.10 2004/07/23 13:16:32 fukachan Exp $ +# $FML: Thread.pm,v 1.11 2004/07/23 15:59:01 fukachan Exp $ # package FML::Article::Thread; @@ -114,143 +114,120 @@ sub new } -=head1 SHOW STATUS +=head1 HANDLE ARTICLE -=head2 print_one_line_summary($thread_args) +=head2 add_article($id, $msg) -=head2 print_summary($thread_args) +check the status of specified article $id where $msg is a +Mail::Message object. + +This routine is expected to be called within FML::Process::Distribute. +So, $msg must be already defined. =cut -# Descriptions: print one line summary. -# Arguments: OBJ($self) HASH_REF($thread_args) -# Side Effects: none +# Descriptions: check the content of message object. +# log and update UDB if needed. +# Arguments: OBJ($self) NUM($id) OBJ($msg) +# Side Effects: update UDB. # Return Value: none -sub print_one_line_summary +sub add_article { - my ($self, $thread_args) = @_; - my $id = $thread_args->{ last_id } || 0; + my ($self, $id, $msg) = @_; + my $curproc = $self->{ _curproc }; + my $thread = $self->{ _thread_object }; + my $article = $self->{ _article_object }; - if ($id) { - $self->_print_summary("one_line_summary", $thread_args); - } + # analyze the current message and store the data into DB (UDB). + # XXX this analyzer examines the basic profile of article, but + # XXX not determine the status "open", "close" et.al. for the article. + # XXX The determination is deferred below. + $thread->analyze($msg); + + # analyze more details of the content and create a hint to + # determine the thread status for later use. + $self->check_if_article_is_reply_message($id, $msg); + $self->check_if_article_has_closing_phrase($id, $msg); + $self->check_if_article_should_be_ignored($id, $msg); } -# Descriptions: print summary. -# Arguments: OBJ($self) HASH_REF($thread_args) -# Side Effects: none +# Descriptions: check the content of message object. +# log and update UDB if needed. +# Arguments: OBJ($self) NUM($id) OBJ($msg) +# Side Effects: update UDB. # Return Value: none -sub print_summary +sub check_if_article_is_reply_message { - my ($self, $thread_args) = @_; - my $id = $thread_args->{ last_id } || 0; + my ($self, $id, $msg) = @_; + my $curproc = $self->{ _curproc }; + my $thread = $self->{ _thread_object }; + my $article = $self->{ _article_object }; + my $header = $msg->whole_message_header(); - if ($id) { - $self->_print_summary("summary", $thread_args); + # 1) get subject. + my $subject = $header->get('subject'); + if ($subject =~ /=\?/o) { + my $string = new Mail::Message::String $subject; + $string->mime_decode(); + $string->charcode_convert_to_internal_code(); + $subject = $string->as_str(); + } + + # 2) it looks subject has a reply tag ? + use FML::Header::Subject; + my $subj = new FML::Header::Subject; + # XXX need $subject is already decoded. + if ($subj->is_reply($subject)) { + $thread->set_article_status($id, $state_followed); + } + else { + $thread->set_article_status($id, $state_open); } } -# Descriptions: actual engine to print summary. -# $thread_args = { -# last_id => last (max) id of our target range, -# range => MH style range, -# } -# Arguments: OBJ($self) STR($fp) HASH_REF($thread_args) -# Side Effects: none +# Descriptions: check the content of message object. +# log and update UDB if needed. +# Arguments: OBJ($self) NUM($id) OBJ($msg) +# Side Effects: update UDB. # Return Value: none -sub _print_summary +sub check_if_article_has_closing_phrase { - my ($self, $fp, $thread_args) = @_; + my ($self, $id, $msg) = @_; my $curproc = $self->{ _curproc }; my $thread = $self->{ _thread_object }; my $article = $self->{ _article_object }; - my $queue = []; - - # here we go. - my $summary = $thread->get_thread_data($thread_args); - - THREAD: - for my $head_id (sort {$a <=> $b} keys %$summary) { - # firstly check thread status. - my $status = $thread->get_thread_status($head_id) || "open"; - next THREAD if $status eq $state_closed; - next THREAD if $status eq $state_auto_closed; - my $list = $summary->{ $head_id } || []; - for my $id (@$list) { - my $article_path = $article->filepath($id); + my $rules = { + 'thank you' => 1, + }; + $msg->set_closing_phrase_rules($rules); - use FileHandle; - my $fh = new FileHandle $article_path; - if (defined $fh) { - use Mail::Message; - my $msg = Mail::Message->parse( { fd => $fh } ); - my $buf = $msg->$fp(); - my $q = { - cur_id => $id, - head_id => $head_id, - id_list => $list, - status => $status, - summary => $buf, - message => $msg, - }; - push(@$queue, $q); - } - else { - $curproc->logerror("no such file: $article_path"); - } - } + # check it as "closed(auto)" if it looks like the end of thread. + # for example, we can find some phrases, "thank you.", "this + # problem is resolved.",... at the last of the article. + if ($msg->has_closing_phrase()) { + $thread->set_article_status($id, $state_auto_closed); } - - my $pfp = $print_switch{ $print_mode }->{ summary }; - $self->$pfp($curproc, $queue); } -=head2 print_list($thread_args) - -list up thread and the related information. - -=cut - - -# Descriptions: list up thread and the related information. -# $thread_args = { -# last_id => last (max) id of our target range, -# range => MH style range, -# } -# Arguments: OBJ($self) HASH_REF($thread_args) -# Side Effects: none +# Descriptions: check the content of message object. +# log and update UDB if needed. +# Arguments: OBJ($self) NUM($id) OBJ($msg) +# Side Effects: update UDB. # Return Value: none -sub print_list +sub check_if_article_should_be_ignored { - my ($self, $thread_args) = @_; - my $curproc = $self->{ _curproc }; - my $thread = $self->{ _thread_object }; - my $article = $self->{ _article_object }; - my $summary = $thread->get_thread_data($thread_args); - my $queue = []; - - THREAD: - for my $head_id (sort {$a <=> $b} keys %$summary) { - my $status = $thread->get_thread_status($head_id) || "open"; - next THREAD if $status eq $state_closed; - next THREAD if $status eq $state_auto_closed; + my ($self, $id, $msg) = @_; - my $list = $summary->{ $head_id } || []; - my $q = { - head_id => $head_id, - id_list => $list, - status => $status, - }; - push(@$queue, $q); + # check if this article should be ignored ? + # for example, "cvs source changes" may be ignored at some ML. + if (0) { + # $self->check_message_filter( file => filter_config_file ) ? } - - my $pfp = $print_switch{ $print_mode }->{ list }; - $self->$pfp($curproc, $queue); } @@ -334,179 +311,203 @@ sub _init_message } -=head2 add_article($id, $msg) +=head2 open_thread_status($th_args) -check the status of specified article. $msg is a Mail::Message object. +open thread. -This routine is expected to be called within FML::Process::Distribute. -So, $msg must be already defined. +=head2 close_thread_status($th_args) + +close thread. =cut -# Descriptions: check the content of message object. -# log and update UDB if needed. -# Arguments: OBJ($self) NUM($id) OBJ($msg) -# Side Effects: update UDB. +# Descriptions: open thread. +# Arguments: OBJ($self) HASH_REF($thread_args) +# Side Effects: none # Return Value: none -sub add_article +sub open_thread_status { - my ($self, $id, $msg) = @_; - my $curproc = $self->{ _curproc }; - my $thread = $self->{ _thread_object }; - my $article = $self->{ _article_object }; - - # analyze the current message and store the data into DB (UDB). - # XXX this analyzer examines the basic profile of article, but - # XXX not determine the status "open", "close" et.al. for the article. - # XXX The determination is deferred below. - $thread->analyze($msg); + my ($self, $thread_args) = @_; - # analyze more details of the content and create a hint to - # determine the thread status for later use. - $self->check_if_article_is_reply_message($id, $msg); - $self->check_if_article_has_closing_phrase($id, $msg); - $self->check_if_article_should_be_ignored($id, $msg); + $self->_change_thread_status("open", $thread_args, $state_open); } -# Descriptions: check the content of message object. -# log and update UDB if needed. -# Arguments: OBJ($self) NUM($id) OBJ($msg) -# Side Effects: update UDB. +# Descriptions: close thread. +# Arguments: OBJ($self) HASH_REF($thread_args) +# Side Effects: none # Return Value: none -sub check_if_article_is_reply_message +sub close_thread_status { - my ($self, $id, $msg) = @_; - my $curproc = $self->{ _curproc }; - my $thread = $self->{ _thread_object }; - my $article = $self->{ _article_object }; - my $header = $msg->whole_message_header(); - - # 1) get subject. - my $subject = $header->get('subject'); - if ($subject =~ /=\?/o) { - my $string = new Mail::Message::String $subject; - $string->mime_decode(); - $string->charcode_convert_to_internal_code(); - $subject = $string->as_str(); - } + my ($self, $thread_args) = @_; - # 2) it looks subject has a reply tag ? - use FML::Header::Subject; - my $subj = new FML::Header::Subject; - # XXX need $subject is already decoded. - if ($subj->is_reply($subject)) { - $thread->set_article_status($id, $state_followed); - } - else { - $thread->set_article_status($id, $state_open); - } + $self->_change_thread_status("close", $thread_args, $state_closed); } -# Descriptions: check the content of message object. -# log and update UDB if needed. -# Arguments: OBJ($self) NUM($id) OBJ($msg) +# Descriptions: open/close thread with the specified range. +# Arguments: OBJ($self) STR($action) HASH_REF($thread_args) STR($state) # Side Effects: update UDB. # Return Value: none -sub check_if_article_has_closing_phrase +sub _change_thread_status { - my ($self, $id, $msg) = @_; + my ($self, $action, $thread_args, $state) = @_; my $curproc = $self->{ _curproc }; my $thread = $self->{ _thread_object }; my $article = $self->{ _article_object }; - my $rules = { - 'thank you' => 1, - }; - $msg->set_closing_phrase_rules($rules); - - # check it as "closed(auto)" if it looks like the end of thread. - # for example, we can find some phrases, "thank you.", "this - # problem is resolved.",... at the last of the article. - if ($msg->has_closing_phrase()) { - $thread->set_article_status($id, $state_auto_closed); - } -} - - -# Descriptions: check the content of message object. -# log and update UDB if needed. -# Arguments: OBJ($self) NUM($id) OBJ($msg) -# Side Effects: update UDB. -# Return Value: none -sub check_if_article_should_be_ignored -{ - my ($self, $id, $msg) = @_; + use Mail::Message::MH; + my $mh = new Mail::Message::MH; + my $range = $thread_args->{ range } || 'last:10'; + my $head_id = $thread_args->{ last_id }; + my $id_list = $mh->expand($range, 1, $head_id); + my $tail_id = $id_list->[ 0 ] || 1; - # check if this article should be ignored ? - # for example, "cvs source changes" may be ignored at some ML. - if (0) { - # $self->check_message_filter( file => filter_config_file ) ? + for my $id (@$id_list) { + $curproc->log("$action thread $id"); + $thread->set_thread_status($id, $state); } } -=head1 UTILITY FUNCTIONS - -=head2 open_thread_status($th_args) +=head1 PRINT STATUS OR SUMMARY -open thread. - -=head2 close_thread_status($th_args) +=head2 print_one_line_summary($thread_args) -close thread. +=head2 print_summary($thread_args) =cut -# Descriptions: open thread. +# Descriptions: print one line summary. # Arguments: OBJ($self) HASH_REF($thread_args) # Side Effects: none # Return Value: none -sub open_thread_status +sub print_one_line_summary { my ($self, $thread_args) = @_; + my $id = $thread_args->{ last_id } || 0; - $self->_change_thread_status("open", $thread_args, $state_open); + if ($id) { + $self->_print_summary("one_line_summary", $thread_args); + } } -# Descriptions: close thread. +# Descriptions: print summary. # Arguments: OBJ($self) HASH_REF($thread_args) # Side Effects: none # Return Value: none -sub close_thread_status +sub print_summary { my ($self, $thread_args) = @_; + my $id = $thread_args->{ last_id } || 0; - $self->_change_thread_status("close", $thread_args, $state_closed); + if ($id) { + $self->_print_summary("summary", $thread_args); + } } -# Descriptions: open/close thread with the specified range. -# Arguments: OBJ($self) STR($action) HASH_REF($thread_args) STR($state) -# Side Effects: update UDB. +# Descriptions: actual engine to print summary. +# $thread_args = { +# last_id => last (max) id of our target range, +# range => MH style range, +# } +# Arguments: OBJ($self) STR($fp) HASH_REF($thread_args) +# Side Effects: none # Return Value: none -sub _change_thread_status +sub _print_summary { - my ($self, $action, $thread_args, $state) = @_; + my ($self, $fp, $thread_args) = @_; my $curproc = $self->{ _curproc }; my $thread = $self->{ _thread_object }; my $article = $self->{ _article_object }; + my $queue = []; - use Mail::Message::MH; - my $mh = new Mail::Message::MH; - my $range = $thread_args->{ range } || 'last:10'; - my $head_id = $thread_args->{ last_id }; - my $id_list = $mh->expand($range, 1, $head_id); - my $tail_id = $id_list->[ 0 ] || 1; + # here we go. + my $summary = $thread->get_thread_data($thread_args); - for my $id (@$id_list) { - $curproc->log("$action thread $id"); - $thread->set_thread_status($id, $state); + THREAD: + for my $head_id (sort {$a <=> $b} keys %$summary) { + # firstly check thread status. + my $status = $thread->get_thread_status($head_id) || "open"; + next THREAD if $status eq $state_closed; + next THREAD if $status eq $state_auto_closed; + + my $list = $summary->{ $head_id } || []; + for my $id (@$list) { + my $article_path = $article->filepath($id); + + use FileHandle; + my $fh = new FileHandle $article_path; + if (defined $fh) { + use Mail::Message; + my $msg = Mail::Message->parse( { fd => $fh } ); + my $buf = $msg->$fp(); + my $q = { + cur_id => $id, + head_id => $head_id, + id_list => $list, + status => $status, + summary => $buf, + message => $msg, + }; + push(@$queue, $q); + } + else { + $curproc->logerror("no such file: $article_path"); + } + } + } + + my $pfp = $print_switch{ $print_mode }->{ summary }; + $self->$pfp($curproc, $queue); +} + + +=head2 print_list($thread_args) + +list up thread and the related information. + +=cut + + +# Descriptions: list up thread and the related information. +# $thread_args = { +# last_id => last (max) id of our target range, +# range => MH style range, +# } +# Arguments: OBJ($self) HASH_REF($thread_args) +# Side Effects: none +# Return Value: none +sub print_list +{ + my ($self, $thread_args) = @_; + my $curproc = $self->{ _curproc }; + my $thread = $self->{ _thread_object }; + my $article = $self->{ _article_object }; + my $summary = $thread->get_thread_data($thread_args); + my $queue = []; + + THREAD: + for my $head_id (sort {$a <=> $b} keys %$summary) { + my $status = $thread->get_thread_status($head_id) || "open"; + next THREAD if $status eq $state_closed; + next THREAD if $status eq $state_auto_closed; + + my $list = $summary->{ $head_id } || []; + my $q = { + head_id => $head_id, + id_list => $list, + status => $status, + }; + push(@$queue, $q); } + + my $pfp = $print_switch{ $print_mode }->{ list }; + $self->$pfp($curproc, $queue); } |
