diff --git a/lisp/gnus/nnimap.el b/lisp/gnus/nnimap.el index d797e893f5..bceba574ca 100644 --- a/lisp/gnus/nnimap.el +++ b/lisp/gnus/nnimap.el @@ -407,8 +407,19 @@ nnimap-keepalive (time-subtract now (nnimap-last-command-time nnimap-object)))) - (ignore-errors ;E.g. "buffer foo has no process". - (nnimap-send-command "NOOP")))))))) + (ignore-errors + (nnimap-send-command "NOOP")) + ;; If our connection has died in the meantime, clean it + ;; and its buffer up. + (unless (memq (process-status (get-buffer-process buffer)) + '(open run)) + (setq nnimap-process-buffers + (delq buffer nnimap-process-buffers)) + (setq nnimap-connection-alist + (seq-filter (lambda (elt) + (null (eq buffer (cdr elt))) + nnimap-connection-alist))) + (kill-buffer buffer)))))))) (defun nnimap-open-connection (buffer) ;; Be backwards-compatible -- the earlier value of nnimap-stream was @@ -1910,6 +1921,10 @@ nnimap-find-connection '(open run))) (get-buffer-process (cadr entry)) (setq nnimap-connection-alist (delq entry nnimap-connection-alist)) + (setq nnimap-process-buffers + (delq (cadr entry) nnimap-process-buffers)) + (when (buffer-live-p (cadr entry)) + (kill-buffer (cadr entry))) nil)))) ;; Leave room for `open-network-stream' to issue a couple of IMAP