From: Eric Wong <e@80x24.org>
To: Augusto Stoffel <arstoffel@gmail.com>
Cc: meta@public-inbox.org
Subject: [PATCH] imap: allow bare `*' in range
Date: Wed, 23 Oct 2024 09:30:05 +0000 [thread overview]
Message-ID: <20241023093005.M99868@dcvr> (raw)
In-Reply-To: <87jzdzguml.fsf@gmail.com>
Augusto Stoffel <arstoffel@gmail.com> 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 <arstoffel@gmail.com>
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');
next prev parent reply other threads:[~2024-10-23 9:30 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-23 7:12 Bug in FETCH request? Augusto Stoffel
2024-10-23 9:30 ` Eric Wong [this message]
2024-10-29 6:53 ` [PATCH] imap: allow bare `*' in range Augusto Stoffel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241023093005.M99868@dcvr \
--to=e@80x24.org \
--cc=arstoffel@gmail.com \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).