]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/WwwText.pm
www: allow html_oneshot to take an array arg
[public-inbox.git] / lib / PublicInbox / WwwText.pm
index 211ee8c928e7f74bd10bb39df4c6dbf7c3a0279f..3f840c447fdf37c3dc3cec8eae518840524d1a76 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2016-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 
 # used for displaying help texts and other non-mail content
@@ -38,11 +38,7 @@ sub get_text {
        }
        my $env = $ctx->{env};
        if ($raw) {
-               if ($code == 200) {
-                       my $gzf = gzf_maybe($hdr, $env);
-                       $txt = $gzf->translate($txt);
-                       $txt .= $gzf->zflush;
-               }
+               $txt = gzf_maybe($hdr, $env)->zflush($txt) if $code == 200;
                $hdr->[3] = length($txt);
                return [ $code, $hdr, [ $txt ] ]
        }
@@ -71,7 +67,10 @@ sub get_text {
                $txt = ascii_html($txt);
        }
        $txt = '<pre>' . $l->linkify_2($txt) . '</pre>';
-       PublicInbox::WwwStream::html_oneshot($ctx, $code, \$txt);
+       $txt =~ s!\bPOP3\b!<a\nid=pop3>POP3</a>!;
+       $txt =~ s!\b(Newsgroups?)\b!<a\nid=nntp>$1</a>!;
+       $txt =~ s!\bIMAP\b!<a\nid=imap>IMAP</a>!;
+       PublicInbox::WwwStream::html_oneshot($ctx, $code, $txt);
 }
 
 sub _srch_prefix ($$) {
@@ -247,20 +246,12 @@ sub coderepos_raw ($$) {
        my ($ctx, $top_url) = @_;
        my $cr = $ctx->{ibx}->{coderepo} // return ();
        my $cfg = $ctx->{www}->{pi_cfg};
-       my @ret;
+       my @ret = ('Code repositories for project(s) associated with this '.
+               $ctx->{ibx}->thing_type . "\n");
        for my $cr_name (@$cr) {
-               $ret[0] //= do {
-                       my $thing = $ctx->{ibx}->can('cloneurl') ?
-                               'public inbox' : 'external index';
-                       <<EOF;
-Code repositories for project(s) associated with this $thing
-EOF
-               };
                my $urls = $cfg->get_all("coderepo.$cr_name.cgiturl");
                if ($urls) {
                        for (@$urls) {
-                               # relative or absolute URL?, prefix relative
-                               # "foo.git" with appropriate number of "../"
                                my $u = m!\A(?:[a-z\+]+:)?//!i ? $_ :
                                        $top_url.$_;
                                $ret[0] .= "\n\t" . prurl($ctx->{env}, $u);
@@ -272,25 +263,41 @@ EOF
        @ret; # may be empty, this sub is called as an arg for join()
 }
 
-sub _add_imap_nntp_urls ($$) {
+sub _add_non_http_urls ($$) {
        my ($ctx, $txt) = @_;
        $ctx->{ibx}->can('nntp_url') or return; # TODO extindex can have IMAP
        my $urls = $ctx->{ibx}->imap_url($ctx);
        if (@$urls) {
-               $$txt .= "\nIMAP subfolder(s) are available under:";
-               $$txt .= "\n  " . join("\n  ", @$urls);
+               $urls = join("\n  ", @$urls);
+               $urls =~ s!://([^/@]+)/!://;AUTH=ANONYMOUS\@$1/!sg;
                $$txt .= <<EOM
 
+IMAP subfolder(s) are available under:
+  $urls
   # each subfolder (starting with `0') holds 50K messages at most
 EOM
        }
-       $urls = $ctx->{ibx}->imap_url($ctx);
+       $urls = $ctx->{ibx}->nntp_url($ctx);
        if (@$urls) {
-               $$txt .= "\n";
-               $$txt .= @$urls == 1 ? 'Newsgroup' : 'Newsgroups are';
+               $$txt .= @$urls == 1 ? "\nNewsgroup" : "\nNewsgroups are";
                $$txt .= ' available over NNTP:';
                $$txt .= "\n  " . join("\n  ", @$urls) . "\n";
        }
+       $urls = $ctx->{ibx}->pop3_url($ctx);
+       if (@$urls) {
+               $urls = join("\n  ", @$urls);
+               $$txt .= <<EOM;
+
+POP3 access is available:
+  $urls
+
+The POP3 password is: anonymous
+The POP3 username is: \$(uuidgen)\@$ctx->{ibx}->{newsgroup}
+where \$(uuidgen) in the output of the `uuidgen' command on your system.
+The UUID in the username functions as a private cookie (don't share it).
+Idle accounts will expire periodically.
+EOM
+       }
 }
 
 sub _add_onion_note ($) {
@@ -379,7 +386,7 @@ EOM
 
 Example config snippet for mirrors: $cfg_link
 EOF
-       _add_imap_nntp_urls($ctx, $txt);
+       _add_non_http_urls($ctx, $txt);
        _add_onion_note($txt);
 
        my $code_url = prurl($ctx->{env}, $PublicInbox::WwwStream::CODE_URL);
@@ -508,7 +515,7 @@ message threading
 EOF
        } # $over
 
-       _add_imap_nntp_urls($ctx, \(my $note = ''));
+       _add_non_http_urls($ctx, \(my $note = ''));
        $note and $note =~ s/^/  /gms and $$txt .= <<EOF;
 additional protocols
 --------------------