]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/IMAP.pm
imap: avoid raising exception if client disconnects
[public-inbox.git] / lib / PublicInbox / IMAP.pm
index 2d0d005e6f8b71239a342669a03645c0600f82ef..d93792acf7ae94406d54999ecc1cf11c01510713 100644 (file)
@@ -300,7 +300,7 @@ sub msn2uid ($) {
 # converts a set of message sequence numbers in requests to UIDs:
 sub msn_to_uid_range ($$) {
        my $msn2uid = $_[0];
-       $_[1] =~ s!([0-9]+)!$msn2uid->[$1 - 1] // ($msn2uid->[-1] + 1)!sge;
+       $_[1] =~ s!([0-9]+)!$msn2uid->[$1 - 1] // ($msn2uid->[-1] // 0 + 1)!sge;
 }
 
 # called by PublicInbox::InboxIdle
@@ -615,18 +615,19 @@ sub fetch_run_ops {
 sub fetch_blob_cb { # called by git->cat_async via git_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
        my $smsg = shift @$msgs or die 'BUG: no smsg';
        if (!defined($oid)) {
                # it's possible to have TOCTOU if an admin runs
                # public-inbox-(edit|purge), just move onto the next message
-               warn "E: $smsg->{blob} missing in $self->{ibx}->{inboxdir}\n";
+               warn "E: $smsg->{blob} missing in $ibx->{inboxdir}\n";
                return requeue_once($self);
        } else {
                $smsg->{blob} eq $oid or die "BUG: $smsg->{blob} != $oid";
        }
        my $pre;
        if (!$self->{wbuf} && (my $nxt = $msgs->[0])) {
-               $pre = $self->{ibx}->git->async_prefetch($nxt->{blob},
+               $pre = $ibx->git->async_prefetch($nxt->{blob},
                                                \&fetch_blob_cb, $fetch_arg);
        }
        fetch_run_ops($self, $smsg, $bref, $ops, $partial);