about summary refs log tree commit homepage
path: root/lib/PublicInbox
diff options
context:
space:
mode:
authorEric Wong <e@yhbt.net>2020-06-27 10:03:45 +0000
committerEric Wong <e@yhbt.net>2020-06-28 22:27:21 +0000
commit5fa10d84517ffe08ac85b13961bdbd20baf3d807 (patch)
tree124d2c83419411512e8a4bfbfdfa960121987e9b /lib/PublicInbox
parent62bb26d307a106d6c9b42e36b583fd04d90a4687 (diff)
downloadpublic-inbox-5fa10d84517ffe08ac85b13961bdbd20baf3d807.tar.gz
Passing a $url parameter to every function was error-prone
and having {url} field for a short-lived object is appropriate.

This matches the version of IMAPTracker posted by
Eric W. Biederman on 2020-05-15 at:
https://public-inbox.org/meta/87ftc0c3r4.fsf_-_@x220.int.ebiederm.org/

The version I originally imported was based on the one
posted on 2019-10-09:
https://public-inbox.org/meta/874l0i9vhc.fsf_-_@x220.int.ebiederm.org/

Cc: Eric W. Biederman <ebiederm@xmission.com>
Diffstat (limited to 'lib/PublicInbox')
-rw-r--r--lib/PublicInbox/IMAPTracker.pm20
-rw-r--r--lib/PublicInbox/WatchMaildir.pm17
2 files changed, 18 insertions, 19 deletions
diff --git a/lib/PublicInbox/IMAPTracker.pm b/lib/PublicInbox/IMAPTracker.pm
index bb4a39cc..26274568 100644
--- a/lib/PublicInbox/IMAPTracker.pm
+++ b/lib/PublicInbox/IMAPTracker.pm
@@ -33,29 +33,29 @@ sub dbh_new ($) {
         $dbh;
 }
 
-sub get_last ($$) {
-        my ($self, $url) = @_;
+sub get_last ($) {
+        my ($self) = @_;
         my $sth = $self->{dbh}->prepare_cached(<<'', undef, 1);
 SELECT uid_validity, uid FROM imap_last WHERE url = ?
 
-        $sth->execute($url);
+        $sth->execute($self->{url});
         $sth->fetchrow_array;
 }
 
-sub update_last ($$$$) {
-        my ($self, $url, $validity, $last) = @_;
+sub update_last ($$$) {
+        my ($self, $validity, $last) = @_;
         my $sth = $self->{dbh}->prepare_cached(<<'');
 INSERT OR REPLACE INTO imap_last (url, uid_validity, uid)
 VALUES (?, ?, ?)
 
-        $sth->execute($url, $validity, $last);
+        $sth->execute($self->{url}, $validity, $last);
 }
 
 sub new {
-        my ($class, $dbname) = @_;
+        my ($class, $url) = @_;
 
         # original name for compatibility with old setups:
-        $dbname //= PublicInbox::Config->config_dir() . "/imap.sqlite3";
+        my $dbname = PublicInbox::Config->config_dir() . "/imap.sqlite3";
 
         # use the new XDG-compliant name for new setups:
         if (!-f $dbname) {
@@ -65,12 +65,12 @@ sub new {
         }
         if (!-f $dbname) {
                 require File::Path;
-                require File::Basename;;
+                require File::Basename;
                 File::Path::mkpath(File::Basename::dirname($dbname));
         }
 
         my $dbh = dbh_new($dbname);
-        bless { dbname => $dbname, dbh => $dbh }, $class;
+        bless { dbname => $dbname, url => $url, dbh => $dbh }, $class;
 }
 
 1;
diff --git a/lib/PublicInbox/WatchMaildir.pm b/lib/PublicInbox/WatchMaildir.pm
index f36aa20a..e0caaa56 100644
--- a/lib/PublicInbox/WatchMaildir.pm
+++ b/lib/PublicInbox/WatchMaildir.pm
@@ -335,12 +335,12 @@ sub mic_for ($$$) { # mic = Mail::IMAPClient
         $mic;
 }
 
-sub imap_import_msg ($$$$$$) {
-        my ($self, $itrk, $url, $r_uidval, $uid, $raw) = @_;
+sub imap_import_msg ($$$$$) {
+        my ($self, $itrk, $r_uidval, $uid, $raw) = @_;
         # our target audience expects LF-only, save storage
         $$raw =~ s/\r\n/\n/sg;
 
-        my $inboxes = $self->{imap}->{$url};
+        my $inboxes = $self->{imap}->{$itrk->{url}};
         if (ref($inboxes)) {
                 for my $ibx (@$inboxes) {
                         my $eml = PublicInbox::Eml->new($$raw);
@@ -348,12 +348,12 @@ sub imap_import_msg ($$$$$$) {
                 }
         } elsif ($inboxes eq 'watchspam') {
                 my $eml = PublicInbox::Eml->new($raw);
-                my $arg = [ $self, $eml, "$url UID:$uid" ];
+                my $arg = [ $self, $eml, "$itrk->{url} UID:$uid" ];
                 $self->{config}->each_inbox(\&remove_eml_i, $arg);
         } else {
                 die "BUG: destination unknown $inboxes";
         }
-        $itrk->update_last($url, $r_uidval, $uid);
+        $itrk->update_last($r_uidval, $uid);
 }
 
 sub imap_fetch_all ($$$) {
@@ -373,8 +373,8 @@ sub imap_fetch_all ($$$) {
                 return "E: $url cannot get UIDVALIDITY";
         $r_uidnext //= $mic->uidnext($mbx) //
                 return "E: $url cannot get UIDNEXT";
-        my $itrk = PublicInbox::IMAPTracker->new;
-        my ($l_uidval, $l_uid) = $itrk->get_last($url);
+        my $itrk = PublicInbox::IMAPTracker->new($url);
+        my ($l_uidval, $l_uid) = $itrk->get_last;
         $l_uidval //= $r_uidval; # first time
         $l_uid //= 1;
         if ($l_uidval != $r_uidval) {
@@ -426,8 +426,7 @@ sub imap_fetch_all ($$$) {
                         }
                         # messages get deleted, so holes appear
                         defined(my $raw = delete $r->{$uid}->{$key}) or next;
-                        imap_import_msg($self, $itrk, $url, $r_uidval, $uid,
-                                        \$raw);
+                        imap_import_msg($self, $itrk, $r_uidval, $uid, \$raw);
                         last if $self->{quit};
                 }
                 _done_for_now($self);