+sub max {
+ my ($self) = @_;
+ my $sth = $self->connect->prepare_cached(<<'', undef, 1);
+SELECT MAX(num) FROM over WHERE num > 0
+
+ $sth->execute;
+ $sth->fetchrow_array // 0;
+}
+
+sub imap_exists {
+ my ($self, $uid_base, $uid_end) = @_;
+ my $sth = $self->connect->prepare_cached(<<'', undef, 1);
+SELECT COUNT(num) FROM over WHERE num > ? AND num <= ?
+
+ $sth->execute($uid_base, $uid_end);
+ $sth->fetchrow_array;
+}
+
+sub check_inodes {
+ my ($self) = @_;
+ my $dbh = $self->{dbh} or return;
+ my $f = $dbh->sqlite_db_filename;
+ if (my @st = stat($f)) { # did st_dev, st_ino change?
+ my $st = pack('dd', $st[0], $st[1]);
+
+ # don't actually reopen, just let {dbh} be recreated later
+ disconnect($self) if $st ne ($self->{st} // $st);
+ } else {
+ warn "W: stat $f: $!\n";
+ }
+}
+