]> Sergey Matveev's repositories - public-inbox.git/commitdiff
view: cleaner Message-ID filtering for References
authorEric Wong <e@80x24.org>
Tue, 18 Aug 2015 01:08:28 +0000 (01:08 +0000)
committerEric Wong <e@80x24.org>
Tue, 18 Aug 2015 01:09:42 +0000 (01:09 +0000)
Avoid compiling a weird and potentially fragile regexp every
time and use the same logic as our search module to dedupe
References.

lib/PublicInbox/View.pm

index 6fbc366027d0c2d1eda266de34ca95c5d8ba4a2d..b0b8e140ee8111aad289296ce7f8c0d4160f1ce4 100644 (file)
@@ -395,10 +395,19 @@ sub headers_to_html_header {
 
        my $refs = $header_obj->header_raw('References');
        if ($refs) {
-               $refs =~ s/\s*\Q$irt\E\s*// if (defined $irt);
-               my @refs = ($refs =~ /<([^>]+)>/g);
+               # avoid redundant URLs wasting bandwidth
+               my %seen;
+               $seen{mid_clean($irt)} = 1 if defined $irt;
+               my @refs;
+               my @raw_refs = ($refs =~ /<([^>]+)>/g);
+               foreach my $ref (@raw_refs) {
+                       next if $seen{$ref};
+                       $seen{$ref} = 1;
+                       push @refs, linkify_ref($ref);
+               }
+
                if (@refs) {
-                       $rv .= 'References: '. linkify_refs(@refs) . "\n";
+                       $rv .= 'References: '. join(' ', @refs) . "\n";
                }
        }
 
@@ -466,13 +475,11 @@ sub html_footer {
        "$irt<a\nhref=\"" . ascii_html($href) . '">reply</a>' . $idx;
 }
 
-sub linkify_refs {
-       join(' ', map {
-               my $v = PublicInbox::Hval->new_msgid($_);
-               my $html = $v->as_html;
-               my $href = $v->as_href;
-               "&lt;<a\nhref=\"$href.html\">$html</a>&gt;";
-       } @_);
+sub linkify_ref {
+       my $v = PublicInbox::Hval->new_msgid($_[0]);
+       my $html = $v->as_html;
+       my $href = $v->as_href;
+       "&lt;<a\nhref=\"$href.html\">$html</a>&gt;";
 }
 
 sub anchor_for {