1 # Copyright (C) 2013-2020 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # Used for generating Atom feeds for web-accessible mailing list archives.
5 package PublicInbox::Feed;
9 use PublicInbox::WwwAtomStream;
10 use PublicInbox::Smsg; # this loads w/o Search::Xapian
14 shift @{$ctx->{msgs}};
20 my $msgs = $ctx->{msgs} = recent_msgs($ctx);
21 return _no_thread() unless @$msgs;
22 PublicInbox::WwwAtomStream->response($ctx, 200, \&generate_i);
25 sub generate_thread_atom {
27 my $msgs = $ctx->{msgs} = $ctx->{-inbox}->over->get_thread($ctx->{mid});
28 return _no_thread() unless @$msgs;
29 PublicInbox::WwwAtomStream->response($ctx, 200, \&generate_i);
32 sub generate_html_index {
34 # if the 'r' query parameter is given, it is a legacy permalink
35 # which we must continue supporting:
37 my $ibx = $ctx->{-inbox};
38 if ($qp && !$qp->{r} && $ibx->over) {
39 return PublicInbox::View::index_topics($ctx);
42 my $env = $ctx->{env};
43 my $url = $ibx->base_url($env) . 'new.html';
44 my $qs = $env->{QUERY_STRING};
45 $url .= "?$qs" if $qs ne '';
46 [302, [ 'Location', $url, 'Content-Type', 'text/plain'],
47 [ "Redirecting to $url\n" ] ];
52 return $ctx->html_top if exists $ctx->{-html_tip};
53 my $msgs = $ctx->{msgs};
54 while (my $smsg = shift @$msgs) {
55 my $eml = $ctx->{-inbox}->smsg_eml($smsg) or next;
56 return PublicInbox::View::eml_entry($ctx, $smsg, $eml,
59 PublicInbox::View::pagination_footer($ctx, './new.html');
64 my $msgs = $ctx->{msgs} = recent_msgs($ctx);
66 return [404, ['Content-Type', 'text/plain'],
67 ["No messages, yet\n"] ];
69 $ctx->{-html_tip} = '<pre>';
72 PublicInbox::WwwStream::response($ctx, 200, \&new_html_i);
78 [404, ['Content-Type', 'text/plain'], ["No feed found for thread\n"]];
83 my $ibx = $ctx->{-inbox};
84 my $max = $ibx->{feedmax};
85 return PublicInbox::View::paginate_recent($ctx, $max) if $ibx->over;
87 # only for rare v1 inboxes which aren't indexed at all
90 my $addmsg = qr!^:000000 100644 \S+ (\S+) A\t${hex}{2}/${hex}{38}$!;
91 my $delmsg = qr!^:100644 000000 (\S+) \S+ D\t(${hex}{2}/${hex}{38})$!;
92 my $refhex = qr/(?:HEAD|${hex}{4,40})(?:~[0-9]+)?/;
94 # revision ranges may be specified
96 my $r = $qp->{r} if $qp;
97 if ($r && ($r =~ /\A(?:$refhex\.\.)?$refhex\z/o)) {
101 # get recent messages
102 # we could use git log -z, but, we already know ssoma will not
103 # leave us with filenames with spaces in them..
104 my $log = $ibx->git->popen(qw/log
105 --no-notes --no-color --raw -r
106 --no-abbrev --abbrev-commit/,
107 "--format=%H", $range);
108 my %deleted; # only an optimization at this point
113 while (defined(my $line = <$log>)) {
114 if ($line =~ /$addmsg/o) {
116 next if $deleted{$add}; # optimization-only
118 if (scalar(@oids) >= $max) {
122 } elsif ($line =~ /$delmsg/o) {
129 while (my $line = <$log>) {
130 if ($line =~ /^(${hex}{7,40})/) {
137 $ctx->{next_page} = "r=$last_commit" if $last_commit;
138 [ map { bless {blob => $_ }, 'PublicInbox::Smsg' } @oids ];