-sub inbox_lookup ($$) {
- my ($self, $mailbox) = @_;
- my ($ibx, $exists, $uidnext, $uid_base);
- if ($mailbox =~ /\A(.+)\.([0-9]+)\z/) {
- # old mail: inbox.comp.foo.$SLICE_IDX
- my $mb_top = $1;
- $uid_base = $2 * UID_SLICE;
- $ibx = $self->{imapd}->{mailboxes}->{lc $mailbox} or return;
- my $max;
- ($exists, $uidnext, $max) = $ibx->over->imap_status($uid_base,
- $uid_base + UID_SLICE);
- ensure_slices_exist($self->{imapd}, $ibx, $max);
- } else { # check for dummy inboxes
- $mailbox = lc $mailbox;
- $ibx = $self->{imapd}->{mailboxes}->{$mailbox} or return;
-
+sub inbox_lookup ($$;$) {
+ my ($self, $mailbox, $examine) = @_;
+ my ($ibx, $exists, $uidmax, $uid_base) = (undef, 0, 0, 0);
+ $mailbox = lc $mailbox;
+ $ibx = $self->{imapd}->{mailboxes}->{$mailbox} or return;
+ my $over = $ibx->over;
+ if ($over != $ibx) { # not a dummy
+ $mailbox =~ /\.([0-9]+)\z/ or
+ die "BUG: unexpected dummy mailbox: $mailbox\n";
+ $uid_base = $1 * UID_SLICE;
+
+ # ->num_highwater caches for writers, so use ->meta_accessor
+ $uidmax = $ibx->mm->meta_accessor('num_highwater') // 0;
+ if ($examine) {
+ $self->{uid_base} = $uid_base;
+ $self->{ibx} = $ibx;
+ $self->{uo2m} = uo2m_ary_new($self, \$exists);
+ } else {
+ $exists = $over->imap_exists;
+ }
+ ensure_slices_exist($self->{imapd}, $ibx, $over->max);
+ } else {
+ if ($examine) {
+ $self->{uid_base} = $uid_base;
+ $self->{ibx} = $ibx;
+ delete $self->{uo2m};
+ }