]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei ls-mail-source: sort IMAP folder names
authorEric Wong <e@80x24.org>
Thu, 16 Sep 2021 02:19:42 +0000 (21:19 -0500)
committerEric Wong <e@80x24.org>
Thu, 16 Sep 2021 04:29:18 +0000 (04:29 +0000)
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

index 71e253d9c476c954f8f68b86eeb29adcefdba95c..f012e10e89c2d10a71da50414be285ebe4a65d0f 100644 (file)
@@ -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;