From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 6D8911FA04 for ; Wed, 10 Jun 2020 07:06:27 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 44/82] imapd: ensure LIST is sorted alphabetically, for now Date: Wed, 10 Jun 2020 07:04:41 +0000 Message-Id: <20200610070519.18252-45-e@yhbt.net> In-Reply-To: <20200610070519.18252-1-e@yhbt.net> References: <20200610070519.18252-1-e@yhbt.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: I'm not sure this matters, and it could be a waste of CPU cycles if no real clients care. However, it does make debugging over telnet or s_client a bit easier. --- lib/PublicInbox/IMAPD.pm | 7 ++++++- t/imapd.t | 14 +++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/PublicInbox/IMAPD.pm b/lib/PublicInbox/IMAPD.pm index b647c940505..6488dc0f3bc 100644 --- a/lib/PublicInbox/IMAPD.pm +++ b/lib/PublicInbox/IMAPD.pm @@ -72,7 +72,12 @@ sub imapd_refresh_finalize { map { my $no = $mailboxes->{$_} == $dummy ? '' : 'No'; qq[* LIST (\\Has${no}Children) "." $_\r\n] - } sort { length($a) <=> length($b) } keys %$mailboxes + } sort { + # shortest names first, alphabetically if lengths match + length($a) == length($b) ? + ($a cmp $b) : + (length($a) <=> length($b)) + } keys %$mailboxes ]; $imapd->{pi_config} = $pi_config; if (my $idler = $imapd->{idler}) { diff --git a/t/imapd.t b/t/imapd.t index 017bfa0b27b..5d9a7d1181c 100644 --- a/t/imapd.t +++ b/t/imapd.t @@ -100,7 +100,7 @@ like($raw[0], qr/\A\*\x20STATUS\x20inbox\.i1\.$first_range\x20 \(MESSAGES\x20\d+\x20UIDNEXT\x20\d+\x20UIDVALIDITY\x20\d+\)\r\n/sx); like($raw[1], qr/\A\S+ OK /, 'finished status response'); -@raw = $mic->list; +my @orig_list = @raw = $mic->list; like($raw[0], qr/^\* LIST \(.*?\) "\." inbox/, 'got an inbox'); like($raw[-1], qr/^\S+ OK /, 'response ended with OK'); @@ -351,6 +351,18 @@ $r2 = $mic->fetch_hash(2, 'BODY.PEEK[HEADER.FIELDS (message-id)]') is($r2->{2}->{'BODY[HEADER.FIELDS (MESSAGE-ID)]'}, 'Message-ID: <20200418222508.GA13918@dcvr>'."\r\n\r\n", 'BODY.PEEK[HEADER.FIELDS ...] drops .PEEK'); + +{ + my @new_list = $mic->list; + # tag differs in [-1] + like($orig_list[-1], qr/\A\S+ OK List done\r\n/, 'orig LIST'); + like($new_list[-1], qr/\A\S+ OK List done\r\n/, 'new LIST'); + pop @new_list; + pop @orig_list; + # TODO: not sure if sort order matters, imapd_refresh_finalize + # sorts, for now, but maybe clients don't care... + is_deeply(\@new_list, \@orig_list, 'LIST identical'); +} ok($mic->close, 'CLOSE works'); ok(!$mic->close, 'CLOSE not idempotent'); ok($mic->logout, 'logged out');