aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-05-10 15:08:10 +0200
committerJohn Ankarström <john@ankarstrom.se>2021-05-10 15:08:10 +0200
commit81eb1e5b5caaf03e34062487c382fa74a21fd7d5 (patch)
tree01ecf6dfad08d0615e1701ffee273902752e0c38
parent93143f534ff971c8702c3f95a04a3f8e89d19cd5 (diff)
downloadperlisdead-81eb1e5b5caaf03e34062487c382fa74a21fd7d5.tar.gz
p5p: Decode non-ASCII headers
-rwxr-xr-xrun/p5p30
1 files 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,@[^.]*\.,@<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
}