From ddfa726e55411277c5f8fda6a5f2c82d062b3fe2 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 15 Sep 2021 21:19:42 -0500 Subject: [PATCH] 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". --- lib/PublicInbox/LeiLsMailSource.pm | 6 ++++++ 1 file changed, 6 insertions(+) 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; -- 2.48.1