]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Feed.pm
feed: merge subjects regardless of "[PATCH vN]"
[public-inbox.git] / lib / PublicInbox / Feed.pm
index 51216aaa1c28943cf396fffeaaa9b9dace0770ee..a0f901ebd6fc586dd38f29dc694386dee72f991c 100644 (file)
@@ -9,7 +9,7 @@ use Date::Parse qw(strptime);
 use PublicInbox::Hval;
 use PublicInbox::GitCatFile;
 use PublicInbox::View;
-use PublicInbox::MID qw/mid_clean mid_compressed/;
+use PublicInbox::MID qw/mid_clean mid_compress/;
 use constant {
        DATEFMT => '%Y-%m-%dT%H:%M:%SZ', # atom standard
        MAX_PER_PAGE => 25, # this needs to be tunable
@@ -89,7 +89,12 @@ sub emit_html_index {
        $srch and $topics = [ [], {} ];
        my (undef, $last) = each_recent_blob($ctx, sub {
                my ($path, $commit, $ts, $u, $subj) = @_;
-               $state ||= [ undef, {}, $commit, 0 ];
+               $state ||= {
+                       ctx => $ctx,
+                       seen => {},
+                       first_commit => $commit,
+                       anchor_idx => 0,
+               };
 
                if ($srch) {
                        add_topic($git, $srch, $topics, $path, $ts, $u, $subj);
@@ -119,9 +124,8 @@ sub nav_footer {
        my $old_r = $cgi->param('r');
        my $head = '    ';
        my $next = '    ';
-       # $state = [ undef, {}, $first_commit, $last_anchor ];
-       my $first = $state->[2];
-       my $anchor = $state->[3];
+       my $first = $state->{first_commit};
+       my $anchor = $state->{anchor_idx};
 
        if ($last) {
                $next = qq!<a\nhref="?r=$last">next</a>!;
@@ -279,7 +283,7 @@ sub add_to_feed {
        my $type = index($title, '&') >= 0 ? "\ntype=\"html\"" : '';
 
        my $from = mime_header($header_obj, 'From') or return 0;
-       my @from = Email::Address->parse($from);
+       my @from = Email::Address->parse($from) or return 0;
        my $name = PublicInbox::Hval->new_oneline($from[0]->name)->as_html;
        my $email = $from[0]->address;
        $email = PublicInbox::Hval->new_oneline($email)->as_html;
@@ -328,14 +332,18 @@ sub add_topic {
                $subj = mime_header($header_obj, 'Subject');
        }
 
-       $subj = $srch->subject_normalized($subj);
-       if (++$subjs->{$subj} == 1) {
+       my $topic = $subj = $srch->subject_normalized($subj);
+
+       # kill "[PATCH v2]" etc. for summarization
+       $topic =~ s/\A\s*\[[^\]]+\]\s*//g;
+
+       if (++$subjs->{$topic} == 1) {
                unless ($header_obj) {
                        my $mime = do_cat_mail($git, $path) or return 0;
                        $header_obj = $mime->header_obj;
                }
                my $mid = $header_obj->header('Message-ID');
-               $mid = mid_compressed(mid_clean($mid));
+               $mid = mid_compress(mid_clean($mid));
                $u = $enc_utf8->decode($u);
                push @$order, [ $mid, $ts, $u, $subj ];
                return 1;