From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id EA2811FBC8 for ; Wed, 10 Jun 2020 07:07:28 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 52/82] imap: SEARCH: clamp results to the 50K UID range Date: Wed, 10 Jun 2020 07:04:49 +0000 Message-Id: <20200610070519.18252-53-e@yhbt.net> In-Reply-To: <20200610070519.18252-1-e@yhbt.net> References: <20200610070519.18252-1-e@yhbt.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: We won't support searching across mailboxes, just yet; but maybe in the future. --- lib/PublicInbox/IMAP.pm | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/lib/PublicInbox/IMAP.pm b/lib/PublicInbox/IMAP.pm index b24dfcd70b5..f9af530aa19 100644 --- a/lib/PublicInbox/IMAP.pm +++ b/lib/PublicInbox/IMAP.pm @@ -487,6 +487,14 @@ sub uid_fetch_cb { # called by git->cat_async via git_async_cat requeue_once($self); } +sub uid_clamp ($$$) { + my ($self, $beg, $end) = @_; + my $uid_min = $self->{uid_min} or return; + my $uid_end = $uid_min + UID_BLOCK - 1; + $$beg = $uid_min if $$beg < $uid_min; + $$end = $uid_end if $$end > $uid_end; +} + sub range_step ($$) { my ($self, $range_csv) = @_; my ($beg, $end, $range); @@ -501,6 +509,8 @@ sub range_step ($$) { } elsif ($range =~ /\A([0-9]+):\*\z/) { $beg = $1 + 0; $end = $self->{ibx}->mm->max // 0; + my $uid_end = ($self->{uid_min} // 1) - 1 + UID_BLOCK; + $end = $uid_end if $end > $uid_end; $beg = $end if $beg > $end; } elsif ($range =~ /\A[0-9]+\z/) { $beg = $end = $range + 0; @@ -508,11 +518,7 @@ sub range_step ($$) { } else { return 'BAD fetch range'; } - if (defined($range) && (my $uid_min = $self->{uid_min})) { - my $uid_end = $uid_min + UID_BLOCK - 1; - $beg = $uid_min if $beg < $uid_min; - $end = $uid_end if $end > $uid_end; - } + uid_clamp($self, \$beg, \$end) if defined($range); [ $beg, $end, $$range_csv ]; } @@ -804,17 +810,6 @@ sub parse_date ($) { # 02-Oct-1993 timegm(0, 0, 0, $dd, $mm, $yyyy); } -sub uid_search_all { # long_response - my ($self, $tag, $num) = @_; - my $uids = $self->{ibx}->mm->ids_after($num); - if (scalar(@$uids)) { - $self->msg_more(join(' ', '', @$uids)); - } else { - $self->write(\"\r\n$tag OK Search done\r\n"); - undef; - } -} - sub uid_search_uid_range { # long_response my ($self, $tag, $beg, $end) = @_; my $uids = $self->{ibx}->mm->msg_range($beg, $end, 'num'); @@ -944,12 +939,15 @@ sub cmd_uid_search ($$$;) { if (!scalar(keys %$q)) { $self->msg_more('* SEARCH'); - my $num = 0; - long_response($self, \&uid_search_all, $tag, \$num); + my $beg = $self->{uid_min} // 1; + my $end = $ibx->mm->max; + uid_clamp($self, \$beg, \$end); + long_response($self, \&uid_search_uid_range, $tag, \$beg, $end); } elsif (my $uid = $q->{uid}) { if ($uid =~ /\A([0-9]+):([0-9]+|\*)\z/s) { my ($beg, $end) = ($1, $2); $end = $ibx->mm->max if $end eq '*'; + uid_clamp($self, \$beg, \$end); $self->msg_more('* SEARCH'); long_response($self, \&uid_search_uid_range, $tag, \$beg, $end);