user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
966879d8ea59f76e8401468e09db7953bbc269c2 blob 1744 bytes (raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
 
# Copyright (C) 2020 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>

# represents an IMAPD (currently a singleton),
# see script/public-inbox-imapd for how it is used
package PublicInbox::IMAPD;
use strict;
use parent qw(PublicInbox::NNTPD);
use PublicInbox::InboxIdle;

sub new {
	my ($class) = @_;
	bless {
		groups => {},
		err => \*STDERR,
		out => \*STDOUT,
		grouplist => [],
		# accept_tls => { SSL_server => 1, ..., SSL_reuse_ctx => ... }
		# pi_config => PublicInbox::Config
		# idler => PublicInbox::InboxIdle
	}, $class;
}

sub refresh_inboxlist ($) {
	my ($self) = @_;
	my @names = map { $_->{newsgroup} } @{delete $self->{grouplist}};
	my %ns; # "\Noselect \HasChildren"

	if (my @uc = grep(/[A-Z]/, @names)) {
		warn "Uppercase not allowed for IMAP newsgroup(s):\n",
			map { "\t$_\n" } @uc;
		my %uc = map { $_ => 1 } @uc;
		@names = grep { !$uc{$_} } @names;
	}
	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);
	}
}

sub idler_start {
	$_[0]->{idler} //= PublicInbox::InboxIdle->new($_[0]->{pi_config});
}

1;
debug log:

solving 966879d8ea5 ...
found 966879d8ea5 in public-inbox.git

Code repositories for project(s) associated with this 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).