Spelling fixes.
[gnus] / lisp / pop3.el
index 96b2ae1..0f7a450 100644 (file)
@@ -167,23 +167,39 @@ Use streaming commands."
 
 (defun pop3-send-streaming-command (process command count total-size)
   (erase-buffer)
-  (let ((i 1))
+  (let ((i 1)
+       (start-point (point-min))
+       (waited-for 0))
     (while (>= count i)
       (process-send-string process (format "%s %d\r\n" command i))
       ;; Only do 100 messages at a time to avoid pipe stalls.
       (when (zerop (% i pop3-stream-length))
-       (pop3-wait-for-messages process i total-size))
-      (incf i)))
-  (pop3-wait-for-messages process count total-size))
-
-(defun pop3-wait-for-messages (process count total-size)
-  (while (< (pop3-number-of-responses total-size) count)
+       (setq start-point
+             (pop3-wait-for-messages process pop3-stream-length
+                                     total-size start-point))
+       (incf waited-for pop3-stream-length))
+      (incf i))
+    (pop3-wait-for-messages process (- count waited-for)
+                           total-size start-point)))
+
+(defun pop3-wait-for-messages (process count total-size start-point)
+  (while (> count 0)
+    (goto-char start-point)
+    (while (or (and (re-search-forward "^\\+OK" nil t)
+                   (or (not total-size)
+                       (re-search-forward "^\\.\r?\n" nil t)))
+              (re-search-forward "^-ERR " nil t))
+      (decf count)
+      (setq start-point (point)))
+    (unless (memq (process-status process) '(open run))
+      (error "pop3 process died"))
     (when total-size
       (message "pop3 retrieved %dKB (%d%%)"
               (truncate (/ (buffer-size) 1000))
               (truncate (* (/ (* (buffer-size) 1.0)
                               total-size) 100))))
-    (pop3-accept-process-output process)))
+    (pop3-accept-process-output process))
+  start-point)
 
 (defun pop3-write-to-file (file)
   (let ((pop-buffer (current-buffer))
@@ -217,17 +233,6 @@ Use streaming commands."
          (delete-char 1))
        (write-region (point-min) (point-max) file nil 'nomesg)))))
 
-(defun pop3-number-of-responses (endp)
-  (let ((responses 0))
-    (save-excursion
-      (goto-char (point-min))
-      (while (or (and (re-search-forward "^\\+OK" nil t)
-                     (or (not endp)
-                         (re-search-forward "^\\.\r?\n" nil t)))
-                (re-search-forward "^-ERR " nil t))
-       (incf responses)))
-    responses))
-
 (defun pop3-logon (process)
   (let ((pop3-password pop3-password))
     ;; for debugging only
@@ -265,11 +270,11 @@ Use streaming commands."
     message-count))
 
 (defcustom pop3-stream-type nil
-  "*Transport security type for POP3 connexions.
-This may be either nil (plain connexion), `ssl' (use an
+  "*Transport security type for POP3 connections.
+This may be either nil (plain connection), `ssl' (use an
 SSL/TSL-secured stream) or `starttls' (use the starttls mechanism
 to turn on TLS security after opening the stream).  However, if
-this is nil, `ssl' is assumed for connexions to port
+this is nil, `ssl' is assumed for connections to port
 995 (pop3s)."
   :version "23.1" ;; No Gnus
   :group 'pop3
@@ -302,11 +307,12 @@ Returns the process associated with the connection."
                    ((or (eq pop3-stream-type 'ssl)
                         (and (not pop3-stream-type)
                              (member port '(995 "pop3s"))))
-                    :tls)
+                    'tls)
                    (t
                     (or pop3-stream-type 'network)))
             :capability-command "CAPA\r\n"
-            :end-of-command "^\\.\r?\n\\|^\\(-ERR\\|+OK \\).*\n"
+            :end-of-command "^\\(-ERR\\|+OK\\).*\n"
+            :end-of-capability "^\\.\r?\n\\|^-ERR"
             :success "^\\+OK.*\n"
             :return-list t
             :starttls-function
@@ -319,6 +325,7 @@ Returns the process associated with the connection."
                (substring response (or (string-match "<" response) 0)
                           (+ 1 (or (string-match ">" response) -1)))))
        (pop3-set-process-query-on-exit-flag (car result) nil)
+       (erase-buffer)
        (car result)))))
 
 ;; Support functions
@@ -514,6 +521,8 @@ Otherwise, return the size of the message-id MSG"
   (let ((start pop3-read-point) end)
     (with-current-buffer (process-buffer process)
       (while (not (re-search-forward "^\\.\r\n" nil t))
+       (unless (memq (process-status process) '(open run))
+         (error "pop3 server closed the connection"))
        (pop3-accept-process-output process)
        (goto-char start))
       (setq pop3-read-point (point-marker))