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 9B0BC1FA09 for ; Wed, 10 Jun 2020 07:06:27 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 45/82] imap: omit $UID_END from mailbox name, use index Date: Wed, 10 Jun 2020 07:04:42 +0000 Message-Id: <20200610070519.18252-46-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: Having two large numbers separated by a dash can make visual comparisons difficult when numbers are in the 3,000,000 range for LKML. So avoid the $UID_END value, since it can be calculated from $UID_MIN. And we can avoid large values of $UID_MIN, too, by instead storing the block index and just multiplying it by 50000 (and adding 1) on the server side. Of course, LKML still goes up to 72, at the moment. --- lib/PublicInbox/IMAP.pm | 15 ++++++--------- lib/PublicInbox/IMAPD.pm | 2 +- t/imapd.t | 2 +- xt/imapd-mbsync-oimap.t | 2 +- xt/imapd-validate.t | 2 +- 5 files changed, 10 insertions(+), 13 deletions(-) diff --git a/lib/PublicInbox/IMAP.pm b/lib/PublicInbox/IMAP.pm index 6f64dff9958..5865822f0c3 100644 --- a/lib/PublicInbox/IMAP.pm +++ b/lib/PublicInbox/IMAP.pm @@ -197,14 +197,10 @@ sub ensure_ranges_exist ($$$) { my $mailboxes = $imapd->{mailboxes}; my $mb_top = $ibx->{newsgroup}; my @created; - my $uid_min = UID_BLOCK * int($max/UID_BLOCK) + 1; - my $uid_end = $uid_min + UID_BLOCK - 1; - while ($uid_min > 0) { - my $sub_mailbox = "$mb_top.$uid_min-$uid_end"; + for (my $i = int($max/UID_BLOCK); $i >= 0; --$i) { + my $sub_mailbox = "$mb_top.$i"; last if exists $mailboxes->{$sub_mailbox}; $mailboxes->{$sub_mailbox} = $ibx; - $uid_end -= UID_BLOCK; - $uid_min -= UID_BLOCK; push @created, $sub_mailbox; } return unless @created; @@ -216,9 +212,9 @@ sub cmd_examine ($$$) { my ($self, $tag, $mailbox) = @_; my ($ibx, $mm, $max); - if ($mailbox =~ /\A(.+)\.([0-9]+)-([0-9]+)\z/) { - # old mail: inbox.comp.foo.$uid_min-$uid_end - my ($mb_top, $uid_min, $uid_end) = ($1, $2 + 0, $3 + 0); + if ($mailbox =~ /\A(.+)\.([0-9]+)\z/) { + # old mail: inbox.comp.foo.$uid_block_idx + my ($mb_top, $uid_min) = ($1, $2 * UID_BLOCK + 1); $ibx = $self->{imapd}->{mailboxes}->{lc $mailbox} or return "$tag NO Mailbox doesn't exist: $mailbox\r\n"; @@ -227,6 +223,7 @@ sub cmd_examine ($$$) { $max = $mm->max // 0; $self->{uid_min} = $uid_min; ensure_ranges_exist($self->{imapd}, $ibx, $max); + my $uid_end = $uid_min + UID_BLOCK - 1; $max = $uid_end if $max > $uid_end; } else { # check for dummy inboxes $ibx = $self->{imapd}->{mailboxes}->{lc $mailbox} or diff --git a/lib/PublicInbox/IMAPD.pm b/lib/PublicInbox/IMAPD.pm index 6488dc0f3bc..261d756042f 100644 --- a/lib/PublicInbox/IMAPD.pm +++ b/lib/PublicInbox/IMAPD.pm @@ -31,7 +31,7 @@ sub imapd_refresh_ibx { # pi_config->each_inbox cb join(', ', @$ngname). "\n"; return; } elsif ($ngname =~ m![^a-z0-9/_\.\-\~\@\+\=:]! || - $ngname =~ /\.[0-9]+-[0-9]+\z/) { + $ngname =~ /\.[0-9]+\z/) { warn "mailbox name invalid: newsgroup=`$ngname'\n"; return; } diff --git a/t/imapd.t b/t/imapd.t index 5d9a7d1181c..45ee401a1e0 100644 --- a/t/imapd.t +++ b/t/imapd.t @@ -17,7 +17,7 @@ if ($can_compress) { # hope this gets fixed upstream, soon } require_ok 'PublicInbox::IMAP'; -my $first_range = '1-'.PublicInbox::IMAP::UID_BLOCK(); +my $first_range = '0'; my $level = '-Lbasic'; SKIP: { diff --git a/xt/imapd-mbsync-oimap.t b/xt/imapd-mbsync-oimap.t index b2cb8737f82..fdaa22aa9ef 100644 --- a/xt/imapd-mbsync-oimap.t +++ b/xt/imapd-mbsync-oimap.t @@ -14,7 +14,7 @@ plan skip_all => "bad characters in $inboxdir" if $inboxdir =~ m![^\w\.\-/]!; my ($tmpdir, $for_destroy) = tmpdir(); my $cfg = "$tmpdir/cfg"; my $newsgroup = 'inbox.test'; -my $mailbox = "$newsgroup.1-50000"; +my $mailbox = "$newsgroup.0"; { open my $fh, '>', $cfg or BAIL_OUT "open: $!"; print $fh <(); - $mailbox = "$newsgroup.1-50000"; + $mailbox = "$newsgroup.0"; } my %opts = (imap => \%OPT, 'imap+compress' => { %OPT, Compress => 1 });