1 # Copyright (C) 2018-2020 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3 package PublicInbox::IMAPTracker;
7 use PublicInbox::Config;
9 sub create_tables ($) {
13 CREATE TABLE IF NOT EXISTS imap_last (
14 url VARCHAR PRIMARY KEY NOT NULL,
15 uid_validity INTEGER NOT NULL,
24 my $dbh = DBI->connect("dbi:SQLite:dbname=$dbname", '', '', {
28 sqlite_use_immediate_transaction => 1,
30 $dbh->{sqlite_unicode} = 1;
31 $dbh->do('PRAGMA journal_mode = TRUNCATE');
37 my ($self, $url) = @_;
38 my $sth = $self->{dbh}->prepare_cached(<<'', undef, 1);
39 SELECT uid_validity, uid FROM imap_last WHERE url = ?
45 sub update_last ($$$$) {
46 my ($self, $url, $validity, $last) = @_;
47 my $sth = $self->{dbh}->prepare_cached(<<'');
48 INSERT OR REPLACE INTO imap_last (url, uid_validity, uid)
51 $sth->execute($url, $validity, $last);
56 my $dbname = PublicInbox::Config->config_dir() . "/imap.sqlite3";
57 my $dbh = dbh_new($dbname);
58 bless { dbname => $dbname, dbh => $dbh }, $class;