about summary refs log tree commit homepage
path: root/lib/PublicInbox/IMAP.pm
diff options
context:
space:
mode:
authorEric Wong <e@yhbt.net>2020-06-10 07:04:42 +0000
committerEric Wong <e@yhbt.net>2020-06-13 07:55:45 +0000
commitd67fff9abf168c7517311bdd8987ce174a60f2c4 (patch)
tree462f73d4c2f6046988c5c60967eb1d8963d4c5ba /lib/PublicInbox/IMAP.pm
parent4d1a787a0a3c27a11c266b2f76293d09b858b38e (diff)
downloadpublic-inbox-d67fff9abf168c7517311bdd8987ce174a60f2c4.tar.gz
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.
Diffstat (limited to 'lib/PublicInbox/IMAP.pm')
-rw-r--r--lib/PublicInbox/IMAP.pm15
1 files changed, 6 insertions, 9 deletions
diff --git a/lib/PublicInbox/IMAP.pm b/lib/PublicInbox/IMAP.pm
index 6f64dff9..5865822f 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