Here's an out of context snippet from a newsreader I wrote in wx (it's still not finished... ) that seems to thread as well as my regular newsreader. You can also see what my commenting looks like in the real world.
Skimming over JWZ's document, I have latched onto the "references" bit, ignoring the In-Reply-To altogether.
If you're interested in the full source, please /msg me -- the caveat (and reason why it hasn't been posted before) is that the reader itself is rather incomplete -- it retrieves, sorts & displays them, but doesn't store messages or message pointers.
# sorting by oldest first seems to give the best chance for accurate m
+essage threading.
# I apologize for the nasty parens nesting scheme as well.
foreach (sort {
Date_Cmp ( $messages{$a}{"date"}, $messages{$b
+}{"date"})
} keys %messages
)
{
my $ref = $messages{$_}{"references"};
print STDERR "Checking $_ for references -- $ref --\n";
# getrefs runs through all the messages in placed,
# looking for references within the current message
my $childof=get_refs($ref, \%placed);
#
# if the current message is a child of another,
# nest it to that messages' node, otherwise place as a c
+hild of
# the newsgroup node.
#
# In either case, we add it to the list of messages we'v
+e 'placed'.
# 'placed' is a bad analogy, and should be replaced.
if ($childof){
$placed{$_}=$this->AppendItem ($placed{$childof}, $_."
+ ".$messages{$_}{"subject"});
} else {
$placed {$_}=$this->AppendItem ($item,$_." ".$messages
+{$_}{"subject"});
}
print STDERR "I have ". keys (%placed) . " items\n";
}
and the sub get_refs,
sub get_refs {
my $msg_refs = shift;
my $msg_list = shift;
my @parent_refs =reverse split /\s+/, $msg_refs;
foreach my $aref(@parent_refs) {
print STDERR "\tChecking $msg_refs\n";
if (exists $$msg_list{$aref}){
print STDERR "$_ is child of $aref\n";
return $aref;
}
}
return undef;
}