about summary refs log tree commit homepage
path: root/lib/PublicInbox/IMAP.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-08-24 22:49:24 +0000
committerEric Wong <e@80x24.org>2021-08-25 08:00:08 +0000
commit796e7215a167f36d0b950631c3b1e44fa47fec07 (patch)
tree163bd59dc121be1b032e18db69421f9600cede35 /lib/PublicInbox/IMAP.pm
parent5a27f82749d723625848c8d1cf216a0f4de73597 (diff)
downloadpublic-inbox-796e7215a167f36d0b950631c3b1e44fa47fec07.tar.gz
imap+nntp: die loudly if ->mm or ->over disappear
While the WWW front-end can gracefully handle ->mm and ->over
disappearing (in most cases), IMAP+NNTP front-ends are completely
dependent on these and failed mysteriously when they go missing
after startup.

These will hopefully make issues like what Konstantin
encountered more obvious:

Link: https://public-inbox.org/meta/20210824204855.ejspej4z7r2rpu63@nitro.local/
Diffstat (limited to 'lib/PublicInbox/IMAP.pm')
-rw-r--r--lib/PublicInbox/IMAP.pm25
1 files changed, 13 insertions, 12 deletions
diff --git a/lib/PublicInbox/IMAP.pm b/lib/PublicInbox/IMAP.pm
index 9402aa41..37e07dae 100644
--- a/lib/PublicInbox/IMAP.pm
+++ b/lib/PublicInbox/IMAP.pm
@@ -195,14 +195,14 @@ sub cmd_capability ($$) {
 # but uo2m_hibernate can compact and deduplicate it
 sub uo2m_ary_new ($;$) {
         my ($self, $exists) = @_;
-        my $base = $self->{uid_base};
-        my $uids = $self->{ibx}->over->uid_range($base + 1, $base + UID_SLICE);
+        my $ub = $self->{uid_base};
+        my $uids = $self->{ibx}->over(1)->uid_range($ub + 1, $ub + UID_SLICE);
 
         # convert UIDs to offsets from {base}
         my @tmp; # [$UID_OFFSET] => $MSN
         my $msn = 0;
-        ++$base;
-        $tmp[$_ - $base] = ++$msn for @$uids;
+        ++$ub;
+        $tmp[$_ - $ub] = ++$msn for @$uids;
         $$exists = $msn if $exists;
         \@tmp;
 }
@@ -243,7 +243,7 @@ sub uo2m_extend ($$;$) {
         # need to extend the current range:
         my $base = $self->{uid_base};
         ++$beg;
-        my $uids = $self->{ibx}->over->uid_range($beg, $base + UID_SLICE);
+        my $uids = $self->{ibx}->over(1)->uid_range($beg, $base + UID_SLICE);
         return $uo2m if !scalar(@$uids);
         my @tmp; # [$UID_OFFSET] => $MSN
         my $write_method = $_[2] // 'msg_more';
@@ -342,7 +342,7 @@ sub cmd_idle ($$) {
         my $fd = fileno($sock);
         $self->{-idle_tag} = $tag;
         # only do inotify on most recent slice
-        if ($ibx->over->max < $uid_end) {
+        if ($ibx->over(1)->max < $uid_end) {
                 $ibx->subscribe_unlock($fd, $self);
                 $self->{imapd}->idler_start;
         }
@@ -393,7 +393,7 @@ sub inbox_lookup ($$;$) {
         my ($ibx, $exists, $uidmax, $uid_base) = (undef, 0, 0, 0);
         $mailbox = lc $mailbox;
         $ibx = $self->{imapd}->{mailboxes}->{$mailbox} or return;
-        my $over = $ibx->over;
+        my $over = $ibx->over(1);
         if ($over != $ibx) { # not a dummy
                 $mailbox =~ /\.([0-9]+)\z/ or
                                 die "BUG: unexpected dummy mailbox: $mailbox\n";
@@ -418,7 +418,8 @@ sub inbox_lookup ($$;$) {
                 # if "INBOX.foo.bar" is selected and "INBOX.foo.bar.0",
                 # check for new UID ranges (e.g. "INBOX.foo.bar.1")
                 if (my $z = $self->{imapd}->{mailboxes}->{"$mailbox.0"}) {
-                        ensure_slices_exist($self->{imapd}, $z, $z->over->max);
+                        ensure_slices_exist($self->{imapd}, $z,
+                                                $z->over(1)->max);
                 }
         }
         ($ibx, $exists, $uidmax + 1, $uid_base);
@@ -722,7 +723,7 @@ sub range_step ($$) {
                 uid_clamp($self, \$beg, \$end);
         } elsif ($range =~ /\A([0-9]+):\*\z/) {
                 $beg = $1 + 0;
-                $end = $self->{ibx}->over->max;
+                $end = $self->{ibx}->over(1)->max;
                 $end = $uid_end if $end > $uid_end;
                 $beg = $end if $beg > $end;
                 uid_clamp($self, \$beg, \$end);
@@ -740,7 +741,7 @@ sub range_step ($$) {
 sub refill_range ($$$) {
         my ($self, $msgs, $range_info) = @_;
         my ($beg, $end, $range_csv) = @$range_info;
-        if (scalar(@$msgs = @{$self->{ibx}->over->query_xover($beg, $end)})) {
+        if (scalar(@$msgs = @{$self->{ibx}->over(1)->query_xover($beg, $end)})){
                 $range_info->[0] = $msgs->[-1]->{num} + 1;
                 return;
         }
@@ -781,7 +782,7 @@ sub fetch_smsg { # long_response
 sub refill_uids ($$$;$) {
         my ($self, $uids, $range_info, $sql) = @_;
         my ($beg, $end, $range_csv) = @$range_info;
-        my $over = $self->{ibx}->over;
+        my $over = $self->{ibx}->over(1);
         while (1) {
                 if (scalar(@$uids = @{$over->uid_range($beg, $end, $sql)})) {
                         $range_info->[0] = $uids->[-1] + 1; # update $beg
@@ -1114,7 +1115,7 @@ sub parse_imap_query ($$) {
         my ($self, $query) = @_;
         my $q = PublicInbox::IMAPsearchqp::parse($self, $query);
         if (ref($q)) {
-                my $max = $self->{ibx}->over->max;
+                my $max = $self->{ibx}->over(1)->max;
                 my $beg = 1;
                 uid_clamp($self, \$beg, \$max);
                 $q->{range_info} = [ $beg, $max ];