From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-2.9 required=3.0 tests=ALL_TRUSTED,BAYES_00, URIBL_BLOCKED shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: meta@public-inbox.org Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 7715563381C; Thu, 27 Aug 2015 04:34:06 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Cc: Eric Wong Subject: [PATCH 4/5] wire up to display non-suffixed Message-ID links Date: Thu, 27 Aug 2015 04:34:01 +0000 Message-Id: <1440650042-26176-5-git-send-email-e@80x24.org> In-Reply-To: <1440650042-26176-1-git-send-email-e@80x24.org> References: <1440650042-26176-1-git-send-email-e@80x24.org> List-Id: These URLs are preferable in case somebody decides to get cute and use a suffix we would've used to prevent others from linking to their message. The common /m/$MESSAGE_ID/ URLs are now 4 characters shorter so may fit better on terminals. --- lib/PublicInbox/Feed.pm | 4 ++-- lib/PublicInbox/View.pm | 40 ++++++++++++++++++++-------------------- lib/PublicInbox/WWW.pm | 7 +++++-- t/cgi.t | 28 ++++++++++++++-------------- t/feed.t | 2 +- t/plack.t | 4 ++-- t/view.t | 7 ++++--- 7 files changed, 48 insertions(+), 44 deletions(-) diff --git a/lib/PublicInbox/Feed.pm b/lib/PublicInbox/Feed.pm index d34978c..9e56747 100644 --- a/lib/PublicInbox/Feed.pm +++ b/lib/PublicInbox/Feed.pm @@ -273,7 +273,7 @@ sub add_to_feed { my $mid = $header_obj->header('Message-ID'); defined $mid or return 0; $mid = PublicInbox::Hval->new_msgid($mid); - my $href = $mid->as_href . '.html'; + my $href = $mid->as_href . '/'; my $content = PublicInbox::View->feed_entry($mime, $fullurl . $href); defined($content) or return 0; $mime = undef; @@ -362,7 +362,7 @@ sub dump_topics { $mid = PublicInbox::Hval->new($mid)->as_href; $subj = PublicInbox::Hval->new($subj)->as_html; $u = PublicInbox::Hval->new($u)->as_html; - $dst .= "\n$subj\n- "; + $dst .= "\n$subj\n- "; $ts = POSIX::strftime('%Y-%m-%d %H:%M', gmtime($ts)); if ($n == 1) { $dst .= "created by $u @ $ts UTC\n" diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm index 7412ccf..8ccdcfa 100644 --- a/lib/PublicInbox/View.pm +++ b/lib/PublicInbox/View.pm @@ -72,7 +72,7 @@ sub index_entry { $subj = PublicInbox::Hval->new_oneline($subj)->as_html; my $more = 'permalink'; my $root_anchor = $state->{root_anchor}; - my $path = $root_anchor ? '../' : ''; + my $path = $root_anchor ? '../../' : ''; my $href = $mid->as_href; my $irt = $header_obj->header('In-Reply-To'); my ($anchor_idx, $anchor, $t_anchor); @@ -84,7 +84,7 @@ sub index_entry { $t_anchor = ''; } if ($srch) { - $subj = "$subj"; + $subj = "$subj"; } if ($root_anchor && $root_anchor eq $id) { $subj = "$subj"; @@ -110,9 +110,9 @@ sub index_entry { $fh->write($rv .= "\n\n"); my ($fhref, $more_ref); - my $mhref = "${path}m/$href.html"; + my $mhref = "${path}m/$href/"; if ($level > 0) { - $fhref = "${path}f/$href.html"; + $fhref = "${path}f/$href/"; $more_ref = \$more; } # scan through all parts, looking for displayable text @@ -121,7 +121,7 @@ sub index_entry { }); $mime->body_set(''); - my $txt = "${path}m/$href.txt"; + my $txt = "${path}m/$href/raw"; $rv = "\n$more raw "; $rv .= html_footer($mime, 0, undef, $ctx); @@ -129,14 +129,14 @@ sub index_entry { unless (defined $anchor) { my $v = PublicInbox::Hval->new_msgid($irt); $v = $v->as_href; - $anchor = "${path}m/$v.html"; + $anchor = "${path}m/$v/"; $seen->{$anchor_idx} = $anchor; } $rv .= " parent"; } if ($srch) { - $rv .= " " . + $rv .= " " . "threadlink"; } @@ -173,9 +173,9 @@ sub emit_thread_html { my $final_anchor = $state->{anchor_idx}; my $next = ""; $next .= $final_anchor == 1 ? 'only message in' : 'end of'; - $next .= " thread, back to index\n"; - $mid = PublicInbox::Hval->new_msgid($mid)->as_href; - $next .= "download: mbox.gz\n\n"; + $next .= " thread, back to index\n"; + # $mid = PublicInbox::Hval->new_msgid($mid)->as_href; + $next .= "download: mbox.gz\n\n"; $fh->write("
" . PRE_WRAP . $next . $foot . ""); $fh->close; @@ -361,7 +361,7 @@ sub headers_to_html_header { } elsif ($h eq 'Subject') { $title[0] = $v->as_html; if ($srch) { - $rv .= "$h: "; + $rv .= "$h: "; $rv .= $v->as_html . "\n"; next; } @@ -371,8 +371,8 @@ sub headers_to_html_header { } $rv .= 'Message-ID: <' . $mid->as_html . '> '; - $mid_href = "../m/$mid_href" unless $full_pfx; - $rv .= "(raw)\n"; + my $raw_ref = $full_pfx ? 'raw' : "../../m/$mid_href/raw"; + $rv .= "(raw)\n"; my $irt = $header_obj->header('In-Reply-To'); if (defined $irt) { @@ -380,7 +380,7 @@ sub headers_to_html_header { my $html = $v->as_html; my $href = $v->as_href; $rv .= "In-Reply-To: <"; - $rv .= "$html>\n"; + $rv .= "$html>\n"; } my $refs = $header_obj->header('References'); @@ -437,12 +437,12 @@ sub html_footer { my $href = "mailto:$to?In-Reply-To=$irt&Cc=${cc}&Subject=$subj"; my $srch = $ctx->{srch} if $ctx; - my $idx = $standalone ? " index" : ''; + my $idx = $standalone ? " index" : ''; if ($idx && $srch) { $irt = $mime->header('In-Reply-To') || ''; $mid = mid_compress(mid_clean($mid)); my $t_anchor = length $irt ? T_ANCHOR : ''; - $idx = " ". + $idx = " ". "threadlink$idx"; my $res = $srch->get_followups($mid); if (my $c = $res->{total}) { @@ -461,7 +461,7 @@ sub html_footer { if ($irt) { $irt = PublicInbox::Hval->new_msgid($irt); $irt = $irt->as_href; - $irt = "parent "; + $irt = "parent "; } else { $irt = ' ' x length('parent '); } @@ -476,7 +476,7 @@ sub linkify_ref { my $v = PublicInbox::Hval->new_msgid($_[0]); my $html = $v->as_html; my $href = $v->as_href; - "<$html>"; + "<$html>"; } sub anchor_for { @@ -511,7 +511,7 @@ sub simple_dump { my $m = PublicInbox::Hval->new_msgid($mid); $f = PublicInbox::Hval->new($f); $d = PublicInbox::Hval->new($d); - $m = $m->as_href . '.html'; + $m = $m->as_href . '/'; $f = $f->as_html; $d = $d->as_html . ' UTC'; if (length($s) == 0) { @@ -592,7 +592,7 @@ sub missing_thread { my $title = 'Thread does not exist'; $cb->([404, ['Content-Type' => 'text/html']])->write(<$title
$title
-Return to index
+Return to index EOF } diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm index ca338fb..ceb34d6 100644 --- a/lib/PublicInbox/WWW.pm +++ b/lib/PublicInbox/WWW.pm @@ -56,6 +56,9 @@ sub run { invalid_list_mid(\%ctx, $1, $2) || get_full_html(\%ctx); # thread display + } elsif ($path_info =~ m!$LISTNAME_RE/t/(\S+)/\z!o) { + invalid_list_mid(\%ctx, $1, $2) || get_thread(\%ctx); + } elsif ($path_info =~ m!$LISTNAME_RE/t/(\S+)\.html\z!o) { invalid_list_mid(\%ctx, $1, $2) || get_thread(\%ctx); @@ -220,7 +223,7 @@ sub redirect_mid { if (lc($pfx) eq 't') { $anchor = '#u'; # is used to highlight in View.pm } - do_redirect($url . ".html$anchor"); + do_redirect($url . "/$anchor"); } # only hit when somebody tries to guess URLs manually: @@ -329,7 +332,7 @@ EOF sub msg_pfx { my ($ctx) = @_; my $href = PublicInbox::Hval::ascii_html(uri_escape_utf8($ctx->{mid})); - "../f/$href.html"; + "../../f/$href/"; } # /$LISTNAME/t/$MESSAGE_ID/mbox -> thread as mbox diff --git a/t/cgi.t b/t/cgi.t index 020dfe7..fc28ae3 100644 --- a/t/cgi.t +++ b/t/cgi.t @@ -152,27 +152,27 @@ EOF } local $ENV{GIT_DIR} = $maindir; - my $res = cgi_run("/test/m/slashy%2fasdf%40example.com.txt"); + my $res = cgi_run("/test/m/slashy%2fasdf%40example.com/raw"); like($res->{body}, qr/Message-Id: <\Q$slashy_mid\E>/, - "slashy mid.txt hit"); + "slashy mid raw hit"); - $res = cgi_run("/test/m/blahblah\@example.com.txt"); + $res = cgi_run("/test/m/blahblah\@example.com/raw"); like($res->{body}, qr/Message-Id: /, - "mid.txt hit"); - $res = cgi_run("/test/m/blahblah\@example.con.txt"); - like($res->{head}, qr/Status: 404 Not Found/, "mid.txt miss"); + "mid raw hit"); + $res = cgi_run("/test/m/blahblah\@example.con/raw"); + like($res->{head}, qr/Status: 404 Not Found/, "mid raw miss"); - $res = cgi_run("/test/m/blahblah\@example.com.html"); - like($res->{body}, qr/\A/, "mid.html hit"); + $res = cgi_run("/test/m/blahblah\@example.com/"); + like($res->{body}, qr/\A/, "mid html hit"); like($res->{head}, qr/Status: 200 OK/, "200 response"); - $res = cgi_run("/test/m/blahblah\@example.con.html"); - like($res->{head}, qr/Status: 404 Not Found/, "mid.html miss"); + $res = cgi_run("/test/m/blahblah\@example.con/"); + like($res->{head}, qr/Status: 404 Not Found/, "mid html miss"); - $res = cgi_run("/test/f/blahblah\@example.com.html"); - like($res->{body}, qr/\A/, "mid.html hit"); + $res = cgi_run("/test/f/blahblah\@example.com/"); + like($res->{body}, qr/\A/, "mid html"); like($res->{head}, qr/Status: 200 OK/, "200 response"); - $res = cgi_run("/test/f/blahblah\@example.con.html"); - like($res->{head}, qr/Status: 404 Not Found/, "mid.html miss"); + $res = cgi_run("/test/f/blahblah\@example.con/"); + like($res->{head}, qr/Status: 404 Not Found/, "mid html miss"); $res = cgi_run("/test/"); like($res->{body}, qr/slashy%2Fasdf%40example\.com/, diff --git a/t/feed.t b/t/feed.t index 6102e8a..a9955f0 100644 --- a/t/feed.t +++ b/t/feed.t @@ -77,7 +77,7 @@ EOF } unlike($feed, qr/drop me/, "long quoted text dropped"); - like($feed, qr!/f/\d%40example\.com\.html\b!, + like($feed, qr!/f/\d%40example\.com/#q!, "/f/ url generated for long quoted text"); like($feed, qr/inline me here/, "short quoted text kept"); like($feed, qr/keep me/, "unquoted text saved"); diff --git a/t/plack.t b/t/plack.t index ed41ab1..ee77291 100644 --- a/t/plack.t +++ b/t/plack.t @@ -88,7 +88,7 @@ EOF is(200, $res->code, 'success response received'); like($res->content, qr!href="\Q$atomurl\E"!, 'atom URL generated'); - like($res->content, qr!href="m/blah%40example\.com\.html"!, + like($res->content, qr!href="m/blah%40example\.com/"!, 'index generated'); }); @@ -98,7 +98,7 @@ EOF my $res = $cb->(GET($pfx . '/atom.xml')); is(200, $res->code, 'success response received for atom'); like($res->content, - qr!link\s+href="\Q$pfx\E/m/blah%40example\.com\.html"!s, + qr!link\s+href="\Q$pfx\E/m/blah%40example\.com/"!s, 'atom feed generated correct URL'); }); diff --git a/t/view.t b/t/view.t index 151fa77..77cf3a3 100644 --- a/t/view.t +++ b/t/view.t @@ -44,17 +44,18 @@ EOF my $html = PublicInbox::View::msg_html(undef, $mime); # ghetto tests - like($html, qr!]+><\/a>> Long and wordy/, "long quoted text is anchored"); # short page - my $pfx = "http://example.com/test/f"; + my $pfx = "../../f/hello%40example.com/"; $mime = Email::MIME->new($s); my $short = PublicInbox::View::msg_html(undef, $mime, $pfx); - like($short, qr!