1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
#!/usr/bin/perl
use strict;
use warnings;
use Net::NNTP;
use HTML::Entities;
my @alt = (
['nntp.perl.org' => 'perl.perl5.porters'],
['news.gmane.io' => 'gmane.comp.lang.perl.perl5.porters'],
);
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 %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
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;
<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>
HTML
}
$nntp->quit;
|