+# $obj must respond to ->on_inbox_unlock, which takes Inbox ($self) as an arg
+sub subscribe_unlock {
+ my ($self, $ident, $obj) = @_;
+ $self->{unlock_subs}->{$ident} = $obj;
+}
+
+sub unsubscribe_unlock {
+ my ($self, $ident) = @_;
+ delete $self->{unlock_subs}->{$ident};
+}
+
+# called by inotify
+sub on_unlock {
+ my ($self) = @_;
+ check_inodes($self);
+ my $subs = $self->{unlock_subs} or return;
+ for my $obj (values %$subs) {
+ eval { $obj->on_inbox_unlock($self) };
+ warn "E: $@ ($self->{inboxdir})\n" if $@;
+ }
+}
+
+sub uidvalidity { $_[0]->{uidvalidity} //= eval { $_[0]->mm->created_at } }
+
+sub eidx_key { $_[0]->{newsgroup} // $_[0]->{inboxdir} }
+
+# only used by NNTP, so we need ->mm anyways
+sub art_min { $_[0]->{-art_min} //= eval { $_[0]->mm(1)->min } }
+
+# used by IMAP, too, which tries to avoid ->mm (but ->{mm} is likely
+# faster since it's smaller iff available)
+sub art_max {
+ $_[0]->{-art_max} //= eval { $_[0]->{mm}->max } //
+ eval { $_[0]->over(1)->max };
+}
+
+sub mailboxid { # rfc 8474, 8620, 8621
+ my ($self, $imap_slice) = @_;
+ my $pfx = defined($imap_slice) ? $self->{newsgroup} : $self->{name};
+ utf8::encode($pfx); # to octets
+ # RFC 8620, 1.2 recommends not starting with dash or digits
+ # "A good solution to these issues is to prefix every id with a single
+ # alphabetical character."
+ 'M'.join('', map { sprintf('%02x', ord) } split(//, $pfx)) .
+ (defined($imap_slice) ? sprintf('-%x', $imap_slice) : '') .
+ sprintf('-%x', uidvalidity($self) // 0)
+}
+
+sub thing_type { 'public inbox' }
+