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,AWL,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 A88611FC04 for ; Wed, 10 Jun 2020 07:07:32 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 71/82] imap: cleanup ->{uid_base} usage Date: Wed, 10 Jun 2020 07:05:08 +0000 Message-Id: <20200610070519.18252-72-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: Ensure {uid_base} is always set, so we don't need to add `//' checks everywhere. Furthermore, this fixes a hard-to-test bug where the STATUS command would inadvertantly clobber {uid_base}. --- lib/PublicInbox/IMAP.pm | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/lib/PublicInbox/IMAP.pm b/lib/PublicInbox/IMAP.pm index 12123072d1a..e9fa338b5fe 100644 --- a/lib/PublicInbox/IMAP.pm +++ b/lib/PublicInbox/IMAP.pm @@ -217,7 +217,7 @@ sub cmd_idle ($$) { my $ibx = $self->{ibx} or return "$tag BAD no mailbox selected\r\n"; $self->{-idle_tag} = $tag; my $max = $ibx->mm->max // 0; - my $uid_end = ($self->{uid_base} // 0) + UID_BLOCK; + my $uid_end = $self->{uid_base} + UID_BLOCK; my $sock = $self->{sock} or return; my $fd = fileno($sock); # only do inotify on most recent slice @@ -270,14 +270,13 @@ sub ensure_ranges_exist ($$$) { sub inbox_lookup ($$) { my ($self, $mailbox) = @_; - my ($ibx, $exists, $uidnext); + my ($ibx, $exists, $uidnext, $uid_base); if ($mailbox =~ /\A(.+)\.([0-9]+)\z/) { # old mail: inbox.comp.foo.$uid_block_idx - my ($mb_top, $uid_base) = ($1, $2 * UID_BLOCK); - + my $mb_top = $1; + $uid_base = $2 * UID_BLOCK; $ibx = $self->{imapd}->{mailboxes}->{lc $mailbox} or return; $exists = $ibx->mm->max // 0; - $self->{uid_base} = $uid_base; ensure_ranges_exist($self->{imapd}, $ibx, $exists); my $uid_end = $uid_base + UID_BLOCK; $exists = $uid_end if $exists > $uid_end; @@ -285,17 +284,17 @@ sub inbox_lookup ($$) { $exists -= $uid_base; } else { # check for dummy inboxes $ibx = $self->{imapd}->{mailboxes}->{lc $mailbox} or return; - delete $self->{uid_base}; - $exists = 0; + $uid_base = $exists = 0; $uidnext = 1; } - ($ibx, $exists, $uidnext); + ($ibx, $exists, $uidnext, $uid_base); } sub cmd_examine ($$$) { my ($self, $tag, $mailbox) = @_; - my ($ibx, $exists, $uidnext) = inbox_lookup($self, $mailbox); + my ($ibx, $exists, $uidnext, $base) = inbox_lookup($self, $mailbox); return "$tag NO Mailbox doesn't exist: $mailbox\r\n" if !$ibx; + $self->{uid_base} = $base; # XXX: do we need this? RFC 5162/7162 my $ret = $self->{ibx} ? "* OK [CLOSED] previous closed\r\n" : ''; @@ -499,8 +498,7 @@ sub fetch_blob_cb { # called by git->cat_async via git_async_cat # fixup old bug from import (pre-a0c07cba0e5d8b6a) $$bref =~ s/\A[\r\n]*From [^\r\n]*\r\n//s; - fetch_run_ops($self, $self->{uid_base} // 0, - $smsg, $bref, $ops, $partial); + fetch_run_ops($self, $self->{uid_base}, $smsg, $bref, $ops, $partial); requeue_once($self); } @@ -558,7 +556,7 @@ sub op_eml_new { $_[4] = PublicInbox::Eml->new($_[3]) } sub uid_clamp ($$$) { my ($self, $beg, $end) = @_; - my $uid_min = ($self->{uid_base} // 0) + 1; + my $uid_min = $self->{uid_base} + 1; my $uid_end = $uid_min + UID_BLOCK - 1; $$beg = $uid_min if $$beg < $uid_min; $$end = $uid_end if $$end > $uid_end; @@ -625,7 +623,7 @@ sub fetch_smsg { # long_response return; } } - my $uid_base = $self->{uid_base} // 0; + my $uid_base = $self->{uid_base}; fetch_run_ops($self, $uid_base, $_, undef, $ops) for @$msgs; @$msgs = (); 1; # more @@ -652,7 +650,7 @@ sub fetch_uid { # long_response } # continue looping } - my $uid_base = $self->{uid_base} // 0; + my $uid_base = $self->{uid_base}; my ($i, $k); for (@$uids) { $self->msg_more(fetch_msn_uid($uid_base, $_)); @@ -903,7 +901,7 @@ sub cmd_uid_fetch ($$$$;@) { } sub msn_to_uid_range ($$) { - my $uid_base = $_[0]->{uid_base} // 0; + my $uid_base = $_[0]->{uid_base}; $_[1] =~ s/([0-9]+)/$uid_base + $1/sge; }