X-Git-Url: http://cgit.sxemacs.org/?a=blobdiff_plain;f=lisp%2Fpop3.el;h=25330989e00292ff4e464b29a74580a67e603a69;hb=e2c1d571d8a1c38be0eab90ac59fe3a916ffa62d;hp=f586cf31d3f56664b3950a57c2d1bd89f63b3e92;hpb=55209c259b538b909a82ea62140435ae66443fbd;p=gnus diff --git a/lisp/pop3.el b/lisp/pop3.el index f586cf31d..25330989e 100644 --- a/lisp/pop3.el +++ b/lisp/pop3.el @@ -1,6 +1,6 @@ ;;; pop3.el --- Post Office Protocol (RFC 1460) interface -;; Copyright (C) 1996-2011 Free Software Foundation, Inc. +;; Copyright (C) 1996-2012 Free Software Foundation, Inc. ;; Author: Richard L. Pieri ;; Maintainer: FSF @@ -167,25 +167,45 @@ 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) - (unless (gnus-process-live-p process) + (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))) + (let ((size 0)) + (goto-char (point-min)) + (while (re-search-forward "^\\+OK.*\n" nil t) + (setq size (+ size (- (point)) + (if (re-search-forward "^\\.\r?\n" nil 'move) + (match-beginning 0) + (point))))) + (message "pop3 retrieved %dKB (%d%%)" + (truncate (/ size 1000)) + (truncate (* (/ (* size 1.0) total-size) 100))))) + (pop3-accept-process-output process)) + start-point) (defun pop3-write-to-file (file) (let ((pop-buffer (current-buffer)) @@ -219,17 +239,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 @@ -267,11 +276,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 @@ -308,7 +317,7 @@ Returns the process associated with the connection." (t (or pop3-stream-type 'network))) :capability-command "CAPA\r\n" - :end-of-command "^\\(-ERR\\|+OK \\).*\n" + :end-of-command "^\\(-ERR\\|+OK\\).*\n" :end-of-capability "^\\.\r?\n\\|^-ERR" :success "^\\+OK.*\n" :return-list t