#!/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,@[^.]*\.,@hidden.,; $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 <
Date: $d{$id}
From: $f{$id}
$s{$id}
HTML } $nntp->quit; exit 0; } die "Cannot retrieve news: $!";