+sub bad_http ($$;$) {
+ my ($lei, $url, $alt) = @_;
+ my $x = $alt ? "did you mean <$alt>?" : 'download and import manually';
+ $lei->fail("E: <$url> not recognized, $x");
+}
+
+sub prepare_http_input ($$$) {
+ my ($self, $lei, $url) = @_;
+ require URI;
+ require PublicInbox::MboxReader;
+ require PublicInbox::LeiCurl;
+ require IO::Uncompress::Gunzip;
+ $self->{curl} //= which('curl') or
+ return $lei->fail("curl missing for <$url>");
+ my $uri = URI->new($url);
+ my $path = $uri->path;
+ my %qf = $uri->query_form;
+ my @curl_opt;
+ if ($path =~ m!/(?:t\.mbox\.gz|all\.mbox\.gz)\z!) {
+ # OK
+ } elsif ($path =~ m!/raw\z!) {
+ push @curl_opt, '--compressed';
+ # convert search query to mboxrd request since they require POST
+ # this is only intended for PublicInbox::WWW, and will false-positive
+ # on many other search engines... oh well
+ } elsif (defined $qf{'q'}) {
+ $qf{x} = 'm';
+ $uri->query_form(\%qf);
+ push @curl_opt, '-d', '';
+ $$uri ne $url and $lei->qerr(<<"");
+# <$url> rewritten to <$$uri> with HTTP POST
+
+ # try to provide hints for /$INBOX/$MSGID/T/ and /$INBOX/
+ } elsif ($path =~ s!/[tT]/\z!/t.mbox.gz! ||
+ $path =~ s!/t\.atom\z!/t.mbox.gz! ||
+ $path =~ s!/([^/]+\@[^/]+)/\z!/$1/raw!) {
+ $uri->path($path);
+ return bad_http($lei, $url, $$uri);
+ } else {
+ return bad_http($lei, $url);
+ }
+ $self->{"-curl-$url"} = [ @curl_opt, $uri ]; # for handle_http_input
+}
+