diff options
author | John Ankarström <john@ankarstrom.se> | 2021-05-10 15:08:10 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2021-05-10 15:09:53 +0200 |
commit | 9aa1e9f77fc7881bc3fd4d0fe3473a82a528af94 (patch) | |
tree | d03e2162139751b9a3aaf8cdab39ee2369e92b77 | |
parent | 93143f534ff971c8702c3f95a04a3f8e89d19cd5 (diff) | |
download | perlisdead-9aa1e9f77fc7881bc3fd4d0fe3473a82a528af94.tar.gz |
p5p: Decode non-ASCII headers
-rwxr-xr-x | run/p5p | 30 |
1 files changed, 19 insertions, 11 deletions
@@ -2,8 +2,9 @@ use strict; use warnings; -use Net::NNTP; +use Email::MIME::RFC2047::Decoder; use HTML::Entities; +use Net::NNTP; my @alt = ( { @@ -26,19 +27,26 @@ for my $alt (@alt) { my %f = %{$nntp->xhdr('From', [$last-10, $last])}; my %s = %{$nntp->xhdr('Subject', [$last-10, $last])}; - # TODO: Handle strings like "=?utf-8?Q?readers=E2=80=99_?=time" + 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} = $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'; - for ((reverse sort keys %d)[0..4]) { - $_ = encode_entities($_) for ($d{$_}, $f{$_}, $s{_}); - $f{$_} =~ s,@[^.]*\.,@<i>hidden</i>.,; - $s{$_} = '(no subject)' if not exists $s{$_}; - 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="$u">$s{$_}</a></div> +<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 } |