]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/LeiXSearch.pm
lei q: support a bunch of curl(1) options
[public-inbox.git] / lib / PublicInbox / LeiXSearch.pm
index d32fe09afa5fe51414dab17b2235ab739bbcc0ae..defe5e67cc2c6e905e2e8d37da7978e9321cb3f5 100644 (file)
@@ -193,6 +193,7 @@ sub query_remote_mboxrd {
        my $dedupe = $lei->{dedupe} // die 'BUG: {dedupe} missing';
        $dedupe->prepare_dedupe;
        my @cmd = qw(curl -XPOST -sSf);
+       $opt->{torsocks} = 'false' if $opt->{'no-torsocks'};
        my $tor = $opt->{torsocks} //= 'auto';
        if ($tor eq 'auto' && substr($uri->host, -6) eq '.onion' &&
                        (($lei->{env}->{LD_PRELOAD}//'') !~ /torsocks/)) {
@@ -202,6 +203,18 @@ sub query_remote_mboxrd {
        }
        my $verbose = $opt->{verbose};
        push @cmd, '-v' if $verbose;
+       for my $o ($lei->curl_opt) {
+               $o =~ s/\|[a-z0-9]\b//i; # remove single char short option
+               if ($o =~ s/=[is]@\z//) {
+                       my $ary = $opt->{$o} or next;
+                       push @cmd, map { ("--$o", $_) } @$ary;
+               } elsif ($o =~ s/=[is]\z//) {
+                       my $val = $opt->{$o} // next;
+                       push @cmd, "--$o", $val;
+               } elsif ($opt->{$o}) {
+                       push @cmd, "--$o";
+               }
+       }
        push @cmd, $uri->as_string;
        $lei->err("# @cmd") if $verbose;
        $? = 0;
@@ -252,7 +265,14 @@ sub query_done { # EOF callback
        }
        $lei->{ovv}->ovv_end($lei);
        if ($has_l2m) { # close() calls LeiToMail reap_compress
-               close(delete($lei->{1})) if $lei->{1};
+               if (my $out = delete $lei->{old_1}) {
+                       if (my $mbout = $lei->{1}) {
+                               close($mbout) or return $lei->fail(<<"");
+Error closing $lei->{ovv}->{dst}: $!
+
+                       }
+                       $lei->{1} = $out;
+               }
                $lei->start_mua;
        }
        $lei->dclose;