lib/PublicInbox/ExtMsg.pm | 19 ++++++++----------- lib/PublicInbox/Hval.pm | 7 ++----- lib/PublicInbox/Linkify.pm | 9 ++++----- lib/PublicInbox/Reply.pm | 6 +++--- lib/PublicInbox/SearchView.pm | 4 ++-- lib/PublicInbox/View.pm | 51 +++++++++++++++++++++++---------------------------- lib/PublicInbox/WwwAtomStream.pm | 9 ++++----- t/psgi_bad_mids.t | 9 +++++++-- diff --git a/lib/PublicInbox/ExtMsg.pm b/lib/PublicInbox/ExtMsg.pm index c48c2db49490d22b9481d717a713401196a54573..44884ad286354aa9a95841fb5b3b171df0d19cc2 100644 --- a/lib/PublicInbox/ExtMsg.pm +++ b/lib/PublicInbox/ExtMsg.pm @@ -8,7 +8,7 @@ # sites. package PublicInbox::ExtMsg; use strict; use warnings; -use PublicInbox::Hval qw(ascii_html prurl); +use PublicInbox::Hval qw(ascii_html prurl mid_href); use PublicInbox::WwwStream; our $MIN_PARTIAL_LEN = 16; @@ -129,9 +129,8 @@ } } my $code = 404; - my $h = PublicInbox::Hval->new_msgid($mid); - my $href = $h->{href}; - my $html = $h->as_html; + my $href = mid_href($mid); + my $html = ascii_html($mid); my $title = "<$html> not found"; my $s = "
Message-ID <$html>\nnot found\n";
if ($n_partial) {
@@ -145,10 +144,9 @@ my ($ibx, $res) = @$pair;
my $env = $ctx->{env} if $ibx->{name} eq $cur_name;
my $u = $ibx->base_url($env) or next;
foreach my $m (@$res) {
- my $p = PublicInbox::Hval->new_msgid($m);
- my $r = $p->{href};
- my $t = $p->as_html;
- $s .= qq{$u$t/\n};
+ my $href = mid_href($m);
+ my $html = ascii_html($m);
+ $s .= qq{$u$html/\n};
}
}
}
@@ -183,9 +181,8 @@ }
sub exact {
my ($ctx, $found, $mid) = @_;
- my $h = PublicInbox::Hval->new_msgid($mid);
- my $href = $h->{href};
- my $html = $h->as_html;
+ my $href = mid_href($mid);
+ my $html = ascii_html($mid);
my $title = "<$html> found in ";
my $end = @$found == 1 ? 'another inbox' : 'other inboxes';
$ctx->{-title_html} = $title . $end;
diff --git a/lib/PublicInbox/Hval.pm b/lib/PublicInbox/Hval.pm
index 2e883f810023f2a0bb3314e418437cca469365e0..40c97da478fe6685810afa1c2c866945b70ef7a3 100644
--- a/lib/PublicInbox/Hval.pm
+++ b/lib/PublicInbox/Hval.pm
@@ -10,7 +10,7 @@ use Encode qw(find_encoding);
use PublicInbox::MID qw/mid_clean mid_escape/;
use base qw/Exporter/;
our @EXPORT_OK = qw/ascii_html obfuscate_addrs to_filename src_escape
- to_attr prurl/;
+ to_attr prurl mid_href/;
my $enc_ascii = find_encoding('us-ascii');
# safe-ish acceptable filename pattern for portability
@@ -27,10 +27,7 @@ href => defined $href ? $href : $raw,
}, $class;
}
-sub new_msgid {
- my ($class, $msgid) = @_;
- $class->new($msgid, mid_escape($msgid));
-}
+sub mid_href { ascii_html(mid_escape($_[0])) }
# some of these overrides are standard C escapes so they're
# easy-to-understand when rendered.
diff --git a/lib/PublicInbox/Linkify.pm b/lib/PublicInbox/Linkify.pm
index d176a7cc8eefca89eaa2d549554c7a33a5bd52d7..2bd8f64a142b1152ea1acf96f989ffa4dbd3c621 100644
--- a/lib/PublicInbox/Linkify.pm
+++ b/lib/PublicInbox/Linkify.pm
@@ -13,7 +13,7 @@ package PublicInbox::Linkify;
use strict;
use warnings;
use Digest::SHA qw/sha1_hex/;
-use PublicInbox::Hval qw(ascii_html);
+use PublicInbox::Hval qw(ascii_html mid_href);
my $SALT = rand;
my $LINK_RE = qr{([\('!])?\b((?:ftps?|https?|nntps?|gopher)://
@@ -94,10 +94,9 @@ # with $pfx being the URL prefix
sub linkify_mids {
my ($self, $pfx, $str, $raw) = @_;
$$str =~ s!<([^>]+)>!
- my $msgid = PublicInbox::Hval->new_msgid($1);
- my $html = $msgid->as_html;
- my $href = $msgid->{href};
- $href = ascii_html($href); # for IDN
+ my $mid = $1;
+ my $html = ascii_html($mid);
+ my $href = mid_href($mid);
# salt this, as this could be exploited to show
# links in the HTML which don't show up in the raw mail.
diff --git a/lib/PublicInbox/Reply.pm b/lib/PublicInbox/Reply.pm
index edeb1ac2189b6e6945e958783cbe2e5242fb226d..5058ff8c39b51edd13a5bd2a833c6d9f99ce5480 100644
--- a/lib/PublicInbox/Reply.pm
+++ b/lib/PublicInbox/Reply.pm
@@ -6,9 +6,9 @@ package PublicInbox::Reply;
use strict;
use warnings;
use URI::Escape qw/uri_escape_utf8/;
-use PublicInbox::Hval qw/ascii_html obfuscate_addrs/;
+use PublicInbox::Hval qw(ascii_html obfuscate_addrs mid_href);
use PublicInbox::Address;
-use PublicInbox::MID qw/mid_clean mid_escape/;
+use PublicInbox::MID qw(mid_clean);
sub squote_maybe ($) {
my ($val) = @_;
@@ -76,7 +76,7 @@ my $subj = $hdr->header('Subject') || '';
$subj = "Re: $subj" unless $subj =~ /\bRe:/i;
my $mid = $hdr->header_raw('Message-ID');
push @arg, '--in-reply-to='.squote_maybe(mid_clean($mid));
- my $irt = mid_escape($mid);
+ my $irt = mid_href($mid);
delete $cc->{$to};
if ($obfs) {
my $arg_to = $to;
diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm
index 7e508bb7764238bfcc4958ecfcc131c08108f514..9b67b045c16eb0af177bb5f833dc5239f7bd0507 100644
--- a/lib/PublicInbox/SearchView.pm
+++ b/lib/PublicInbox/SearchView.pm
@@ -7,7 +7,7 @@ use strict;
use warnings;
use URI::Escape qw(uri_unescape uri_escape);
use PublicInbox::SearchMsg;
-use PublicInbox::Hval qw/ascii_html obfuscate_addrs/;
+use PublicInbox::Hval qw(ascii_html obfuscate_addrs mid_href);
use PublicInbox::View;
use PublicInbox::WwwAtomStream;
use PublicInbox::SearchThread;
@@ -115,7 +115,7 @@ obfuscate_addrs($obfs_ibx, $s);
obfuscate_addrs($obfs_ibx, $f);
}
my $date = PublicInbox::View::fmt_ts($smsg->{ds});
- my $mid = PublicInbox::Hval->new_msgid($smsg->{mid})->{href};
+ my $mid = mid_href($smsg->{mid});
$s = '(no subject)' if $s eq '';
$$res .= qq{$rank. }.
$s . "\n";
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index d4bfa62d660e529d04ac12f50db926cf98457263..14b7d81d619a85cb45455334c71abcd9c08d49f5 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -8,9 +8,9 @@ use strict;
use warnings;
use bytes (); # only for bytes::length
use PublicInbox::MsgTime qw(msg_datestamp);
-use PublicInbox::Hval qw(ascii_html obfuscate_addrs prurl);
+use PublicInbox::Hval qw(ascii_html obfuscate_addrs prurl mid_href);
use PublicInbox::Linkify;
-use PublicInbox::MID qw/id_compress mid_escape mids mids_for_index references/;
+use PublicInbox::MID qw/id_compress mids mids_for_index references/;
use PublicInbox::MsgIter;
use PublicInbox::Address;
use PublicInbox::WwwStream;
@@ -29,7 +29,7 @@ my ($nr, $ctx) = @_;
my $more = $ctx->{more};
if ($nr == 1) {
# $more cannot be true w/o $smsg being defined:
- $ctx->{mhref} = $more ? '../'.mid_escape($ctx->{smsg}->mid).'/'
+ $ctx->{mhref} = $more ? '../'.mid_href($ctx->{smsg}->{mid}).'/'
: '';
multipart_text_as_html(delete $ctx->{mime}, $ctx);
${delete $ctx->{obuf}} .= '