- my ($git, $path) = @_;
- my $mime = eval {
- my $str = $git->cat_file("HEAD:$path");
- Email::MIME->new($str);
- };
- $@ ? undef : $mime;
-}
-
-# accumulate recent topics if search is supported
-sub add_topic {
- my ($git, $srch, $topics, $path, $ts, $u, $subj) = @_;
- my ($order, $subjs) = @$topics;
- my $header_obj;
-
- # legacy ssoma did not set commit titles based on Subject
- $subj = $enc_utf8->decode($subj);
- if ($subj eq 'mda') {
- my $mime = do_cat_mail($git, $path) or return 0;
- $header_obj = $mime->header_obj;
- $subj = mime_header($header_obj, 'Subject');
- }
-
- 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_compress(mid_clean($mid));
- $u = $enc_utf8->decode($u);
- push @$order, [ $mid, $ts, $u, $subj, $topic ];
- return 1;
- }
- 0; # old topic, continue going
-}
-
-sub dump_topics {
- my ($topics) = @_;
- my ($order, $subjs) = @$topics;
- my $dst = '';
- $dst .= "\n[No recent topics]" unless (scalar @$order);
- while (defined(my $info = shift @$order)) {
- my ($mid, $ts, $u, $subj, $topic) = @$info;
- my $n = delete $subjs->{$topic};
- $mid = PublicInbox::Hval->new($mid)->as_href;
- $subj = PublicInbox::Hval->new($subj)->as_html;
- $u = PublicInbox::Hval->new($u)->as_html;
- $dst .= "\n<a\nhref=\"t/$mid/#u\"><b>$subj</b></a>\n- ";
- $ts = strftime('%Y-%m-%d %H:%M', gmtime($ts));
- if ($n == 1) {
- $dst .= "created by $u @ $ts UTC\n"
- } else {
- # $n isn't the total number of posts on the topic,
- # just the number of posts in the current "git log"
- # window, so leave it unlabeled
- $dst .= "updated by $u @ $ts UTC ($n)\n"
- }
- }
- $dst .= '</pre>'