Importing Pterodactyl Gnus v0.97.
[elisp/gnus.git-] / lisp / nntp.el
index 816b98f..507733a 100644 (file)
@@ -292,6 +292,11 @@ noticing asynchronous data.")
       (unless discard
        (erase-buffer)))))
 
+(defun nntp-kill-buffer (buffer)
+  (when (buffer-name buffer)
+    (kill-buffer buffer)
+    (nnheader-init-server-buffer)))
+
 (defsubst nntp-find-connection (buffer)
   "Find the connection delivering to BUFFER."
   (let ((alist nntp-connection-alist)
@@ -304,8 +309,7 @@ noticing asynchronous data.")
     (when process
       (if (memq (process-status process) '(open run))
          process
-       (when (buffer-name (process-buffer process))
-         (kill-buffer (process-buffer process)))
+       (nntp-kill-buffer (process-buffer process))
        (setq nntp-connection-alist (delq entry nntp-connection-alist))
        nil))))
 
@@ -476,64 +480,65 @@ noticing asynchronous data.")
 (deffoo nntp-retrieve-groups (groups &optional server)
   "Retrieve group info on GROUPS."
   (nntp-possibly-change-group nil server)
-  (save-excursion
-    (set-buffer (nntp-find-connection-buffer nntp-server-buffer))
-    ;; The first time this is run, this variable is `try'.  So we
-    ;; try.
-    (when (eq nntp-server-list-active-group 'try)
-      (nntp-try-list-active (car groups)))
-    (erase-buffer)
-    (let ((count 0)
-         (received 0)
-         (last-point (point-min))
-         (nntp-inhibit-erase t)
-         (command (if nntp-server-list-active-group "LIST ACTIVE" "GROUP")))
-      (while groups
-       ;; Send the command to the server.
-       (nntp-send-command nil command (pop groups))
-       (incf count)
-       ;; Every 400 requests we have to read the stream in
-       ;; order to avoid deadlocks.
-       (when (or (null groups)         ;All requests have been sent.
-                 (zerop (% count nntp-maximum-request)))
-         (nntp-accept-response)
-         (while (progn
-                  (goto-char last-point)
-                  ;; Count replies.
-                  (while (re-search-forward "^[0-9]" nil t)
-                    (incf received))
-                  (setq last-point (point))
-                  (< received count))
-           (nntp-accept-response))))
+  (when (nntp-find-connection-buffer nntp-server-buffer)
+    (save-excursion
+      (set-buffer (nntp-find-connection-buffer nntp-server-buffer))
+      ;; The first time this is run, this variable is `try'.  So we
+      ;; try.
+      (when (eq nntp-server-list-active-group 'try)
+       (nntp-try-list-active (car groups)))
+      (erase-buffer)
+      (let ((count 0)
+           (received 0)
+           (last-point (point-min))
+           (nntp-inhibit-erase t)
+           (command (if nntp-server-list-active-group "LIST ACTIVE" "GROUP")))
+       (while groups
+         ;; Send the command to the server.
+         (nntp-send-command nil command (pop groups))
+         (incf count)
+         ;; Every 400 requests we have to read the stream in
+         ;; order to avoid deadlocks.
+         (when (or (null groups)       ;All requests have been sent.
+                   (zerop (% count nntp-maximum-request)))
+           (nntp-accept-response)
+           (while (progn
+                    (goto-char last-point)
+                    ;; Count replies.
+                    (while (re-search-forward "^[0-9]" nil t)
+                      (incf received))
+                    (setq last-point (point))
+                    (< received count))
+             (nntp-accept-response))))
 
-      ;; Wait for the reply from the final command.
-      (goto-char (point-max))
-      (re-search-backward "^[0-9]" nil t)
-      (when (looking-at "^[23]")
-       (while (progn
-                (goto-char (point-max))
-                (if (not nntp-server-list-active-group)
-                    (not (re-search-backward "\r?\n" (- (point) 3) t))
-                  (not (re-search-backward "^\\.\r?\n" (- (point) 4) t))))
-         (nntp-accept-response)))
-
-      ;; Now all replies are received.  We remove CRs.
-      (goto-char (point-min))
-      (while (search-forward "\r" nil t)
-       (replace-match "" t t))
+       ;; Wait for the reply from the final command.
+       (goto-char (point-max))
+       (re-search-backward "^[0-9]" nil t)
+       (when (looking-at "^[23]")
+         (while (progn
+                  (goto-char (point-max))
+                  (if (not nntp-server-list-active-group)
+                      (not (re-search-backward "\r?\n" (- (point) 3) t))
+                    (not (re-search-backward "^\\.\r?\n" (- (point) 4) t))))
+           (nntp-accept-response)))
 
-      (if (not nntp-server-list-active-group)
-         (progn
-           (copy-to-buffer nntp-server-buffer (point-min) (point-max))
-           'group)
-       ;; We have read active entries, so we just delete the
-       ;; superfluous gunk.
+       ;; Now all replies are received.  We remove CRs.
        (goto-char (point-min))
-       (while (re-search-forward "^[.2-5]" nil t)
-         (delete-region (match-beginning 0)
-                        (progn (forward-line 1) (point))))
-       (copy-to-buffer nntp-server-buffer (point-min) (point-max))
-       'active))))
+       (while (search-forward "\r" nil t)
+         (replace-match "" t t))
+
+       (if (not nntp-server-list-active-group)
+           (progn
+             (copy-to-buffer nntp-server-buffer (point-min) (point-max))
+             'group)
+         ;; We have read active entries, so we just delete the
+         ;; superfluous gunk.
+         (goto-char (point-min))
+         (while (re-search-forward "^[.2-5]" nil t)
+           (delete-region (match-beginning 0)
+                          (progn (forward-line 1) (point))))
+         (copy-to-buffer nntp-server-buffer (point-min) (point-max))
+         'active)))))
 
 (deffoo nntp-retrieve-articles (articles &optional group server)
   (nntp-possibly-change-group group server)
@@ -695,8 +700,7 @@ noticing asynchronous data.")
            ;; QUIT command actually is sent out before we kill
            ;; the process.
            (sleep-for 1))))
-      (when (buffer-name (process-buffer process))
-       (kill-buffer (process-buffer process)))
+      (nntp-kill-buffer (process-buffer process))
       (setq process (car (pop nntp-connection-alist))))
     (nnoo-close-server 'nntp)))
 
@@ -712,8 +716,7 @@ noticing asynchronous data.")
            ;; QUIT command actually is sent out before we kill
            ;; the process.
            (sleep-for 1))))
-      (when (buffer-name (process-buffer process))
-       (kill-buffer (process-buffer process))))))
+      (nntp-kill-buffer (process-buffer process)))))
 
 (deffoo nntp-request-list (&optional server)
   (nntp-possibly-change-group nil server)
@@ -845,8 +848,7 @@ password contained in '~/.nntp-authinfo'."
               (nnheader-run-at-time
                nntp-connection-timeout nil
                `(lambda ()
-                  (when (buffer-name ,pbuffer)
-                    (kill-buffer ,pbuffer))))))
+                  (nntp-kill-buffer ,pbuffer)))))
         (process
          (condition-case ()
              (let ((coding-system-for-read nntp-coding-system-for-read)
@@ -872,8 +874,7 @@ password contained in '~/.nntp-authinfo'."
              (let ((nnheader-callback-function nil))
                (run-hooks 'nntp-server-opened-hook)
                (nntp-send-authinfo t))))
-       (when (buffer-name (process-buffer process))
-         (kill-buffer (process-buffer process)))
+       (nntp-kill-buffer (process-buffer process))
        nil))))
 
 (defun nntp-open-network-stream (buffer)
@@ -1256,7 +1257,6 @@ password contained in '~/.nntp-authinfo'."
                   (setq nntp-telnet-passwd
                         (mail-source-read-passwd "Password: ")))
               "\n"))
-       (erase-buffer)
        (nntp-wait-for-string nntp-telnet-shell-prompt)
        (process-send-string
         proc (concat (mapconcat 'identity nntp-telnet-parameters " ") "\n"))