From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 588BE1F4BE; Wed, 23 Oct 2024 09:30:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1729675805; bh=RfdGmSb3QCSeuSiEo3hiCzEiYCpWG2B76/M+eagR2gk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=IWht29eTFzrRTUEZ0sOnotAXCl6wbUrfjlicYWcFjuyYqvmjDiRtrw+clKmyFGTuy n5NDtCzREMc6YL+IR1+px5WbAOJd3zxf0pwGJdkF1a3LSWN2Z7DzX5HiEkpwPaI3IC XLo7eMKDYNeGYL3aDfO5HD/DirhCsjSnuh0XMMcc= Date: Wed, 23 Oct 2024 09:30:05 +0000 From: Eric Wong To: Augusto Stoffel Cc: meta@public-inbox.org Subject: [PATCH] imap: allow bare `*' in range Message-ID: <20241023093005.M99868@dcvr> References: <87jzdzguml.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <87jzdzguml.fsf@gmail.com> List-Id: Augusto Stoffel wrote: > The following request querying the latest message id fails on > public-inbox.org > > curl 'imaps://:@public-inbox.org/inbox.comp.mail.public-inbox.meta.0'\ > -X 'FETCH * (UID)' > > It works on other IMAP servers and AFAICT is allowed by the protocol > spec. > > Subject: Re: Bug in FETCH request? Yup, that's a bug, fix below (deployed to public-inbox.org) Thanks for reporting it since I've been stuck on tougher data design problems :x > This on the other hand works, but you need to choose a high enough > number... > > curl 'imaps://:@public-inbox.org/inbox.comp.mail.public-inbox.meta.0'\ > -X 'FETCH 999999:* (UID)' Right, IIRC that was explicitly in a RFC 3501 example, whereas a bare `*' wasn't used as an example (and I didn't check the BNF carefully enough). Curious, did you discover this on a certain real-world IMAP client? ------8<------ Subject: [PATCH] imap: allow bare `*' in range I missed that a bare `*' is an allowable seq-number for IMAP for the number of the latest message in a given mailbox. Reported-by: Augusto Stoffel Link: https://public-inbox.org/meta/87jzdzguml.fsf@gmail.com/ --- lib/PublicInbox/IMAP.pm | 5 ++++- t/imapd.t | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/PublicInbox/IMAP.pm b/lib/PublicInbox/IMAP.pm index 378a0363..74249784 100644 --- a/lib/PublicInbox/IMAP.pm +++ b/lib/PublicInbox/IMAP.pm @@ -88,7 +88,7 @@ for my $att (keys %FETCH_ATT) { } undef %FETCH_NEED; -my $valid_range = '[0-9]+|[0-9]+:[0-9]+|[0-9]+:\*'; +my $valid_range = '[0-9]+|[0-9]+:[0-9]+|[0-9]+:\*|\*'; $valid_range = qr/\A(?:$valid_range)(?:,(?:$valid_range))*\z/; sub do_greet { @@ -697,6 +697,9 @@ sub range_step ($$) { # just let the caller do an out-of-range query if a single # UID is out-of-range ++$beg if ($beg <= $uid_base || $end > $uid_end); + } elsif ($range eq '*') { + $beg = $end = $self->{ibx}->over(1)->max; + uid_clamp($self, \$beg, \$end); } else { return 'BAD fetch range'; } diff --git a/t/imapd.t b/t/imapd.t index 549b8766..27c46e54 100644 --- a/t/imapd.t +++ b/t/imapd.t @@ -174,7 +174,7 @@ is_deeply(scalar $mic->flags('1'), [], '->flags works'); is_deeply($ret, {}, "out-of-range UID FETCH $r"); } -for my $r ('1:*', '1') { +for my $r ('1:*', '1', '*') { $ret = $mic->fetch_hash($r, 'RFC822') or BAIL_OUT "FETCH $@"; is_deeply([keys %$ret], [1]); like($ret->{1}->{RFC822}, qr/\r\n\r\nThis is a test/, 'read full');