]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/IMAP.pm
imap+nntp: die loudly if ->mm or ->over disappear
[public-inbox.git] / lib / PublicInbox / IMAP.pm
index 226e98a2e2a144930d221fe798d663ab3feb78ad..37e07daedeefe0edc510d215e5aa8df35a071e75 100644 (file)
@@ -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);
@@ -499,7 +500,7 @@ sub body_disposition ($) {
        my $cd = $eml->header_raw('Content-Disposition') or return 'NIL';
        $cd = parse_content_disposition($cd);
        my $buf = '('._esc($cd->{type});
-       $buf .= ' ' . _esc_hash(delete $cd->{attributes});
+       $buf .= ' ' . _esc_hash($cd->{attributes});
        $buf .= ')';
 }
 
@@ -511,7 +512,7 @@ sub body_leaf ($$;$) {
        my $ct = $eml->ct;
        $buf .= '('._esc($ct->{type}).' ';
        $buf .= _esc($ct->{subtype});
-       $buf .= ' ' . _esc_hash(delete $ct->{attributes});
+       $buf .= ' ' . _esc_hash($ct->{attributes});
        $buf .= ' ' . _esc($eml->header_raw('Content-ID'));
        $buf .= ' ' . _esc($eml->header_raw('Content-Description'));
        my $cte = $eml->header_raw('Content-Transfer-Encoding') // '7bit';
@@ -540,7 +541,7 @@ sub body_parent ($$$) {
                $buf .= @$hold ? join('', @$hold) : 'NIL';
                $buf .= ' '._esc($ct->{subtype});
                if ($structure) {
-                       $buf .= ' '._esc_hash(delete $ct->{attributes});
+                       $buf .= ' '._esc_hash($ct->{attributes});
                        $buf .= ' '.body_disposition($eml);
                        $buf .= ' '._esc($eml->header_raw('Content-Language'));
                        $buf .= ' '._esc($eml->header_raw('Content-Location'));
@@ -612,7 +613,7 @@ sub fetch_run_ops {
        $self->msg_more(")\r\n");
 }
 
-sub fetch_blob_cb { # called by git->cat_async via git_async_cat
+sub fetch_blob_cb { # called by git->cat_async via ibx_async_cat
        my ($bref, $oid, $type, $size, $fetch_arg) = @_;
        my ($self, undef, $msgs, $range_info, $ops, $partial) = @$fetch_arg;
        my $ibx = $self->{ibx} or return $self->close; # client disconnected
@@ -627,8 +628,8 @@ sub fetch_blob_cb { # called by git->cat_async via git_async_cat
        }
        my $pre;
        if (!$self->{wbuf} && (my $nxt = $msgs->[0])) {
-               $pre = git_async_prefetch($ibx->git, $nxt->{blob},
-                                               \&fetch_blob_cb, $fetch_arg);
+               $pre = ibx_async_prefetch($ibx, $nxt->{blob},
+                                       \&fetch_blob_cb, $fetch_arg);
        }
        fetch_run_ops($self, $smsg, $bref, $ops, $partial);
        $pre ? $self->zflush : requeue_once($self);
@@ -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;
        }
@@ -760,7 +761,7 @@ sub fetch_blob { # long_response
                }
        }
        uo2m_extend($self, $msgs->[-1]->{num});
-       git_async_cat($self->{ibx}->git, $msgs->[0]->{blob},
+       ibx_async_cat($self->{ibx}, $msgs->[0]->{blob},
                        \&fetch_blob_cb, \@_);
 }
 
@@ -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 ];
@@ -1228,7 +1229,7 @@ sub long_step {
        } elsif ($more) { # $self->{wbuf}:
                $self->update_idle_time;
 
-               # control passed to git_async_cat if $more == \undef
+               # control passed to ibx_async_cat if $more == \undef
                requeue_once($self) if !ref($more);
        } else { # all done!
                delete $self->{long_cb};