aboutsummaryrefslogtreecommitdiff
path: root/run/p5p
blob: e645bba0d67fc1254aecbed3e11fa4d66482ad36 (plain)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/perl

use strict;
use warnings;
use Email::MIME::RFC2047::Decoder;
use HTML::Entities;
use Net::NNTP;

my @alt = (
	{
		server => 'nntp.perl.org',
		group => 'perl.perl5.porters',
		offset => 0
	},
	{
		server => 'news.gmane.io',
		group => 'gmane.comp.lang.perl.perl5.porters',
		offset => 77786
	},
);

for my $alt (@alt) {
	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 $decoder = Email::MIME::RFC2047::Decoder->new;

	for my $id ((reverse sort keys %d)[0..4]) {
		$d{$id} = encode_entities($d{$id});

		$f{$id} = $decoder->decode_text($f{$id});
		$f{$id} = encode_entities($f{$id});
		$f{$id} =~ s,@[^.]*\.,@<i>hidden</i>.,;

		$s{$id} = '(no subject)' if not exists $s{$id};
		$s{$id} =~ s/Re:=\?/Re: =?/; # fix encoding
		$s{$id} = $decoder->decode_text($s{$id});
		$s{$id} = encode_entities($s{$id});

		my $u = 'https://www.nntp.perl.org/group/perl.perl5.porters/0/0/msg' . ($id + $alt->{offset}) . '.html';

		print <<HTML;
<div class="entry">
<div class="date">Date: $d{$id}</div>
<div class="from">From: $f{$id}</div>
<div class="subject"><a href="$u">$s{$id}</a></div>
</div>
HTML
	}

	$nntp->quit;
	exit 0;
}
die "Cannot retrieve news: $!";