From 81eb1e5b5caaf03e34062487c382fa74a21fd7d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Mon, 10 May 2021 15:08:10 +0200 Subject: p5p: Decode non-ASCII headers --- run/p5p | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/run/p5p b/run/p5p index d0323a1..69fd6db 100755 --- a/run/p5p +++ b/run/p5p @@ -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,@[^.]*\.,@hidden.,; + + $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,@[^.]*\.,@hidden.,; - $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 < -
Date: $d{$_}
-
From: $f{$_}
- +
Date: $d{$id}
+
From: $f{$id}
+ HTML } -- cgit v1.2.3