-;; Copyright (C) 1987,88,89,90,92,93,94,95,96 Free Software Foundation, Inc.
+;;; Copyright (C) 1987,88,89,90,92,93,94,95,96 Free Software Foundation, Inc.
;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
;; Keywords: news
(defvoo nntp-port-number "nntp"
"Port number on the physical nntp server.")
-(defvoo nntp-server-opened-hook nil
+(defvoo nntp-server-opened-hook '(nntp-send-mode-reader)
"*Hook used for sending commands to the server at startup.
The default value is `nntp-send-mode-reader', which makes an innd
server spawn an nnrpd server. Another useful function to put in this
hook might be `nntp-send-authinfo', which will prompt for a password
to allow posting from the server. Note that this is only necessary to
-do on servers that use strict access control.")
-(add-hook 'nntp-server-opened-hook 'nntp-send-mode-reader)
+do on servers that use strict access control.")
(defvoo nntp-authinfo-function 'nntp-send-authinfo
"Function used to send AUTHINFO to the server.")
(defvoo nntp-server-action-alist
'(("nntpd 1\\.5\\.11t"
- (remove-hook 'nntp-server-opened-hook 'nntp-send-mode-reader)))
+ (remove-hook 'nntp-server-opened-hook 'nntp-send-mode-reader))
+ ("NNRP server Netscape"
+ (setq nntp-server-list-active-group nil)))
"Alist of regexps to match on server types and actions to be taken.
For instance, if you want Gnus to beep every time you connect
to innd, you could say something like:
(defvoo nntp-xover-commands '("XOVER" "XOVERVIEW")
"*List of strings that are used as commands to fetch NOV lines from a server.
-The strings are tried in turn until a positive response is gotten. If
+The strings are tried in turn until a positive response is gotten. If
none of the commands are successful, nntp will just grab headers one
by one.")
have an account at the machine \"other.machine\". This machine has
access to an NNTP server that you can't access locally. You could
then use this hook to rsh to the remote machine and start a proxy NNTP
-server there that you can connect to. See also `nntp-open-connection-function'")
+server there that you can connect to. See also `nntp-open-connection-function'")
(defvoo nntp-warn-about-losing-connection t
"*If non-nil, beep when a server closes connection.")
(defvar nntp-process-start-point nil)
(defvar nntp-inside-change-function nil)
+(defvar nntp-connection-list nil)
+
(defvoo nntp-server-type nil)
(defvoo nntp-connection-alist nil)
(defvoo nntp-status-string "")
(save-excursion
(set-buffer (nntp-find-connection-buffer nntp-server-buffer))
(erase-buffer)
- (if (and (not gnus-nov-is-evil)
+ (if (and (not gnus-nov-is-evil)
(not nntp-nov-is-evil)
(nntp-retrieve-headers-with-xover articles fetch-old))
;; We successfully retrieved the headers via XOVER.
(count 0)
(received 0)
(last-point (point-min))
+ (buf (nntp-find-connection-buffer nntp-server-buffer))
(nntp-inhibit-erase t))
;; Send HEAD command.
(while articles
(nntp-send-command
nil
- "HEAD" (if (numberp (car articles))
+ "HEAD" (if (numberp (car articles))
(int-to-string (car articles))
;; `articles' is either a list of article numbers
;; or a list of article IDs.
(zerop (% count nntp-maximum-request)))
(nntp-accept-response)
(while (progn
- (goto-char last-point)
+ (progn
+ (set-buffer buf)
+ (goto-char last-point))
;; Count replies.
(while (re-search-forward "^[0-9]" nil t)
- (setq received (1+ received)))
+ (incf received))
(setq last-point (point))
(< received count))
;; If number of headers is greater than 100, give
(command (if nntp-server-list-active-group "LIST ACTIVE" "GROUP")))
(while groups
;; Send the command to the server.
- (nntp-send-command nil command (car groups))
- (setq groups (cdr groups))
- (setq count (1+ count))
+ (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.
(goto-char last-point)
;; Count replies.
(while (re-search-forward "^[0-9]" nil t)
- (setq received (1+ received)))
+ (incf received))
(setq last-point (point))
(< received count))
(nntp-accept-response))))
;; Wait for the reply from the final command.
- (when nntp-server-list-active-group
- (goto-char (point-max))
- (re-search-backward "^[0-9]" nil t)
- (when (looking-at "^[23]")
- (while (progn
- (goto-char (- (point-max) 3))
- (not (looking-at "^\\.\r?\n")))
- (nntp-accept-response))))
-
- ;; Now all replies are received. We remove CRs.
+ (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))
(if (not nntp-server-list-active-group)
- 'group
+ (progn
+ (copy-to-buffer nntp-server-buffer (point-min) (point-max))
+ 'group)
;; We have read active entries, so we just delete the
- ;; superfluos gunk.
+ ;; superfluous gunk.
(goto-char (point-min))
(while (re-search-forward "^[.2-5]" nil t)
- (delete-region (match-beginning 0)
+ (delete-region (match-beginning 0)
(progn (forward-line 1) (point))))
(copy-to-buffer nntp-server-buffer (point-min) (point-max))
'active))))
(defun nntp-try-list-active (group)
(nntp-list-active-group group)
(save-excursion
+ (set-buffer nntp-server-buffer)
(goto-char (point-min))
(cond ((looking-at "5[0-9]+")
(setq nntp-server-list-active-group nil))
(deffoo nntp-list-active-group (group &optional server)
"Return the active info on GROUP (which can be a regexp."
- (nntp-possibly-change-group group server)
+ (nntp-possibly-change-group nil server)
(nntp-send-command "^.*\r?\n" "LIST ACTIVE" group))
(deffoo nntp-request-article (article &optional group server buffer command)
(kill-buffer (process-buffer process))))
(nnoo-close-server 'nntp)))
+(deffoo nntp-request-close ()
+ (let (process)
+ (while (setq process (pop nntp-connection-list))
+ (when (memq (process-status process) '(open run))
+ (set-process-sentinel process nil)
+ (nntp-send-string process "QUIT"))
+ (when (buffer-name (process-buffer process))
+ (kill-buffer (process-buffer process))))))
+
(deffoo nntp-request-list (&optional server)
(nntp-possibly-change-group nil server)
(nntp-send-command-and-decode "\r?\n\\.\r?\n" "LIST"))
(let* ((date (timezone-parse-date date))
(time-string
(format "%s%02d%02d %s%s%s"
- (substring (aref date 0) 2) (string-to-int (aref date 1))
+ (substring (aref date 0) 2) (string-to-int (aref date 1))
(string-to-int (aref date 2)) (substring (aref date 3) 0 2)
(substring
(aref date 3) 3 5) (substring (aref date 3) 6 8))))
(set-buffer nntp-server-buffer)
(erase-buffer)))
(nntp-retrieve-data
- (mapconcat 'identity strings " ")
+ (mapconcat 'identity strings " ")
nntp-address nntp-port-number nntp-server-buffer
wait-for nnheader-callback-function))
(defun nntp-send-command-nodelete (wait-for &rest strings)
"Send STRINGS to server and wait until WAIT-FOR returns."
(nntp-retrieve-data
- (mapconcat 'identity strings " ")
+ (mapconcat 'identity strings " ")
nntp-address nntp-port-number nntp-server-buffer
wait-for nnheader-callback-function))
(set-buffer nntp-server-buffer)
(erase-buffer)))
(nntp-retrieve-data
- (mapconcat 'identity strings " ")
+ (mapconcat 'identity strings " ")
nntp-address nntp-port-number nntp-server-buffer
wait-for nnheader-callback-function t))
(nntp-wait-for process "^.*\n" buffer)
(if (memq (process-status process) '(open run))
(prog1
- (caar (push (list process buffer nil)
+ (caar (push (list process buffer nil)
nntp-connection-alist))
- (nntp-read-server-type)
- (run-hooks 'nntp-server-opened-hook))
+ (push process nntp-connection-list)
+ (save-excursion
+ (set-buffer nntp-server-buffer)
+ (nntp-read-server-type)
+ (run-hooks 'nntp-server-opened-hook)))
(when (buffer-name (process-buffer process))
(kill-buffer (process-buffer process)))
nil))))
(setq nntp-server-type (buffer-string))
(let ((alist nntp-server-action-alist)
entry)
- ;; Run server-specific commmands.
+ ;; Run server-specific commands.
(while alist
(setq entry (pop alist))
(when (string-match (car entry) nntp-server-type)
(eval (cadr entry))
(funcall (cadr entry)))))))
-(defun nntp-after-change-function (beg end len)
+(defun nntp-after-change-function-callback (beg end len)
(when nntp-process-callback
(save-match-data
(if (and (= beg (point-min))
(let ((process (or (nntp-find-connection buffer)
(nntp-open-connection buffer))))
(if (not process)
- (nnheader-report 'nntp "Couldn't open connection to %a" address)
+ (nnheader-report 'nntp "Couldn't open connection to %s" address)
(unless (or nntp-inhibit-erase nnheader-callback-function)
(save-excursion
(set-buffer (process-buffer process))
nntp-process-wait-for wait-for
nntp-process-callback callback
nntp-process-start-point (point-max)
- after-change-functions (list 'nntp-after-change-function)))
+ after-change-functions
+ (list 'nntp-after-change-function-callback)))
t)
(wait-for
(nntp-wait-for process wait-for buffer decode))
(save-excursion
(set-buffer (or (nntp-find-connection-buffer nntp-server-buffer)
nntp-server-buffer))
- (message "nntp reading%s" (make-string (/ (point-max) 10000) ?.))
+ (let ((len (/ (point-max) 10000)))
+ (unless (zerop len)
+ (message "nntp reading%s" (make-string len ?.))))
(accept-process-output process 1)))
(defun nntp-accept-response ()
fetch-old)
(nntp-send-xover-command
(if fetch-old
- (if (numberp fetch-old)
- (max 1 (- (car articles) fetch-old))
+ (if (numberp fetch-old)
+ (max 1 (- (car articles) fetch-old))
1)
(car articles))
(car (last articles)) 'wait)
(setq first (car articles))
;; Search forward until we find a gap, or until we run out of
;; articles.
- (while (and (cdr articles)
+ (while (and (cdr articles)
(< (- (nth 1 articles) (car articles)) nntp-nov-gap))
(setq articles (cdr articles)))
(zerop (% count nntp-maximum-request)))
(accept-process-output)
;; On some Emacs versions the preceding function has
- ;; a tendency to change the buffer. Perhaps. It's
+ ;; a tendency to change the buffer. Perhaps. It's
;; quite difficult to reproduce, because it only
;; seems to happen once in a blue moon.
- (set-buffer buf)
+ (set-buffer buf)
(while (progn
(goto-char last-point)
;; Count replies.
(save-excursion
(set-buffer nntp-server-buffer)
(goto-char (point-min))
- (and (looking-at "[23]") ; No error message.
+ (and (looking-at "[23]") ; No error message.
;; We also have to look at the lines. Some buggy
;; servers give back simple lines with just the
;; article number. How... helpful.
(string-match (format "\\([^ :]+\\):%d" number) xref))
(substring xref (match-beginning 1) (match-end 1)))
(t "")))
- (when (string-match "\r" group)
+ (when (string-match "\r" group)
(setq group (substring group 0 (match-beginning 0))))
(cons group number)))))