From 0735aef9bffc4779628a069aefc438e5371b40cc Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 10 Jun 2020 07:04:07 +0000 Subject: imap: support LIST command We'll optimize for the common case of: $TAG LIST "" * and rely on the grep perlfunc to handle trickier cases. --- lib/PublicInbox/IMAPD.pm | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'lib/PublicInbox/IMAPD.pm') diff --git a/lib/PublicInbox/IMAPD.pm b/lib/PublicInbox/IMAPD.pm index 05aa30e4..a3a25986 100644 --- a/lib/PublicInbox/IMAPD.pm +++ b/lib/PublicInbox/IMAPD.pm @@ -21,10 +21,35 @@ sub new { }, $class; } +sub refresh_inboxlist ($) { + my ($self) = @_; + my @names = map { $_->{newsgroup} } @{delete $self->{grouplist}}; + my %ns; # "\Noselect \HasChildren" + for (@names) { + my $up = $_; + while ($up =~ s/\.[^\.]+\z//) { + $ns{$up} = '\\Noselect \\HasChildren'; + } + } + @names = map {; + my $at = delete($ns{$_}) ? '\\HasChildren' : '\\HasNoChildren'; + qq[* LIST ($at) "." $_\r\n] + } @names; + push(@names, map { qq[* LIST ($ns{$_}) "." $_\r\n] } keys %ns); + @names = sort { + my ($xa) = ($a =~ / (\S+)\r\n/g); + my ($xb) = ($b =~ / (\S+)\r\n/g); + length($xa) <=> length($xb); + } @names; + $self->{inboxlist} = \@names; +} + sub refresh_groups { my ($self) = @_; my $pi_config = $self->{pi_config} = PublicInbox::Config->new; $self->SUPER::refresh_groups($pi_config); + refresh_inboxlist($self); + if (my $idler = $self->{idler}) { $idler->refresh($pi_config); } -- cgit v1.2.3-24-ge0c7