diff options
author | John Ankarström <john@ankarstrom.se> | 2021-05-10 14:54:37 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2021-05-10 14:54:37 +0200 |
commit | ab494bed6040a91102e58684441319ef718277da (patch) | |
tree | b5cf1bdda0638d57f75638e72ff4e169fd0a42cb | |
parent | 3013d5e295035c8a1e98fe97d98e59b10d208c04 (diff) | |
download | perlisdead-ab494bed6040a91102e58684441319ef718277da.tar.gz |
p5p: Fix message IDs from Gmane
-rwxr-xr-x | run/p5p | 49 |
1 files changed, 28 insertions, 21 deletions
@@ -6,36 +6,43 @@ use Net::NNTP; use HTML::Entities; my @alt = ( - ['nntp.perl.org' => 'perl.perl5.porters'], - ['news.gmane.io' => 'gmane.comp.lang.perl.perl5.porters'], + { + server => 'nntp.perl.org', + group => 'perl.perl5.porters', + offset => 0 + }, + { + server => 'news.gmane.io', + group => 'gmane.comp.lang.perl.perl5.porters', + offset => 77786 + }, ); -my ($nntp, $count, $first, $last); for my $alt (@alt) { - $nntp = Net::NNTP->new($alt->[0], Timeout => 10) - or next; - ($count, $first, $last) = $nntp->group($alt->[1]); - last; -} -die "Cannot retrieve news: $!" if not $nntp; + my $nntp = Net::NNTP->new($alt->{server}, Timeout => 10) or next; + my ($count, $first, $last) = $nntp->group($alt->{group}); -my %d = %{$nntp->xhdr('Date', [$last-10, $last])}; -my %f = %{$nntp->xhdr('From', [$last-10, $last])}; -my %s = %{$nntp->xhdr('Subject', [$last-10, $last])}; + my %d = %{$nntp->xhdr('Date', [$last-10, $last])}; + my %f = %{$nntp->xhdr('From', [$last-10, $last])}; + my %s = %{$nntp->xhdr('Subject', [$last-10, $last])}; -# TODO: Escape potential HTML characters + # TODO: Handle strings like "=?utf-8?Q?readers=E2=80=99_?=time" -for ((reverse sort keys %d)[0..4]) { - $_ = encode_entities($_) for ($d{$_}, $f{$_}, $s{_}); - $f{$_} =~ s,@[^.]*\.,@<i>hidden</i>.,; - my $l = "https://www.nntp.perl.org/group/perl.perl5.porters/0/0/msg$_.html"; - print <<HTML; + for ((reverse sort keys %d)[0..4]) { + $_ = encode_entities($_) for ($d{$_}, $f{$_}, $s{_}); + $f{$_} =~ s,@[^.]*\.,@<i>hidden</i>.,; + my $n = $_ + $alt->{offset}; + my $u = "https://www.nntp.perl.org/group/perl.perl5.porters/0/0/msg$n.html"; + print <<HTML; <div class="entry"> <div class="date">Date: $d{$_}</div> <div class="from">From: $f{$_}</div> -<div class="subject"><a href="$l">$s{$_}</a></div> +<div class="subject"><a href="$u">$s{$_}</a></div> </div> HTML -} + } -$nntp->quit; + $nntp->quit; + exit 0; +} +die "Cannot retrieve news: $!"; |