(gnus-point-at-bol, gnus-point-at-eol): Remove.
[gnus] / lisp / nntp.el
index 45e63a6..d452a98 100644 (file)
@@ -75,6 +75,7 @@ host.
 Direct connections:
 - `nntp-open-network-stream' (the default),
 - `nntp-open-ssl-stream',
+- `nntp-open-tls-stream',
 - `nntp-open-telnet-stream'.
 
 Indirect connections:
@@ -106,8 +107,8 @@ The default is \"rsh\", but \"ssh\" is a popular alternative.")
   "*Switches given to the rlogin command `nntp-via-rlogin-command'.
 If you use \"ssh\" for `nntp-via-rlogin-command', you may set this to
 \(\"-C\") in order to compress all data connections, otherwise set this
-to \(\"-t\") or (\"-C\" \"-t\") if the telnet command requires a pseudo-tty
-allocation on an intermediate host.")
+to \(\"-t\" \"-e\" \"none\") or (\"-C\" \"-t\" \"-e\" \"none\") if the telnet
+command requires a pseudo-tty allocation on an intermediate host.")
 
 (defvoo nntp-via-telnet-command "telnet"
   "*Telnet command used to connect to an intermediate host.
@@ -138,8 +139,8 @@ If non-nil, there will be no prompt for a login name.")
 This variable is used by the `nntp-open-via-telnet-and-telnet' method.")
 
 (defvoo nntp-large-newsgroup 50
-  "*The number of the articles which indicates a large newsgroup.
-If the number of the articles is greater than the value, verbose
+  "*The number of articles which indicates a large newsgroup.
+If the number of articles is greater than the value, verbose
 messages will be shown to indicate the current status.")
 
 (defvoo nntp-maximum-request 400
@@ -207,13 +208,6 @@ NOTE: This variable is never seen to work in Emacs 20 and XEmacs 21.")
   "*Hook run just before posting an article.  It is supposed to be used
 to insert Cancel-Lock headers.")
 
-(defvoo nntp-read-timeout (if (string-match "windows-nt\\|os/2\\|emx\\|cygwin"
-                                           (symbol-name system-type))
-                             1.0
-                           0.1)
-  "How long nntp should wait between checking for the end of output.
-Shorter values mean quicker response, but is more CPU intensive.")
-
 ;;; Internal variables.
 
 (defvar nntp-record-commands nil
@@ -261,9 +255,6 @@ Within a string, %s is replaced with the server address and %p with
 port number on server.  The program should accept IMAP commands on
 stdin and return responses to stdout.")
 
-(eval-and-compile
-  (autoload 'mail-source-read-passwd "mail-source"))
-
 \f
 
 ;;; Internal functions.
@@ -454,7 +445,7 @@ be restored and the command retried."
              (goto-char pos)
              (if (looking-at (regexp-quote command))
                  (delete-region pos (progn (forward-line 1)
-                                           (gnus-point-at-bol))))
+                                           (point-at-bol))))
              )))
       (nnheader-report 'nntp "Couldn't open connection to %s."
                       nntp-address))))
@@ -479,8 +470,7 @@ be restored and the command retried."
              (goto-char pos)
              (if (looking-at (regexp-quote command))
                  (delete-region pos (progn (forward-line 1)
-                                           (gnus-point-at-bol))))
-             )))
+                                           (point-at-bol)))))))
       (nnheader-report 'nntp "Couldn't open connection to %s."
                       nntp-address))))
 
@@ -508,7 +498,7 @@ be restored and the command retried."
          (set-buffer buffer)
          (goto-char pos)
          (if (looking-at (regexp-quote command))
-             (delete-region pos (progn (forward-line 1) (gnus-point-at-bol))))
+             (delete-region pos (progn (forward-line 1) (point-at-bol))))
          )))
       (nnheader-report 'nntp "Couldn't open connection to %s."
                       nntp-address))))
@@ -1048,9 +1038,8 @@ If SEND-IF-FORCE, only send authinfo to the server if the
           (or passwd
               nntp-authinfo-password
               (setq nntp-authinfo-password
-                    (mail-source-read-passwd
-                     (format "NNTP (%s@%s) password: "
-                             user nntp-address))))))))))
+                    (read-passwd (format "NNTP (%s@%s) password: "
+                                         user nntp-address))))))))))
 
 (defun nntp-send-nosy-authinfo ()
   "Send the AUTHINFO to the nntp server."
@@ -1059,8 +1048,8 @@ If SEND-IF-FORCE, only send authinfo to the server if the
       (nntp-send-command "^3.*\r?\n" "AUTHINFO USER" user)
       (when t                          ;???Should check if AUTHINFO succeeded
        (nntp-send-command "^2.*\r?\n" "AUTHINFO PASS"
-                          (mail-source-read-passwd "NNTP (%s@%s) password: "
-                                                   user nntp-address))))))
+                          (read-passwd (format "NNTP (%s@%s) password: "
+                                               user nntp-address)))))))
 
 (defun nntp-send-authinfo-from-file ()
   "Send the AUTHINFO to the nntp server.
@@ -1074,7 +1063,7 @@ password contained in '~/.nntp-authinfo'."
       (nntp-send-command "^3.*\r?\n" "AUTHINFO USER" (user-login-name))
       (nntp-send-command
        "^2.*\r?\n" "AUTHINFO PASS"
-       (buffer-substring (point) (progn (end-of-line) (point)))))))
+       (buffer-substring (point) (point-at-eol))))))
 
 ;;; Internal functions.
 
@@ -1153,6 +1142,10 @@ password contained in '~/.nntp-authinfo'."
 (defun nntp-open-network-stream (buffer)
   (open-network-stream "nntpd" buffer nntp-address nntp-port-number))
 
+(autoload 'format-spec "format")
+(autoload 'format-spec-make "format")
+(autoload 'open-tls-stream "tls")
+
 (defun nntp-open-ssl-stream (buffer)
   (let* ((process-connection-type nil)
         (proc (start-process "nntpd" buffer 
@@ -1165,7 +1158,19 @@ password contained in '~/.nntp-authinfo'."
     (process-kill-without-query proc)
     (save-excursion
       (set-buffer buffer)
-      (nntp-wait-for-string "^\r*20[01]")
+      (let ((nntp-connection-alist (list proc buffer nil)))
+       (nntp-wait-for-string "^\r*20[01]"))
+      (beginning-of-line)
+      (delete-region (point-min) (point))
+      proc)))
+
+(defun nntp-open-tls-stream (buffer)
+  (let ((proc (open-tls-stream "nntpd" buffer nntp-address nntp-port-number)))
+    (process-kill-without-query proc)
+    (save-excursion
+      (set-buffer buffer)
+      (let ((nntp-connection-alist (list proc buffer nil)))
+       (nntp-wait-for-string "^\r*20[01]"))
       (beginning-of-line)
       (delete-region (point-min) (point))
       proc)))
@@ -1299,12 +1304,7 @@ password contained in '~/.nntp-authinfo'."
       (unless (< len 10)
        (setq nntp-have-messaged t)
        (nnheader-message 7 "nntp read: %dk" len)))
-    (accept-process-output
-     process
-     (truncate nntp-read-timeout)
-     (truncate (* (- nntp-read-timeout
-                    (truncate nntp-read-timeout))
-                 1000)))
+    (nnheader-accept-process-output process)
     ;; accept-process-output may update status of process to indicate
     ;; that the server has closed the connection.  This MUST be
     ;; handled here as the buffer restored by the save-excursion may
@@ -1329,16 +1329,18 @@ password contained in '~/.nntp-authinfo'."
 
   (when group
     (let ((entry (nntp-find-connection-entry nntp-server-buffer)))
-      (when (not (equal group (caddr entry)))
-       (save-excursion
-         (set-buffer (process-buffer (car entry)))
-         (erase-buffer)
-         (nntp-send-command "^[245].*\n" "GROUP" group)
-         (setcar (cddr entry) group)
-         (erase-buffer)
-         (save-excursion
-           (set-buffer nntp-server-buffer)
-           (erase-buffer)))))))
+      (cond ((not entry)
+             (nntp-report "Server closed connection"))
+            ((not (equal group (caddr entry)))
+             (save-excursion
+               (set-buffer (process-buffer (car entry)))
+               (erase-buffer)
+               (nntp-send-command "^[245].*\n" "GROUP" group)
+               (setcar (cddr entry) group)
+               (erase-buffer)
+               (save-excursion
+                 (set-buffer nntp-server-buffer)
+                 (erase-buffer))))))))
 
 (defun nntp-decode-text (&optional cr-only)
   "Decode the text in the current buffer."
@@ -1422,8 +1424,7 @@ password contained in '~/.nntp-authinfo'."
          in-process-buffer-p
          (buf nntp-server-buffer)
          (process-buffer (nntp-find-connection-buffer nntp-server-buffer))
-         first
-          last)
+         first last status)
       ;; We have to check `nntp-server-xover'.  If it gets set to nil,
       ;; that means that the server does not understand XOVER, but we
       ;; won't know that until we try.
@@ -1457,15 +1458,22 @@ password contained in '~/.nntp-authinfo'."
            (while (progn
                     (goto-char (or last-point (point-min)))
                     ;; Count replies.
-                    (while (re-search-forward "^[0-9][0-9][0-9] .*\n" nil t)
-                      (incf received))
+                    (while (re-search-forward "^\\([0-9][0-9][0-9]\\) .*\n"
+                                              nil t)
+                      (incf received)
+                      (setq status (match-string 1))
+                      (if (string-match "^[45]" status)
+                          (setq status 'error)
+                        (setq status 'ok)))
                     (setq last-point (point))
                     (or (< received count)
-                        ;; I haven't started reading the final response
-                         (progn
-                           (goto-char (point-max))
-                           (forward-line -1)
-                           (not (looking-at "^\\.\r?\n")))))
+                        (if (eq status 'error)
+                            nil
+                          ;; I haven't started reading the final response
+                          (progn
+                            (goto-char (point-max))
+                            (forward-line -1)
+                            (not (looking-at "^\\.\r?\n"))))))
              ;; I haven't read the end of the final response
              (nntp-accept-response)
              (set-buffer process-buffer))))
@@ -1683,7 +1691,7 @@ via telnet.")
         proc (concat
               (or nntp-telnet-passwd
                   (setq nntp-telnet-passwd
-                        (mail-source-read-passwd "Password: ")))
+                        (read-passwd "Password: ")))
               "\n"))
        (nntp-wait-for-string nntp-telnet-shell-prompt)
        (process-send-string
@@ -1783,7 +1791,15 @@ Please refer to the following variables to customize the connection:
       (nntp-wait-for-string "^\r*20[01]")
       (beginning-of-line)
       (delete-region (point-min) (point))
-      proc)))
+      (process-send-string proc "\^]")
+      (nntp-wait-for-string "^r?telnet")
+      (process-send-string proc "mode character\n")
+      (accept-process-output proc 1)
+      (sit-for 1)
+      (goto-char (point-min))
+      (forward-line 1)
+      (delete-region (point) (point-max)))
+    proc))
 
 (defun nntp-open-via-telnet-and-telnet (buffer)
   "Open a connection to an nntp server through an intermediate host.
@@ -1835,8 +1851,7 @@ Please refer to the following variables to customize the connection:
                             (concat
                              (or nntp-via-user-password
                                  (setq nntp-via-user-password
-                                       (mail-source-read-passwd
-                                        "Password: ")))
+                                       (read-passwd "Password: ")))
                              "\n"))
        (nntp-wait-for-string nntp-via-shell-prompt)
        (let ((real-telnet-command `("exec"