]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
imap: allow bare `*' in range
authorEric Wong <e@80x24.org>
Wed, 23 Oct 2024 09:30:05 +0000 (09:30 +0000)
committerEric Wong <e@80x24.org>
Thu, 24 Oct 2024 07:07:44 +0000 (07:07 +0000)
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
t/imapd.t

index 378a0363eb3e0ff4a48c28abdc45f9629af1ac73..742497841b8473c13450b3992624f264d5773f9e 100644 (file)
@@ -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';
        }
index 549b87666851ef376fc1a3fde51c0798f4be7af6..27c46e5401195cbbb5ccb706f385fdfe2f3d7a51 100644 (file)
--- 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');