From: Eric Wong Date: Thu, 16 Sep 2021 02:19:42 +0000 (-0500) Subject: lei ls-mail-source: sort IMAP folder names X-Git-Tag: v1.7.0~365 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=ddfa726e55411277c5f8fda6a5f2c82d062b3fe2;p=public-inbox.git lei ls-mail-source: sort IMAP folder names Otherwise, public-inbox-imapd will emit mailboxes in random order (as IMAP servers do not need to guarantee any sort of ordering). We'll take into account numeric slice numbers generated by -imapd if they exist, so slice "80" doesn't show up next to "8". --- diff --git a/lib/PublicInbox/LeiLsMailSource.pm b/lib/PublicInbox/LeiLsMailSource.pm index 71e253d9..f012e10e 100644 --- a/lib/PublicInbox/LeiLsMailSource.pm +++ b/lib/PublicInbox/LeiLsMailSource.pm @@ -27,6 +27,12 @@ sub input_path_url { # overrides LeiInput version my $sec = $lei->{net}->can('uri_section')->($uri); my $mic = $lei->{net}->mic_get($uri); my $l = $mic->folders_hash($uri->path); # server-side filter + @$l = map { $_->[2] } # undo Schwartzian transform below: + sort { $a->[0] cmp $b->[0] || $a->[1] <=> $b->[1] } + map { # prepare to sort -imapd slices numerically + $_->{name} =~ /\A(.+?)\.([0-9]+)\z/ ? + [ $1, $2 + 0, $_ ] : [ $_->{name}, -1, $_ ]; + } @$l; @f = map { "$sec/$_->{name}" } @$l; if ($json) { $_->{url} = "$sec/$_->{name}" for @$l;