about summary refs log tree commit homepage
path: root/lib/PublicInbox/IMAP.pm
diff options
context:
space:
mode:
authorEric Wong <e@yhbt.net>2020-06-10 07:04:07 +0000
committerEric Wong <e@yhbt.net>2020-06-13 07:55:45 +0000
commit0735aef9bffc4779628a069aefc438e5371b40cc (patch)
tree1947d8ba211ebc37e27f2fff179c5fa553752aea /lib/PublicInbox/IMAP.pm
parenta62624ba8aa07f4d38d6d99623f6a2e679193896 (diff)
downloadpublic-inbox-0735aef9bffc4779628a069aefc438e5371b40cc.tar.gz
We'll optimize for the common case of: $TAG LIST "" *
and rely on the grep perlfunc to handle trickier cases.
Diffstat (limited to 'lib/PublicInbox/IMAP.pm')
-rw-r--r--lib/PublicInbox/IMAP.pm14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/PublicInbox/IMAP.pm b/lib/PublicInbox/IMAP.pm
index 7745d9f9..ca9a0ea7 100644
--- a/lib/PublicInbox/IMAP.pm
+++ b/lib/PublicInbox/IMAP.pm
@@ -336,6 +336,20 @@ sub cmd_status ($$$;@) {
         "$tag OK Status complete\r\n";
 }
 
+my %patmap = ('*' => '.*', '%' => '[^\.]*');
+sub cmd_list ($$$$) {
+        my ($self, $tag, $refname, $wildcard) = @_;
+        my $l = $self->{imapd}->{inboxlist};
+        if ($refname eq '' && $wildcard eq '') {
+                # request for hierarchy delimiter
+                $l = [ qq[* LIST (\\Noselect) "." ""\r\n] ];
+        } elsif ($refname ne '' || $wildcard ne '*') {
+                $wildcard =~ s!([^a-z0-9_])!$patmap{$1} // "\Q$1"!eig;
+                $l = [ grep(/ \Q$refname\E$wildcard\r\n\z/s, @$l) ];
+        }
+        \(join('', @$l, "$tag OK List complete\r\n"));
+}
+
 sub cmd_uid_fetch ($$$;@) {
         my ($self, $tag, $range, @want) = @_;
         my $ibx = $self->{ibx} or return "$tag BAD No mailbox selected\r\n";