]> Sergey Matveev's repositories - public-inbox.git/commitdiff
search: common Subject: normalization for Re: prefixes
authorEric Wong <e@80x24.org>
Tue, 18 Aug 2015 01:11:05 +0000 (01:11 +0000)
committerEric Wong <e@80x24.org>
Tue, 18 Aug 2015 01:11:59 +0000 (01:11 +0000)
Drop German ("Aw:") support since it's non-standard and
is not supported by Mail::Thread and non-English prefixes
are more likely to conflict with prefixes used in Free Software
development where ("subsection:") prefixes are common and English is the
common language.

Anyways we don't filter "Vs: " (Finnish) or "Sv: "
(Norwegian, Swedish, Danish, Icelandic), either.

ref:
https://en.wikipedia.org/wiki/RE_(e-mail)#Abbreviations_in_other_languages

lib/PublicInbox/Search.pm
lib/PublicInbox/View.pm

index db86301d8794e8bee3e83930724448983bc6247e..6a05ce7a4e72e5ff2303caf04bdb1c6eb7354869 100644 (file)
@@ -10,6 +10,10 @@ require PublicInbox::View;
 use Email::MIME;
 use PublicInbox::MID qw/mid_clean mid_compressed/;
 
+# This is English-only, everything else is non-standard and may be confused as
+# a prefix common in patch emails
+our $REPLY_RE = qr/^re:\s+/i;
+
 use constant {
        TS => 0,
        # SCHEMA_VERSION history
@@ -490,7 +494,7 @@ sub subject_path {
 
        $subj =~ s/\A\s+//;
        $subj =~ s/\s+\z//;
-       $subj =~ s/^(?:re|aw):\s*//i; # remove reply prefix (aw: German)
+       $subj =~ s/$REPLY_RE//igo; # remove reply prefix
        $subj =~ s![^a-zA-Z0-9_\.~/\-]+!_!g;
        lc($subj);
 }
index b0b8e140ee8111aad289296ce7f8c0d4160f1ce4..7122a38ded651c2e8e12979ffe1231ae8bf471bc 100644 (file)
@@ -457,6 +457,7 @@ sub html_footer {
                if (my $c = $res->{count}) {
                        $c = $c == 1 ? '1 followup' : "$c followups";
                        $idx .= "\n$c:\n";
+                       $res->{srch} = $srch;
                        thread_followups(\$idx, $mime, $res);
                } else {
                        $idx .= "\n(no followups, yet)\n";
@@ -493,13 +494,14 @@ sub anchor_for {
 
 sub simple_dump {
        my ($dst, $root, $node, $level) = @_;
+       # $root = [ Root Message-ID, \%seen, $srch ];
        my $pfx = '  ' x $level;
        $$dst .= $pfx;
        if (my $x = $node->message) {
                my $mid = $x->header('Message-ID');
                if ($root->[0] ne $mid) {
                        my $s = $x->header('Subject');
-                       my $h = hash_subj($s);
+                       my $h = $root->[2]->subject_path($s);
                        if ($root->[1]->{$h}) {
                                $s = '';
                        } else {
@@ -525,15 +527,6 @@ sub simple_dump {
        simple_dump($dst, $root, $node->next, $level) if $node->next;
 }
 
-sub hash_subj {
-       my ($subj) = @_;
-       $subj =~ s/\A\s+//;
-       $subj =~ s/\s+\z//;
-       $subj =~ s/^(?:re|aw):\s*//i; # remove reply prefix (aw: German)
-       $subj =~ s/\s+/ /;
-       Digest::SHA::sha1($subj);
-}
-
 sub thread_followups {
        my ($dst, $root, $res) = @_;
        my @msgs = map { $_->mini_mime } @{$res->{msgs}};
@@ -542,8 +535,10 @@ sub thread_followups {
        my $th = PublicInbox::Thread->new($root, @msgs);
        $th->thread;
        $th->order(*PublicInbox::Thread::sort_ts);
-       $root = [ $root->header('Message-ID'),
-                 { hash_subj($root->header('Subject')) => 1 } ];
+       my $srch = $res->{srch};
+       my $subj = $srch->subject_path($root->header('Subject'));
+       my %seen = ($subj => 1);
+       $root = [ $root->header('Message-ID'), \%seen, $srch ];
        simple_dump($dst, $root, $_, 0) for $th->rootset;
 }