From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 3/3] imapd: sort LIST response
Date: Wed, 15 Sep 2021 21:19:43 -0500 [thread overview]
Message-ID: <20210916021943.22529-4-e@80x24.org> (raw)
In-Reply-To: <20210916021943.22529-1-e@80x24.org>
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.
---
lib/PublicInbox/IMAP.pm | 4 ++--
lib/PublicInbox/IMAPD.pm | 15 ++++++++++++---
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;
prev parent reply other threads:[~2021-09-16 2:19 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-16 2:19 [PATCH 0/3] IMAP and Tor .onion niceities Eric Wong
2021-09-16 2:19 ` [PATCH 1/3] net_reader: emit .onion help for potential Tor users Eric Wong
2021-09-16 2:19 ` [PATCH 2/3] lei ls-mail-source: sort IMAP folder names Eric Wong
2021-09-16 2:19 ` Eric Wong [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210916021943.22529-4-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).