Importing Gnus v5.8.3.
[elisp/gnus.git-] / lisp / pop3.el
index c19a77f..4aafc48 100644 (file)
@@ -71,6 +71,8 @@ Used for APOP authentication.")
         (n 1)
         message-count
         (pop3-password pop3-password)
+        ;; use Unix line endings for crashbox
+        (coding-system-for-write 'binary)
         )
     ;; for debugging only
     (if pop3-debug (switch-to-buffer (process-buffer process)))
@@ -107,15 +109,37 @@ Used for APOP authentication.")
     )
   t)
 
+(defun pop3-get-message-count ()
+  "Return the number of messages in the maildrop."
+  (let* ((process (pop3-open-server pop3-mailhost pop3-port))
+        message-count
+        (pop3-password pop3-password)
+        )
+    ;; for debugging only
+    (if pop3-debug (switch-to-buffer (process-buffer process)))
+    ;; query for password
+    (if (and pop3-password-required (not pop3-password))
+       (setq pop3-password
+             (pop3-read-passwd (format "Password for %s: " pop3-maildrop))))
+    (cond ((equal 'apop pop3-authentication-scheme)
+          (pop3-apop process pop3-maildrop))
+         ((equal 'pass pop3-authentication-scheme)
+          (pop3-user process pop3-maildrop)
+          (pop3-pass process))
+         (t (error "Invalid POP3 authentication scheme.")))
+    (setq message-count (car (pop3-stat process)))
+    (pop3-quit process)
+    message-count))
+
 (defun pop3-open-server (mailhost port)
   "Open TCP connection to MAILHOST.
 Returns the process associated with the connection."
   (let ((process-buffer
         (get-buffer-create (format "trace of POP session to %s" mailhost)))
        (process)
-       (coding-system-for-read 'binary)   ;; because FSF Emacs 20 and
-       (coding-system-for-write 'binary)  ;; XEmacs 20 & 21 are st00pid
-    )
+       (coding-system-for-read 'binary);; because FSF Emacs 20 and
+       (coding-system-for-write 'binary);; XEmacs 20 & 21 are st00pid
+       )
     (save-excursion
       (set-buffer process-buffer)
       (erase-buffer)
@@ -139,15 +163,15 @@ Returns the process associated with the connection."
     (insert output)))
 
 (defun pop3-send-command (process command)
-    (set-buffer (process-buffer process))
-    (goto-char (point-max))
-;;    (if (= (aref command 0) ?P)
-;;     (insert "PASS <omitted>\r\n")
-;;      (insert command "\r\n"))
-    (setq pop3-read-point (point))
-    (goto-char (point-max))
-    (process-send-string process (concat command "\r\n"))
-    )
+  (set-buffer (process-buffer process))
+  (goto-char (point-max))
+  ;;    (if (= (aref command 0) ?P)
+  ;;   (insert "PASS <omitted>\r\n")
+  ;;      (insert command "\r\n"))
+  (setq pop3-read-point (point))
+  (goto-char (point-max))
+  (process-send-string process (concat command "\r\n"))
+  )
 
 (defun pop3-read-response (process &optional return)
   "Read the response from the server.
@@ -317,16 +341,16 @@ This function currently does nothing.")
        ;; bill@att.com
        ;; condensed into:
        ;; (sometimes causes problems for really large messages.)
-;      (if (> (buffer-size) 20000) (sleep-for (/ (buffer-size) 20000)))
+       ;;      (if (> (buffer-size) 20000) (sleep-for (/ (buffer-size) 20000)))
        (goto-char start))
       (setq pop3-read-point (point-marker))
-;; this code does not seem to work for some POP servers...
-;; and I cannot figure out why not.
-;      (goto-char (match-beginning 0))
-;      (backward-char 2)
-;      (if (not (looking-at "\r\n"))
-;        (insert "\r\n"))
-;      (re-search-forward "\\.\r\n")
+      ;; this code does not seem to work for some POP servers...
+      ;; and I cannot figure out why not.
+      ;;      (goto-char (match-beginning 0))
+      ;;      (backward-char 2)
+      ;;      (if (not (looking-at "\r\n"))
+      ;;         (insert "\r\n"))
+      ;;      (re-search-forward "\\.\r\n")
       (goto-char (match-beginning 0))
       (setq end (point-marker))
       (pop3-clean-region start end)