about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-09-15 21:19:43 -0500
committerEric Wong <e@80x24.org>2021-09-16 04:29:18 +0000
commit9d65d8e41fa69c0f0a13789754c5d6dc5f699b8a (patch)
treec53eed7d9063fc5419459da128bba0eeb4728542
parentddfa726e55411277c5f8fda6a5f2c82d062b3fe2 (diff)
downloadpublic-inbox-9d65d8e41fa69c0f0a13789754c5d6dc5f699b8a.tar.gz
While RFC 3501 doesn't require LIST responses be sorted,
it makes reading protocol dumps easier and we memoize it
once per-refresh, so it shouldn't be too expensive even
with thousands of folders.
-rw-r--r--lib/PublicInbox/IMAP.pm4
-rw-r--r--lib/PublicInbox/IMAPD.pm15
2 files changed, 14 insertions, 5 deletions
diff --git a/lib/PublicInbox/IMAP.pm b/lib/PublicInbox/IMAP.pm
index 37e07dae..27013ea5 100644
--- a/lib/PublicInbox/IMAP.pm
+++ b/lib/PublicInbox/IMAP.pm
@@ -384,7 +384,7 @@ sub ensure_slices_exist ($$$) {
                 push @created, $sub_mailbox;
         }
         return unless @created;
-        my $l = $imapd->{inboxlist} or return;
+        my $l = $imapd->{mailboxlist} or return;
         push @$l, map { qq[* LIST (\\HasNoChildren) "." $_\r\n] } @created;
 }
 
@@ -850,7 +850,7 @@ sub cmd_status ($$$;@) {
 my %patmap = ('*' => '.*', '%' => '[^\.]*');
 sub cmd_list ($$$$) {
         my ($self, $tag, $refname, $wildcard) = @_;
-        my $l = $self->{imapd}->{inboxlist};
+        my $l = $self->{imapd}->{mailboxlist};
         if ($refname eq '' && $wildcard eq '') {
                 # request for hierarchy delimiter
                 $l = [ qq[* LIST (\\Noselect) "." ""\r\n] ];
diff --git a/lib/PublicInbox/IMAPD.pm b/lib/PublicInbox/IMAPD.pm
index 7425409d..6aa3d12f 100644
--- a/lib/PublicInbox/IMAPD.pm
+++ b/lib/PublicInbox/IMAPD.pm
@@ -70,12 +70,21 @@ sub imapd_refresh_finalize {
         }
         %$mailboxes = (%$mailboxes, %{$imapd->{mailboxes}});
         $imapd->{mailboxes} = $mailboxes;
-        $imapd->{inboxlist} = [
+        $imapd->{mailboxlist} = [
+                map { $_->[2] }
+                sort { $a->[0] cmp $b->[0] || $a->[1] <=> $b->[1] }
                 map {
-                        my $no = $mailboxes->{$_} == $dummy ? '' : 'No';
                         my $u = $_; # capitalize "INBOX" for user-familiarity
                         $u =~ s/\Ainbox(\.|\z)/INBOX$1/i;
-                        qq[* LIST (\\Has${no}Children) "." $u\r\n]
+                        if ($mailboxes->{$_} == $dummy) {
+                                [ $u, -1,
+                                  qq[* LIST (\\HasChildren) "." $u\r\n]]
+                        } else {
+                                $u =~ /\A(.+)\.([0-9]+)\z/ or
+                                        die "BUG: `$u' has no slice digit(s)";
+                                [ $1, $2 + 0,
+                                  qq[* LIST (\\HasNoChildren) "." $u\r\n] ]
+                        }
                 } keys %$mailboxes
         ];
         $imapd->{pi_cfg} = $pi_cfg;