]> Sergey Matveev's repositories - public-inbox.git/commitdiff
cgi: wire up HTML pages for messages
authorEric Wong <e@80x24.org>
Thu, 10 Apr 2014 23:33:48 +0000 (23:33 +0000)
committerEric Wong <e@80x24.org>
Fri, 11 Apr 2014 22:23:58 +0000 (22:23 +0000)
These need better tests and verification, but it's something
for now.

public-inbox-cgi
t/cgi.t

index e4e2e3a2168b7e189641ee60d8f3ed613771b3aa..6a6f31e23ef81acd8045001190a3e7991c012290 100755 (executable)
@@ -69,6 +69,13 @@ sub main {
                invalid_list_mid(\%ctx, $1, $2) || get_mid_html(\%ctx, $cgi);
        } elsif ($path_info =~ m!$LISTNAME_RE/m/(\S+)\z!o) {
                redirect_mid_html($cgi, $1, $2);
+
+       # full-message page
+       } elsif ($path_info =~ m!$LISTNAME_RE/f/(\S+)\.html\z!o) {
+               invalid_list_mid(\%ctx, $1, $2) || get_full_html(\%ctx, $cgi);
+       } elsif ($path_info =~ m!$LISTNAME_RE/f/(\S+)\z!o) {
+               redirect_mid_html($cgi, $1, $2);
+
        } else {
                r404();
        }
@@ -148,6 +155,32 @@ sub get_mid_txt {
        $x ? [ "200 OK", {'Content-Type' => 'text/plain'}, $$x ] : r404();
 }
 
+# /$LISTNAME/m/$MESSAGE_ID.html                   -> HTML content (short quotes)
+sub get_mid_html {
+       my ($ctx, $cgi) = @_;
+       my $x = mid2blob($ctx);
+       return r404() unless $x;
+
+       my $pfx = $cgi->self_url;
+       $pfx =~ s!/m/.+\z!/!; # FIXME: this is not robust
+
+       require PublicInbox::View;
+       require Email::MIME;
+       [ "200 OK", {'Content-Type' => 'text/html'},
+               PublicInbox::View->as_html(Email::MIME->new($$x), $pfx)];
+}
+
+# /$LISTNAME/f/$MESSAGE_ID.html                   -> HTML content (fullquotes)
+sub get_full_html {
+       my ($ctx, $cgi) = @_;
+       my $x = mid2blob($ctx);
+       return r404() unless $x;
+       require PublicInbox::View;
+       require Email::MIME;
+       [ "200 OK", {'Content-Type' => 'text/html'},
+               PublicInbox::View->as_html(Email::MIME->new($$x))];
+}
+
 # only used for CGI and static file generation modes
 sub set_binmode {
        my ($headers) = @_;
diff --git a/t/cgi.t b/t/cgi.t
index 2c4c824c500543827f05b461452497ea3564aa16..afbe604fb3bf22d7cf4961adef8be363620766bc 100644 (file)
--- a/t/cgi.t
+++ b/t/cgi.t
@@ -133,6 +133,18 @@ EOF
                "mid.txt hit");
        $res = cgi_run("/test/m/blahblah\@example.con.txt");
        like($res->{head}, qr/Status: 404 Not Found/, "mid.txt miss");
+
+       $res = cgi_run("/test/m/blahblah\@example.com.html");
+       like($res->{body}, qr/\A<html>/, "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/f/blahblah\@example.com.html");
+       like($res->{body}, qr/\A<html>/, "mid.html hit");
+       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");
 }
 
 done_testing();