]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/IMAPD.pm
lei: move to v5.12 to avoid "use strict"
[public-inbox.git] / lib / PublicInbox / IMAPD.pm
index fb9458477ef7a09d135cc21c6ac8f252985830dd..6aa3d12fa1e76eb4a2ab20008e281a9dfad03ec8 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2020 all contributors <meta@public-inbox.org>
+# Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 
 # represents an IMAPD (currently a singleton),
@@ -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;