- @names = map {;
- my $at = delete($ns{$_}) ? '\\HasChildren' : '\\HasNoChildren';
- qq[* LIST ($at) "." $_\r\n]
- } @names;
- push(@names, map { qq[* LIST ($ns{$_}) "." $_\r\n] } keys %ns);
- @names = sort {
- my ($xa) = ($a =~ / (\S+)\r\n/g);
- my ($xb) = ($b =~ / (\S+)\r\n/g);
- length($xa) <=> length($xb);
- } @names;
- $self->{inboxlist} = \@names;
-}
-
-sub imapd_refresh_ibx { # pi_config->each_inbox cb
- my ($ibx, $imapd) = @_;
- my $ngname = $ibx->{newsgroup} or return;
- if (ref $ngname) {
- warn 'multiple newsgroups not supported: '.
- join(', ', @$ngname). "\n";
- } elsif ($ngname =~ m![^a-z0-9/_\.\-\~\@\+\=:]! ||
- $ngname =~ /\.[0-9]+-[0-9]+\z/) {
- warn "mailbox name invalid: `$ngname'\n";
- }
-
- my $mm = $ibx->mm or return;
- $ibx->{mm} = undef;
- defined($ibx->{uidvalidity} = $mm->created_at) or return;
- $imapd->{tmp_groups}->{$ngname} = $ibx;
-
- # preload to avoid fragmentation:
- $ibx->description;
- $ibx->base_url;
- # my $max = $mm->max // 0;
- # my $uid_min = UID_BLOCK * int($max/UID_BLOCK) + 1;
-}
-
-sub imapd_refresh_finalize {
- my ($imapd, $pi_config) = @_;
- $imapd->{groups} = delete $imapd->{tmp_groups};
- $imapd->{grouplist} = [ values %{$imapd->{groups}} ];
- refresh_inboxlist($imapd);
- $imapd->{pi_config} = $pi_config;
- if (my $idler = $imapd->{idler}) {
- $idler->refresh($pi_config);
- }
-}
-
-sub imapd_refresh_step { # pi_config->iterate_start cb
- my ($pi_config, $section, $imapd) = @_;
- if (defined($section)) {
- return if $section !~ m!\Apublicinbox\.([^/]+)\z!;
- my $ibx = $pi_config->lookup_name($1) or return;
- imapd_refresh_ibx($ibx, $imapd);
- } else { # "EOF"
- imapd_refresh_finalize($imapd, $pi_config);
+ my $ce = $cache->{$ngname};
+ %$ibx = (%$ibx, %$ce) if $ce;
+ # only valid if msgmap and over works:
+ if (defined($ibx->uidvalidity)) {
+ # fill ->{mailboxes}:
+ PublicInbox::IMAP::ensure_slices_exist($imapd, $ibx);
+ # preload to avoid fragmentation:
+ $ibx->description;
+ # ensure dummies are selectable:
+ do {
+ $dummies->{$ngname} = $dummy;
+ } while ($ngname =~ s/\.[^\.]+\z//);