1 # Copyright (C) 2020 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # Each instance of this represents an IMAP client connected to
5 # public-inbox-imapd. Much of this was taken from NNTP, but
6 # further refined while experimenting on future ideas to handle
10 # * NNTP article numbers are UIDs and message sequence numbers (MSNs)
11 # * Message sequence numbers (MSNs) can be stable since we're read-only.
12 # Most IMAP clients use UIDs (I hope), and we can return a dummy
13 # message if a client requests a non-existent MSN.
15 package PublicInbox::IMAP;
17 use base qw(PublicInbox::DS);
18 use fields qw(imapd logged_in ibx long_cb -login_tag
21 use PublicInbox::EmlContentFoo qw(parse_content_disposition);
22 use PublicInbox::DS qw(now);
23 use PublicInbox::Syscall qw(EPOLLIN EPOLLONESHOT);
24 use Text::ParseWords qw(parse_line);
27 for my $mod (qw(Email::Address::XS Mail::Address)) {
28 eval "require $mod" or next;
29 $Address = $mod and last;
31 die "neither Email::Address::XS nor Mail::Address loaded: $@" if !$Address;
33 sub LINE_MAX () { 512 } # does RFC 3501 have a limit like RFC 977?
35 my %FETCH_NEED_BLOB = ( # for future optimization
36 'BODY.PEEK[HEADER]' => 1,
37 'BODY.PEEK[TEXT]' => 1,
43 'RFC822.SIZE' => 1, # needs CRLF conversion :<
53 my %FETCH_ATT = map { $_ => [ $_ ] } keys %FETCH_NEED_BLOB;
55 # aliases (RFC 3501 section 6.4.5)
56 $FETCH_ATT{FAST} = [ qw(FLAGS INTERNALDATE RFC822.SIZE) ];
57 $FETCH_ATT{ALL} = [ @{$FETCH_ATT{FAST}}, 'ENVELOPE' ];
58 $FETCH_ATT{FULL} = [ @{$FETCH_ATT{ALL}}, 'BODY' ];
60 for my $att (keys %FETCH_ATT) {
61 my %h = map { $_ => 1 } @{$FETCH_ATT{$att}};
62 $FETCH_ATT{$att} = \%h;
67 my $capa = capa($self);
68 $self->write(\"* OK [$capa] public-inbox-imapd ready\r\n");
72 my ($class, $sock, $imapd) = @_;
73 my $self = fields::new($class);
76 if ($sock->can('accept_SSL') && !$sock->accept_SSL) {
77 return CORE::close($sock) if $! != EAGAIN;
78 $ev = PublicInbox::TLS::epollbit();
79 $wbuf = [ \&PublicInbox::DS::accept_tls_step, \&greet ];
81 $self->SUPER::new($sock, $ev | EPOLLONESHOT);
82 $self->{imapd} = $imapd;
84 $self->{wbuf} = $wbuf;
88 $self->update_idle_time;
95 # dovecot advertises IDLE pre-login; perhaps because some clients
96 # depend on it, so we'll do the same
97 my $capa = 'CAPABILITY IMAP4rev1 IDLE';
98 if ($self->{logged_in}) {
99 $capa .= ' COMPRESS=DEFLATE';
101 if (!($self->{sock} // $self)->can('accept_SSL') &&
102 $self->{imapd}->{accept_tls}) {
103 $capa .= ' STARTTLS';
105 $capa .= ' AUTH=ANONYMOUS';
109 sub login_success ($$) {
110 my ($self, $tag) = @_;
111 $self->{logged_in} = 1;
112 my $capa = capa($self);
113 "$tag OK [$capa] Logged in\r\n";
116 sub auth_challenge_ok ($) {
118 my $tag = delete($self->{-login_tag}) or return;
119 login_success($self, $tag);
122 sub cmd_login ($$$$) {
123 my ($self, $tag) = @_; # ignore ($user, $password) = ($_[2], $_[3])
124 login_success($self, $tag);
127 sub cmd_logout ($$) {
128 my ($self, $tag) = @_;
129 delete $self->{logged_in};
130 $self->write(\"* BYE logging out\r\n$tag OK logout completed\r\n");
131 $self->shutdn; # PublicInbox::DS::shutdn
135 sub cmd_authenticate ($$$) {
136 my ($self, $tag) = @_; # $method = $_[2], should be "ANONYMOUS"
137 $self->{-login_tag} = $tag;
141 sub cmd_capability ($$) {
142 my ($self, $tag) = @_;
143 '* '.capa($self)."\r\n$tag OK\r\n";
146 sub cmd_noop ($$) { "$_[1] OK NOOP completed\r\n" }
148 # called by PublicInbox::InboxIdle
149 sub on_inbox_unlock {
150 my ($self, $ibx) = @_;
151 my $new = $ibx->mm->max;
152 defined(my $old = $self->{-idle_max}) or die 'BUG: -idle_max unset';
154 $self->{-idle_max} = $new;
155 $self->msg_more("* $_ EXISTS\r\n") for (($old + 1)..($new - 1));
156 $self->write(\"* $new EXISTS\r\n");
161 my ($self, $tag) = @_;
162 # IDLE seems allowed by dovecot w/o a mailbox selected *shrug*
163 my $ibx = $self->{ibx} or return "$tag BAD no mailbox selected\r\n";
164 $ibx->subscribe_unlock(fileno($self->{sock}), $self);
165 $self->{imapd}->idler_start;
166 $self->{-idle_tag} = $tag;
167 $self->{-idle_max} = $ibx->mm->max // 0;
172 my ($self, $tag) = @_; # $tag is "DONE" (case-insensitive)
173 defined(my $idle_tag = delete $self->{-idle_tag}) or
174 return "$tag BAD not idle\r\n";
175 my $ibx = $self->{ibx} or do {
176 warn "BUG: idle_tag set w/o inbox";
177 return "$tag BAD internal bug\r\n";
179 $ibx->unsubscribe_unlock(fileno($self->{sock}));
180 "$idle_tag OK Idle completed\r\n";
183 sub cmd_examine ($$$) {
184 my ($self, $tag, $mailbox) = @_;
185 my $ibx = $self->{imapd}->{groups}->{$mailbox} or
186 return "$tag NO Mailbox doesn't exist: $mailbox\r\n";
188 my $max = $mm->max // 0;
189 # RFC 3501 2.3.1.1 - "A good UIDVALIDITY value to use in
190 # this case is a 32-bit representation of the creation
191 # date/time of the mailbox"
192 my $uidvalidity = $mm->created_at or return "$tag BAD UIDVALIDITY\r\n";
193 my $uidnext = $max + 1;
195 # XXX: do we need this? RFC 5162/7162
196 my $ret = $self->{ibx} ? "* OK [CLOSED] previous closed\r\n" : '';
202 * OK [PERMANENTFLAGS ()] Read-only mailbox\r
204 $ret .= "* OK [UNSEEN $max]\r\n" if $max;
205 $ret .= "* OK [UIDNEXT $uidnext]\r\n" if defined $uidnext;
206 $ret .= "* OK [UIDVALIDITY $uidvalidity]\r\n" if defined $uidvalidity;
207 $ret .= "$tag OK [READ-ONLY] EXAMINE/SELECT complete\r\n";
214 } elsif ($v =~ /[{"\r\n%*\\\[]/) { # literal string
215 '{' . length($v) . "}\r\n" . $v;
216 } else { # quoted string
221 sub addr_envelope ($$;$) {
222 my ($eml, $x, $y) = @_;
223 my $v = $eml->header_raw($x) //
224 ($y ? $eml->header_raw($y) : undef) // return 'NIL';
226 my @x = $Address->parse($v) or return 'NIL';
228 map { '(' . join(' ',
229 _esc($_->name), 'NIL',
230 _esc($_->user), _esc($_->host)
236 sub eml_envelope ($) {
239 _esc($eml->header_raw('Date')),
240 _esc($eml->header_raw('Subject')),
241 addr_envelope($eml, 'From'),
242 addr_envelope($eml, 'Sender', 'From'),
243 addr_envelope($eml, 'Reply-To', 'From'),
244 addr_envelope($eml, 'To'),
245 addr_envelope($eml, 'Cc'),
246 addr_envelope($eml, 'Bcc'),
247 _esc($eml->header_raw('In-Reply-To')),
248 _esc($eml->header_raw('Message-ID')),
254 if ($hash && scalar keys %$hash) {
255 $hash = [ %$hash ]; # flatten hash into 1-dimensional array
256 '(' . join(' ', map { _esc($_) } @$hash) . ')';
262 sub body_disposition ($) {
264 my $cd = $eml->header_raw('Content-Disposition') or return 'NIL';
265 $cd = parse_content_disposition($cd);
266 my $buf = '('._esc($cd->{type});
267 $buf .= ' ' . _esc_hash(delete $cd->{attributes});
271 sub body_leaf ($$;$) {
272 my ($eml, $structure, $hold) = @_;
274 $eml->{is_submsg} and # parent was a message/(rfc822|news|global)
275 $buf .= eml_envelope($eml). ' ';
277 $buf .= '('._esc($ct->{type}).' ';
278 $buf .= _esc($ct->{subtype});
279 $buf .= ' ' . _esc_hash(delete $ct->{attributes});
280 $buf .= ' ' . _esc($eml->header_raw('Content-ID'));
281 $buf .= ' ' . _esc($eml->header_raw('Content-Description'));
282 my $cte = $eml->header_raw('Content-Transfer-Encoding') // '7bit';
283 $buf .= ' ' . _esc($cte);
284 $buf .= ' ' . $eml->{imap_body_len};
285 $buf .= ' '.($eml->body_raw =~ tr/\n/\n/) if lc($ct->{type}) eq 'text';
287 # for message/(rfc822|global|news), $hold[0] should have envelope
288 $buf .= ' ' . (@$hold ? join('', @$hold) : 'NIL') if $hold;
291 $buf .= ' '._esc($eml->header_raw('Content-MD5'));
292 $buf .= ' '. body_disposition($eml);
293 $buf .= ' '._esc($eml->header_raw('Content-Language'));
294 $buf .= ' '._esc($eml->header_raw('Content-Location'));
299 sub body_parent ($$$) {
300 my ($eml, $structure, $hold) = @_;
302 my $type = lc($ct->{type});
303 if ($type eq 'multipart') {
305 $buf .= @$hold ? join('', @$hold) : 'NIL';
306 $buf .= ' '._esc($ct->{subtype});
308 $buf .= ' '._esc_hash(delete $ct->{attributes});
309 $buf .= ' '.body_disposition($eml);
310 $buf .= ' '._esc($eml->header_raw('Content-Language'));
311 $buf .= ' '._esc($eml->header_raw('Content-Location'));
315 } else { # message/(rfc822|global|news)
316 @$hold = (body_leaf($eml, $structure, $hold));
320 # this is gross, but we need to process the parent part AFTER
321 # the child parts are done
322 sub bodystructure_prep {
324 my ($eml, $depth) = @$p; # ignore idx
325 # set length here, as $eml->{bdy} gets deleted for message/rfc822
326 $eml->{imap_body_len} = length($eml->body_raw);
327 push @$q, $eml, $depth;
330 # for FETCH BODY and FETCH BODYSTRUCTURE
331 sub fetch_body ($;$) {
332 my ($eml, $structure) = @_;
334 $eml->each_part(\&bodystructure_prep, \@q, 0, 1);
338 my ($part, $depth) = splice(@q, -2);
339 my $is_mp_parent = $depth == ($cur_depth - 1);
343 body_parent($part, $structure, \@hold);
345 unshift @hold, body_leaf($part, $structure);
351 sub uid_fetch_cb { # called by git->cat_async
352 my ($bref, $oid, $type, $size, $fetch_m_arg) = @_;
353 my ($self, undef, $ibx, undef, undef, $msgs, $want) = @$fetch_m_arg;
354 my $smsg = shift @$msgs or die 'BUG: no smsg';
355 $smsg->{blob} eq $oid or die "BUG: $smsg->{blob} != $oid";
356 $$bref =~ s/(?<!\r)\n/\r\n/sg; # make strict clients happy
358 # fixup old bug from import (pre-a0c07cba0e5d8b6a)
359 $$bref =~ s/\A[\r\n]*From [^\r\n]*\r\n//s;
361 $self->msg_more("* $smsg->{num} FETCH (UID $smsg->{num}");
363 $want->{'RFC822.SIZE'} and
364 $self->msg_more(' RFC822.SIZE '.length($$bref));
365 $want->{INTERNALDATE} and
366 $self->msg_more(' INTERNALDATE "'.$smsg->internaldate.'"');
367 $want->{FLAGS} and $self->msg_more(' FLAGS ()');
368 for ('RFC822', 'BODY[]', 'BODY.PEEK[]') {
369 next unless $want->{$_};
370 $self->msg_more(" $_ {".length($$bref)."}\r\n");
371 $self->msg_more($$bref);
374 my $eml = PublicInbox::Eml->new($bref);
376 $want->{ENVELOPE} and
377 $self->msg_more(' ENVELOPE '.eml_envelope($eml));
379 for my $f ('RFC822.HEADER', 'BODY[HEADER]', 'BODY.PEEK[HEADER]') {
380 next unless $want->{$f};
381 $self->msg_more(" $f {".length(${$eml->{hdr}})."}\r\n");
382 $self->msg_more(${$eml->{hdr}});
384 for my $f ('RFC822.TEXT', 'BODY[TEXT]') {
385 next unless $want->{$f};
386 $self->msg_more(" $f {".length($$bref)."}\r\n");
387 $self->msg_more($$bref);
389 $want->{BODYSTRUCTURE} and
390 $self->msg_more(' BODYSTRUCTURE '.fetch_body($eml, 1));
392 $self->msg_more(' BODY '.fetch_body($eml));
394 $self->msg_more(")\r\n");
397 sub uid_fetch_m { # long_response
398 my ($self, $tag, $ibx, $beg, $end, $msgs, $want) = @_;
399 if (!@$msgs) { # refill
400 @$msgs = @{$ibx->over->query_xover($$beg, $end)};
402 $self->write(\"$tag OK Fetch done\r\n");
405 $$beg = $msgs->[-1]->{num} + 1;
408 $git->cat_async_begin; # TODO: actually make async
409 $git->cat_async($msgs->[0]->{blob}, \&uid_fetch_cb, \@_);
410 $git->cat_async_wait;
414 sub cmd_status ($$$;@) {
415 my ($self, $tag, $mailbox, @items) = @_;
416 my $ibx = $self->{imapd}->{groups}->{$mailbox} or
417 return "$tag NO Mailbox doesn't exist: $mailbox\r\n";
418 return "$tag BAD no items\r\n" if !scalar(@items);
419 ($items[0] !~ s/\A\(//s || $items[-1] !~ s/\)\z//s) and
420 return "$tag BAD invalid args\r\n";
424 for my $it (@items) {
427 if ($it =~ /\A(?:MESSAGES|UNSEEN|RECENT)\z/) {
428 push(@it, ($max //= $mm->max // 0));
429 } elsif ($it eq 'UIDNEXT') {
430 push(@it, ($max //= $mm->max // 0) + 1);
431 } elsif ($it eq 'UIDVALIDITY') {
432 push(@it, $mm->created_at //
433 return("$tag BAD UIDVALIDITY\r\n"));
435 return "$tag BAD invalid item\r\n";
438 return "$tag BAD no items\r\n" if !@it;
439 "* STATUS $mailbox (".join(' ', @it).")\r\n" .
440 "$tag OK Status complete\r\n";
443 my %patmap = ('*' => '.*', '%' => '[^\.]*');
444 sub cmd_list ($$$$) {
445 my ($self, $tag, $refname, $wildcard) = @_;
446 my $l = $self->{imapd}->{inboxlist};
447 if ($refname eq '' && $wildcard eq '') {
448 # request for hierarchy delimiter
449 $l = [ qq[* LIST (\\Noselect) "." ""\r\n] ];
450 } elsif ($refname ne '' || $wildcard ne '*') {
451 $wildcard =~ s!([^a-z0-9_])!$patmap{$1} // "\Q$1"!eig;
452 $l = [ grep(/ \Q$refname\E$wildcard\r\n\z/s, @$l) ];
454 \(join('', @$l, "$tag OK List complete\r\n"));
457 sub cmd_uid_fetch ($$$;@) {
458 my ($self, $tag, $range, @want) = @_;
459 my $ibx = $self->{ibx} or return "$tag BAD No mailbox selected\r\n";
460 if ($want[0] =~ s/\A\(//s) {
461 $want[-1] =~ s/\)\z//s or return "$tag BAD no rparen\r\n";
464 my $x = $FETCH_ATT{uc($_)} or return "$tag BAD param: $_\r\n";
469 if ($range =~ /\A([0-9]+):([0-9]+)\z/s) {
470 ($beg, $end) = ($1, $2);
471 } elsif ($range =~ /\A([0-9]+):\*\z/s) {
472 ($beg, $end) = ($1, $ibx->mm->max // 0);
473 } elsif ($range =~ /\A[0-9]+\z/) {
474 my $smsg = $ibx->over->get_art($range) or return "$tag OK\r\n";
476 ($beg, $end) = ($range, 0);
478 return "$tag BAD\r\n";
480 long_response($self, \&uid_fetch_m, $tag, $ibx,
481 \$beg, $end, $msgs, \%want);
484 sub uid_search_all { # long_response
485 my ($self, $tag, $ibx, $num) = @_;
486 my $uids = $ibx->mm->ids_after($num);
487 if (scalar(@$uids)) {
488 $self->msg_more(join(' ', '', @$uids));
490 $self->write(\"\r\n$tag OK\r\n");
495 sub uid_search_uid_range { # long_response
496 my ($self, $tag, $ibx, $beg, $end) = @_;
497 my $uids = $ibx->mm->msg_range($beg, $end, 'num');
499 $self->msg_more(join('', map { " $_->[0]" } @$uids));
501 $self->write(\"\r\n$tag OK\r\n");
506 sub cmd_uid_search ($$$;) {
507 my ($self, $tag, $arg, @rest) = @_;
508 my $ibx = $self->{ibx} or return "$tag BAD No mailbox selected\r\n";
510 if ($arg eq 'ALL' && !@rest) {
511 $self->msg_more('* SEARCH');
513 long_response($self, \&uid_search_all, $tag, $ibx, \$num);
514 } elsif ($arg eq 'UID' && scalar(@rest) == 1) {
515 if ($rest[0] =~ /\A([0-9]+):([0-9]+|\*)\z/s) {
516 my ($beg, $end) = ($1, $2);
517 $end = $ibx->mm->max if $end eq '*';
518 $self->msg_more('* SEARCH');
519 long_response($self, \&uid_search_uid_range,
520 $tag, $ibx, \$beg, $end);
521 } elsif ($rest[0] =~ /\A[0-9]+\z/s) {
523 $uid = $ibx->over->get_art($uid) ? " $uid" : '';
524 "* SEARCH$uid\r\n$tag OK\r\n";
533 sub args_ok ($$) { # duplicated from PublicInbox::NNTP
534 my ($cb, $argc) = @_;
535 my $tot = prototype $cb;
536 my ($nreq, undef) = split(';', $tot);
537 $nreq = ($nreq =~ tr/$//) - 1;
538 $tot = ($tot =~ tr/$//) - 1;
539 ($argc <= $tot && $argc >= $nreq);
542 # returns 1 if we can continue, 0 if not due to buffered writes or disconnect
543 sub process_line ($$) {
545 my ($tag, $req, @args) = parse_line('[ \t]+', 0, $l);
546 pop(@args) if (@args && !defined($args[-1]));
547 if (@args && uc($req) eq 'UID') {
548 $req .= "_".(shift @args);
551 if (my $cmd = $self->can('cmd_'.lc($req // ''))) {
552 defined($self->{-idle_tag}) ?
553 "$self->{-idle_tag} BAD expected DONE\r\n" :
554 $cmd->($self, $tag, @args);
555 } elsif (uc($tag // '') eq 'DONE' && !defined($req)) {
556 cmd_done($self, $tag);
557 } else { # this is weird
558 auth_challenge_ok($self) //
559 "$tag BAD Error in IMAP command $req: ".
560 "Unknown command\r\n";
564 if ($err && $self->{sock}) {
566 err($self, 'error from: %s (%s)', $l, $err);
567 $res = "$tag BAD program fault - command not performed\r\n";
569 return 0 unless defined $res;
575 # wbuf is unset or empty, here; {long} may add to it
576 my ($fd, $cb, $t0, @args) = @{$self->{long_cb}};
577 my $more = eval { $cb->($self, @args) };
578 if ($@ || !$self->{sock}) { # something bad happened...
579 delete $self->{long_cb};
580 my $elapsed = now() - $t0;
583 "%s during long response[$fd] - %0.6f",
586 out($self, " deferred[$fd] aborted - %0.6f", $elapsed);
588 } elsif ($more) { # $self->{wbuf}:
589 $self->update_idle_time;
591 # COMPRESS users all share the same DEFLATE context.
592 # Flush it here to ensure clients don't see
596 # no recursion, schedule another call ASAP, but only after
597 # all pending writes are done. autovivify wbuf:
598 my $new_size = push(@{$self->{wbuf}}, \&long_step);
600 # wbuf may be populated by $cb, no need to rearm if so:
601 $self->requeue if $new_size == 1;
603 delete $self->{long_cb};
604 my $elapsed = now() - $t0;
605 my $fd = fileno($self->{sock});
606 out($self, " deferred[$fd] done - %0.6f", $elapsed);
607 my $wbuf = $self->{wbuf}; # do NOT autovivify
609 $self->requeue unless $wbuf && @$wbuf;
614 my ($self, $fmt, @args) = @_;
615 printf { $self->{imapd}->{err} } $fmt."\n", @args;
619 my ($self, $fmt, @args) = @_;
620 printf { $self->{imapd}->{out} } $fmt."\n", @args;
623 sub long_response ($$;@) {
624 my ($self, $cb, @args) = @_; # cb returns true if more, false if done
626 my $sock = $self->{sock} or return;
627 # make sure we disable reading during a long response,
628 # clients should not be sending us stuff and making us do more
629 # work while we are stream a response to them
630 $self->{long_cb} = [ fileno($sock), $cb, now(), @args ];
631 long_step($self); # kick off!
635 # callback used by PublicInbox::DS for any (e)poll (in/out/hup/err)
639 return unless $self->flush_write && $self->{sock};
641 $self->update_idle_time;
642 # only read more requests if we've drained the write buffer,
643 # otherwise we can be buffering infinitely w/o backpressure
645 my $rbuf = $self->{rbuf} // (\(my $x = ''));
648 if (index($$rbuf, "\n") < 0) {
649 my $off = length($$rbuf);
650 $r = $self->do_read($rbuf, LINE_MAX, $off) or return;
652 while ($r > 0 && $$rbuf =~ s/\A[ \t]*([^\n]*?)\r?\n//) {
654 return $self->close if $line =~ /[[:cntrl:]]/s;
656 my $fd = fileno($self->{sock});
657 $r = eval { process_line($self, $line) };
658 my $pending = $self->{wbuf} ? ' pending' : '';
659 out($self, "[$fd] %s - %0.6f$pending", $line, now() - $t0);
662 return $self->close if $r < 0;
663 my $len = length($$rbuf);
664 return $self->close if ($len >= LINE_MAX);
665 $self->rbuf_idle($rbuf);
666 $self->update_idle_time;
668 # maybe there's more pipelined data, or we'll have
669 # to register it for socket-readiness notifications
670 $self->requeue unless $self->{wbuf};
673 sub compressed { undef }
675 sub zflush {} # overridden by IMAPdeflate
678 sub cmd_compress ($$$) {
679 my ($self, $tag, $alg) = @_;
680 return "$tag BAD DEFLATE only\r\n" if uc($alg) ne "DEFLATE";
681 return "$tag BAD COMPRESS active\r\n" if $self->compressed;
683 # CRIME made TLS compression obsolete
684 # return "$tag NO [COMPRESSIONACTIVE]\r\n" if $self->tls_compressed;
686 PublicInbox::IMAPdeflate->enable($self, $tag);
691 sub cmd_starttls ($$) {
692 my ($self, $tag) = @_;
693 my $sock = $self->{sock} or return;
694 if ($sock->can('stop_SSL') || $self->compressed) {
695 return "$tag BAD TLS or compression already enabled\r\n";
697 my $opt = $self->{imapd}->{accept_tls} or
698 return "$tag BAD can not initiate TLS negotiation\r\n";
699 $self->write(\"$tag OK begin TLS negotiation now\r\n");
700 $self->{sock} = IO::Socket::SSL->start_SSL($sock, %$opt);
701 $self->requeue if PublicInbox::DS::accept_tls_step($self);
705 # for graceful shutdown in PublicInbox::Daemon:
707 my ($self, $now) = @_;
708 ($self->{rbuf} || $self->{wbuf} || $self->not_idle_long($now));
713 if (my $ibx = delete $self->{ibx}) {
714 if (my $sock = $self->{sock}) {;
715 $ibx->unsubscribe_unlock(fileno($sock));
718 $self->SUPER::close; # PublicInbox::DS::close
721 # we're read-only, so SELECT and EXAMINE do the same thing
723 *cmd_select = \&cmd_examine;