1 ;;; nntp.el --- nntp access for Gnus
3 ;; Copyright (C) 1987, 1988, 1989, 1990, 1992, 1993, 1994, 1995, 1996,
4 ;; 1997, 1998, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published
13 ;; by the Free Software Foundation; either version 2, or (at your
14 ;; option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;; General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
35 (eval-when-compile (require 'cl))
37 (defvoo nntp-address nil
38 "Address of the physical nntp server.")
40 (defvoo nntp-port-number "nntp"
41 "Port number on the physical nntp server.")
43 (defvoo nntp-server-opened-hook '(nntp-send-mode-reader)
44 "*Hook used for sending commands to the server at startup.
45 The default value is `nntp-send-mode-reader', which makes an innd
46 server spawn an nnrpd server.")
48 (defvoo nntp-authinfo-function 'nntp-send-authinfo
49 "Function used to send AUTHINFO to the server.
50 It is called with no parameters.")
52 (defvoo nntp-server-action-alist
53 '(("nntpd 1\\.5\\.11t"
54 (remove-hook 'nntp-server-opened-hook 'nntp-send-mode-reader))
55 ("NNRP server Netscape"
56 (setq nntp-server-list-active-group nil)))
57 "Alist of regexps to match on server types and actions to be taken.
58 For instance, if you want Gnus to beep every time you connect
59 to innd, you could say something like:
61 \(setq nntp-server-action-alist
64 You probably don't want to do that, though.")
66 (defvoo nntp-open-connection-function 'nntp-open-network-stream
67 "*Function used for connecting to a remote system.
68 It will be called with the buffer to output in as argument.
70 Currently, five such functions are provided (please refer to their
71 respective doc string for more information), three of them establishing
72 direct connections to the nntp server, and two of them using an indirect
76 - `nntp-open-network-stream' (the default),
77 - `nntp-open-ssl-stream',
78 - `nntp-open-tls-stream',
79 - `nntp-open-telnet-stream'.
82 - `nntp-open-via-rlogin-and-telnet',
83 - `nntp-open-via-telnet-and-telnet'.")
85 (defvoo nntp-pre-command nil
86 "*Pre-command to use with the various nntp-open-via-* methods.
87 This is where you would put \"runsocks\" or stuff like that.")
89 (defvoo nntp-telnet-command "telnet"
90 "*Telnet command used to connect to the nntp server.
91 This command is used by the various nntp-open-via-* methods.")
93 (defvoo nntp-telnet-switches '("-8")
94 "*Switches given to the telnet command `nntp-telnet-command'.")
96 (defvoo nntp-end-of-line "\r\n"
97 "*String to use on the end of lines when talking to the NNTP server.
98 This is \"\\r\\n\" by default, but should be \"\\n\" when
99 using and indirect connection method (nntp-open-via-*).")
101 (defvoo nntp-via-rlogin-command "rsh"
102 "*Rlogin command used to connect to an intermediate host.
103 This command is used by the `nntp-open-via-rlogin-and-telnet' method.
104 The default is \"rsh\", but \"ssh\" is a popular alternative.")
106 (defvoo nntp-via-rlogin-command-switches nil
107 "*Switches given to the rlogin command `nntp-via-rlogin-command'.
108 If you use \"ssh\" for `nntp-via-rlogin-command', you may set this to
109 \(\"-C\") in order to compress all data connections, otherwise set this
110 to \(\"-t\" \"-e\" \"none\") or (\"-C\" \"-t\" \"-e\" \"none\") if the telnet
111 command requires a pseudo-tty allocation on an intermediate host.")
113 (defvoo nntp-via-telnet-command "telnet"
114 "*Telnet command used to connect to an intermediate host.
115 This command is used by the `nntp-open-via-telnet-and-telnet' method.")
117 (defvoo nntp-via-telnet-switches '("-8")
118 "*Switches given to the telnet command `nntp-via-telnet-command'.")
120 (defvoo nntp-via-user-name nil
121 "*User name to log in on an intermediate host with.
122 This variable is used by the `nntp-open-via-telnet-and-telnet' method.")
124 (defvoo nntp-via-user-password nil
125 "*Password to use to log in on an intermediate host with.
126 This variable is used by the `nntp-open-via-telnet-and-telnet' method.")
128 (defvoo nntp-via-address nil
129 "*Address of an intermediate host to connect to.
130 This variable is used by the `nntp-open-via-rlogin-and-telnet' and
131 `nntp-open-via-telnet-and-telnet' methods.")
133 (defvoo nntp-via-envuser nil
134 "*Whether both telnet client and server support the ENVIRON option.
135 If non-nil, there will be no prompt for a login name.")
137 (defvoo nntp-via-shell-prompt "bash\\|\$ *\r?$\\|> *\r?"
138 "*Regular expression to match the shell prompt on an intermediate host.
139 This variable is used by the `nntp-open-via-telnet-and-telnet' method.")
141 (defvoo nntp-large-newsgroup 50
142 "*The number of articles which indicates a large newsgroup.
143 If the number of articles is greater than the value, verbose
144 messages will be shown to indicate the current status.")
146 (defvoo nntp-maximum-request 400
147 "*The maximum number of the requests sent to the NNTP server at one time.
148 If Emacs hangs up while retrieving headers, set the variable to a
151 (defvoo nntp-nov-is-evil nil
152 "*If non-nil, nntp will never attempt to use XOVER when talking to the server.")
154 (defvoo nntp-xover-commands '("XOVER" "XOVERVIEW")
155 "*List of strings that are used as commands to fetch NOV lines from a server.
156 The strings are tried in turn until a positive response is gotten. If
157 none of the commands are successful, nntp will just grab headers one
160 (defvoo nntp-nov-gap 5
161 "*Maximum allowed gap between two articles.
162 If the gap between two consecutive articles is bigger than this
163 variable, split the XOVER request into two requests.")
165 (defvoo nntp-prepare-server-hook nil
166 "*Hook run before a server is opened.
167 If can be used to set up a server remotely, for instance. Say you
168 have an account at the machine \"other.machine\". This machine has
169 access to an NNTP server that you can't access locally. You could
170 then use this hook to rsh to the remote machine and start a proxy NNTP
171 server there that you can connect to. See also
172 `nntp-open-connection-function'")
174 (defvoo nntp-warn-about-losing-connection t
175 "*If non-nil, beep when a server closes connection.")
177 (defvoo nntp-coding-system-for-read 'binary
178 "*Coding system to read from NNTP.")
180 (defvoo nntp-coding-system-for-write 'binary
181 "*Coding system to write to NNTP.")
183 (defcustom nntp-authinfo-file "~/.authinfo"
184 ".netrc-like file that holds nntp authinfo passwords."
187 (repeat :tag "Entries"
190 :value ("" ("login" . "") ("password" . ""))
194 (const :format "" "login")
195 (string :format "Login: %v"))
197 (const :format "" "password")
198 (string :format "Password: %v")))))))
202 (defvoo nntp-connection-timeout nil
203 "*Number of seconds to wait before an nntp connection times out.
204 If this variable is nil, which is the default, no timers are set.
205 NOTE: This variable is never seen to work in Emacs 20 and XEmacs 21.")
207 (defvoo nntp-prepare-post-hook nil
208 "*Hook run just before posting an article. It is supposed to be used
209 to insert Cancel-Lock headers.")
211 ;;; Internal variables.
213 (defvar nntp-record-commands nil
214 "*If non-nil, nntp will record all commands in the \"*nntp-log*\" buffer.")
216 (defvar nntp-have-messaged nil)
218 (defvar nntp-process-wait-for nil)
219 (defvar nntp-process-to-buffer nil)
220 (defvar nntp-process-callback nil)
221 (defvar nntp-process-decode nil)
222 (defvar nntp-process-start-point nil)
223 (defvar nntp-inside-change-function nil)
224 (defvoo nntp-last-command-time nil)
225 (defvoo nntp-last-command nil)
226 (defvoo nntp-authinfo-password nil)
227 (defvoo nntp-authinfo-user nil)
229 (defvar nntp-connection-list nil)
231 (defvoo nntp-server-type nil)
232 (defvoo nntp-connection-alist nil)
233 (defvoo nntp-status-string "")
234 (defconst nntp-version "nntp 5.0")
235 (defvoo nntp-inhibit-erase nil)
236 (defvoo nntp-inhibit-output nil)
238 (defvoo nntp-server-xover 'try)
239 (defvoo nntp-server-list-active-group 'try)
241 (defvar nntp-async-needs-kluge
242 (string-match "^GNU Emacs 20\\.3\\." (emacs-version))
243 "*When non-nil, nntp will poll asynchronous connections
244 once a second. By default, this is turned on only for Emacs
245 20.3, which has a bug that breaks nntp's normal method of
246 noticing asynchronous data.")
248 (defvar nntp-async-timer nil)
249 (defvar nntp-async-process-list nil)
251 (defvar nntp-ssl-program
252 "openssl s_client -quiet -ssl3 -connect %s:%p"
253 "A string containing commands for SSL connections.
254 Within a string, %s is replaced with the server address and %p with
255 port number on server. The program should accept IMAP commands on
256 stdin and return responses to stdout.")
260 ;;; Internal functions.
262 (defsubst nntp-send-string (process string)
263 "Send STRING to PROCESS."
264 ;; We need to store the time to provide timeouts, and
265 ;; to store the command so the we can replay the command
266 ;; if the server gives us an AUTHINFO challenge.
267 (setq nntp-last-command-time (current-time)
268 nntp-last-command string)
269 (when nntp-record-commands
270 (nntp-record-command string))
271 (process-send-string process (concat string nntp-end-of-line))
272 (or (memq (process-status process) '(open run))
273 (nntp-report "Server closed connection")))
275 (defun nntp-record-command (string)
276 "Record the command STRING."
278 (set-buffer (get-buffer-create "*nntp-log*"))
279 (goto-char (point-max))
280 (let ((time (current-time)))
281 (insert (format-time-string "%Y%m%dT%H%M%S" time)
282 "." (format "%03d" (/ (nth 2 time) 1000))
283 " " nntp-address " " string "\n"))))
285 (defun nntp-report (&rest args)
286 "Report an error from the nntp backend. The first string in ARGS
287 can be a format string. For some commands, the failed command may be
288 retried once before actually displaying the error report."
290 (when nntp-record-commands
291 (nntp-record-command "*** CALLED nntp-report ***"))
293 (nnheader-report 'nntp args)
297 (defun nntp-report-1 (&rest args)
298 "Throws out to nntp-with-open-group-error so that the connection may
299 be restored and the command retried."
301 (when nntp-record-commands
302 (nntp-record-command "*** CONNECTION LOST ***"))
304 (throw 'nntp-with-open-group-error t))
306 (defsubst nntp-wait-for (process wait-for buffer &optional decode discard)
307 "Wait for WAIT-FOR to arrive from PROCESS."
309 (set-buffer (process-buffer process))
310 (goto-char (point-min))
311 (while (and (or (not (memq (char-after (point)) '(?2 ?3 ?4 ?5)))
313 (memq (process-status process) '(open run)))
314 (when (looking-at "480")
315 (nntp-handle-authinfo process))
316 (when (looking-at "^.*\n")
317 (delete-region (point) (progn (forward-line 1) (point))))
318 (nntp-accept-process-output process)
319 (goto-char (point-min)))
324 (nntp-snarf-error-message)
326 ((not (memq (process-status process) '(open run)))
327 (nntp-report "Server closed connection"))
329 (goto-char (point-max))
330 (let ((limit (point-min))
332 (while (not (re-search-backward wait-for limit t))
333 (nntp-accept-process-output process)
334 ;; We assume that whatever we wait for is less than 1000
336 (setq limit (max (- (point-max) 1000) (point-min)))
337 (goto-char (point-max)))
338 (setq response (match-string 0))
339 (with-current-buffer nntp-server-buffer
340 (setq nntp-process-response response)))
341 (nntp-decode-text (not decode))
345 (goto-char (point-max))
346 (insert-buffer-substring (process-buffer process))
347 ;; Nix out "nntp reading...." message.
348 (when nntp-have-messaged
349 (setq nntp-have-messaged nil)
350 (nnheader-message 5 ""))))
355 (defun nntp-kill-buffer (buffer)
356 (when (buffer-name buffer)
358 (nnheader-init-server-buffer)))
360 (defsubst nntp-find-connection (buffer)
361 "Find the connection delivering to BUFFER."
362 (let ((alist nntp-connection-alist)
363 (buffer (if (stringp buffer) (get-buffer buffer) buffer))
365 (while (and alist (setq entry (pop alist)))
366 (when (eq buffer (cadr entry))
367 (setq process (car entry)
370 (if (memq (process-status process) '(open run))
372 (nntp-kill-buffer (process-buffer process))
373 (setq nntp-connection-alist (delq entry nntp-connection-alist))
376 (defsubst nntp-find-connection-entry (buffer)
377 "Return the entry for the connection to BUFFER."
378 (assq (nntp-find-connection buffer) nntp-connection-alist))
380 (defun nntp-find-connection-buffer (buffer)
381 "Return the process connection buffer tied to BUFFER."
382 (let ((process (nntp-find-connection buffer)))
384 (process-buffer process))))
386 (defsubst nntp-retrieve-data (command address port buffer
387 &optional wait-for callback decode)
388 "Use COMMAND to retrieve data into BUFFER from PORT on ADDRESS."
389 (let ((process (or (nntp-find-connection buffer)
390 (nntp-open-connection buffer))))
393 (unless (or nntp-inhibit-erase nnheader-callback-function)
395 (set-buffer (process-buffer process))
400 (nntp-send-string process command))
402 ((eq callback 'ignore)
404 ((and callback wait-for)
405 (nntp-async-wait process wait-for buffer decode callback)
408 (nntp-wait-for process wait-for buffer decode))
411 (nnheader-report 'nntp "Couldn't open connection to %s: %s"
414 (message "Quit retrieving data from nntp")
417 (nnheader-report 'nntp "Couldn't open connection to %s" address))))
419 (defsubst nntp-send-command (wait-for &rest strings)
420 "Send STRINGS to server and wait until WAIT-FOR returns."
421 (when (and (not nnheader-callback-function)
422 (not nntp-inhibit-output))
424 (set-buffer nntp-server-buffer)
426 (let* ((command (mapconcat 'identity strings " "))
427 (process (nntp-find-connection nntp-server-buffer))
428 (buffer (and process (process-buffer process)))
429 (pos (and buffer (with-current-buffer buffer (point)))))
432 (nntp-retrieve-data command
433 nntp-address nntp-port-number
435 wait-for nnheader-callback-function)
436 ;; If nothing to wait for, still remove possibly echo'ed commands.
437 ;; We don't have echos if nntp-open-connection-function
438 ;; is `nntp-open-network-stream', so we skip this in that case.
440 (equal nntp-open-connection-function
441 'nntp-open-network-stream))
442 (nntp-accept-response)
446 (if (looking-at (regexp-quote command))
447 (delete-region pos (progn (forward-line 1)
448 (gnus-point-at-bol))))
450 (nnheader-report 'nntp "Couldn't open connection to %s."
453 (defun nntp-send-command-nodelete (wait-for &rest strings)
454 "Send STRINGS to server and wait until WAIT-FOR returns."
455 (let* ((command (mapconcat 'identity strings " "))
456 (process (nntp-find-connection nntp-server-buffer))
457 (buffer (and process (process-buffer process)))
458 (pos (and buffer (with-current-buffer buffer (point)))))
461 (nntp-retrieve-data command
462 nntp-address nntp-port-number
464 wait-for nnheader-callback-function)
465 ;; If nothing to wait for, still remove possibly echo'ed commands
467 (nntp-accept-response)
471 (if (looking-at (regexp-quote command))
472 (delete-region pos (progn (forward-line 1)
473 (gnus-point-at-bol))))
475 (nnheader-report 'nntp "Couldn't open connection to %s."
478 (defun nntp-send-command-and-decode (wait-for &rest strings)
479 "Send STRINGS to server and wait until WAIT-FOR returns."
480 (when (and (not nnheader-callback-function)
481 (not nntp-inhibit-output))
483 (set-buffer nntp-server-buffer)
485 (let* ((command (mapconcat 'identity strings " "))
486 (process (nntp-find-connection nntp-server-buffer))
487 (buffer (and process (process-buffer process)))
488 (pos (and buffer (with-current-buffer buffer (point)))))
491 (nntp-retrieve-data command
492 nntp-address nntp-port-number
494 wait-for nnheader-callback-function t)
495 ;; If nothing to wait for, still remove possibly echo'ed commands
497 (nntp-accept-response)
501 (if (looking-at (regexp-quote command))
502 (delete-region pos (progn (forward-line 1) (gnus-point-at-bol))))
504 (nnheader-report 'nntp "Couldn't open connection to %s."
508 (defun nntp-send-buffer (wait-for)
509 "Send the current buffer to server and wait until WAIT-FOR returns."
510 (when (and (not nnheader-callback-function)
511 (not nntp-inhibit-output))
513 (set-buffer (nntp-find-connection-buffer nntp-server-buffer))
516 (mm-with-unibyte-current-buffer
517 ;; Some encoded unicode text contains character 0x80-0x9f e.g. Euro.
518 (process-send-region (nntp-find-connection nntp-server-buffer)
519 (point-min) (point-max)))
521 nil nntp-address nntp-port-number nntp-server-buffer
522 wait-for nnheader-callback-function))
526 ;;; Interface functions.
528 (nnoo-define-basics nntp)
530 (defsubst nntp-next-result-arrived-p ()
532 ;; A result that starts with a 2xx code is terminated by
533 ;; a line with only a "." on it.
534 ((eq (char-after) ?2)
535 (if (re-search-forward "\n\\.\r?\n" nil t)
538 ;; A result that starts with a 3xx or 4xx code is terminated
541 (if (search-forward "\n" nil t)
549 (defvar nntp-with-open-group-internal nil)
550 (defvar nntp-report-n nil))
552 (defmacro nntp-with-open-group (group server &optional connectionless &rest forms)
553 "Protect against servers that don't like clients that keep idle connections opens.
554 The problem being that these servers may either close a connection or
555 simply ignore any further requests on a connection. Closed
556 connections are not detected until accept-process-output has updated
557 the process-status. Dropped connections are not detected until the
558 connection timeouts (which may be several minutes) or
559 nntp-connection-timeout has expired. When these occur
560 nntp-with-open-group, opens a new connection then re-issues the NNTP
561 command whose response triggered the error."
562 (when (and (listp connectionless)
563 (not (eq connectionless nil)))
564 (setq forms (cons connectionless forms)
566 `(letf ((nntp-report-n (symbol-function 'nntp-report))
567 ((symbol-function 'nntp-report) (symbol-function 'nntp-report-1))
568 (nntp-with-open-group-internal nil))
569 (while (catch 'nntp-with-open-group-error
570 ;; Open the connection to the server
571 ;; NOTE: Existing connections are NOT tested.
572 (nntp-possibly-change-group ,group ,server ,connectionless)
575 (and nntp-connection-timeout
576 (nnheader-run-at-time
577 nntp-connection-timeout nil
579 (let ((process (nntp-find-connection
582 (process-buffer process))))
583 ;; When I an able to identify the
584 ;; connection to the server AND I've
585 ;; received NO reponse for
586 ;; nntp-connection-timeout seconds.
587 (when (and buffer (eq 0 (buffer-size buffer)))
588 ;; Close the connection. Take no
589 ;; other action as the accept input
590 ;; code will handle the closed
592 (nntp-kill-buffer buffer))))))))
594 (setq nntp-with-open-group-internal
599 (signal 'quit nil))))
601 (nnheader-cancel-timer timer)))
603 (setf (symbol-function 'nntp-report) nntp-report-n))
604 nntp-with-open-group-internal))
606 (deffoo nntp-retrieve-headers (articles &optional group server fetch-old)
607 "Retrieve the headers of ARTICLES."
608 (nntp-with-open-group
611 (set-buffer (nntp-find-connection-buffer nntp-server-buffer))
613 (if (and (not gnus-nov-is-evil)
614 (not nntp-nov-is-evil)
615 (nntp-retrieve-headers-with-xover articles fetch-old))
616 ;; We successfully retrieved the headers via XOVER.
618 ;; XOVER didn't work, so we do it the hard, slow and inefficient
620 (let ((number (length articles))
624 (last-point (point-min))
625 (buf (nntp-find-connection-buffer nntp-server-buffer))
626 (nntp-inhibit-erase t)
628 ;; Send HEAD commands.
629 (while (setq article (pop articles))
632 "HEAD" (if (numberp article)
633 (int-to-string article)
634 ;; `articles' is either a list of article numbers
635 ;; or a list of article IDs.
638 ;; Every 400 requests we have to read the stream in
639 ;; order to avoid deadlocks.
640 (when (or (null articles) ;All requests have been sent.
641 (zerop (% count nntp-maximum-request)))
642 (nntp-accept-response)
645 (goto-char last-point)
647 (while (nntp-next-result-arrived-p)
648 (setq last-point (point))
651 ;; If number of headers is greater than 100, give
652 ;; informative messages.
653 (and (numberp nntp-large-newsgroup)
654 (> number nntp-large-newsgroup)
655 (zerop (% received 20))
656 (nnheader-message 6 "NNTP: Receiving headers... %d%%"
657 (/ (* received 100) number)))
658 (nntp-accept-response))))
659 (and (numberp nntp-large-newsgroup)
660 (> number nntp-large-newsgroup)
661 (nnheader-message 6 "NNTP: Receiving headers...done"))
663 ;; Now all of replies are received. Fold continuation lines.
664 (nnheader-fold-continuation-lines)
665 ;; Remove all "\r"'s.
667 (copy-to-buffer nntp-server-buffer (point-min) (point-max))
670 (deffoo nntp-retrieve-groups (groups &optional server)
671 "Retrieve group info on GROUPS."
672 (nntp-with-open-group
674 (when (nntp-find-connection-buffer nntp-server-buffer)
677 ;; Erase nntp-server-buffer before nntp-inhibit-erase.
678 (set-buffer nntp-server-buffer)
680 (set-buffer (nntp-find-connection-buffer nntp-server-buffer))
681 ;; The first time this is run, this variable is `try'. So we
683 (when (eq nntp-server-list-active-group 'try)
684 (nntp-try-list-active (car groups)))
689 (last-point (point-min))
690 (nntp-inhibit-erase t)
691 (buf (nntp-find-connection-buffer nntp-server-buffer))
692 (command (if nntp-server-list-active-group
693 "LIST ACTIVE" "GROUP")))
695 ;; Timeout may have killed the buffer.
696 (unless (gnus-buffer-live-p buf)
697 (nnheader-report 'nntp "Connection to %s is closed." server)
699 ;; Send the command to the server.
700 (nntp-send-command nil command (pop groups))
702 ;; Every 400 requests we have to read the stream in
703 ;; order to avoid deadlocks.
704 (when (or (null groups) ;All requests have been sent.
705 (zerop (% count nntp-maximum-request)))
706 (nntp-accept-response)
707 (while (and (gnus-buffer-live-p buf)
709 ;; Search `blue moon' in this file for the
710 ;; reason why set-buffer here.
712 (goto-char last-point)
714 (while (re-search-forward "^[0-9]" nil t)
716 (setq last-point (point))
718 (nntp-accept-response))))
720 ;; Wait for the reply from the final command.
721 (unless (gnus-buffer-live-p buf)
722 (nnheader-report 'nntp "Connection to %s is closed." server)
725 (goto-char (point-max))
726 (re-search-backward "^[0-9]" nil t)
727 (when (looking-at "^[23]")
728 (while (and (gnus-buffer-live-p buf)
731 (goto-char (point-max))
732 (if (not nntp-server-list-active-group)
733 (not (re-search-backward "\r?\n"
735 (not (re-search-backward "^\\.\r?\n"
737 (nntp-accept-response)))
739 ;; Now all replies are received. We remove CRs.
740 (unless (gnus-buffer-live-p buf)
741 (nnheader-report 'nntp "Connection to %s is closed." server)
744 (goto-char (point-min))
745 (while (search-forward "\r" nil t)
746 (replace-match "" t t))
748 (if (not nntp-server-list-active-group)
750 (copy-to-buffer nntp-server-buffer (point-min) (point-max))
752 ;; We have read active entries, so we just delete the
754 (goto-char (point-min))
755 (while (re-search-forward "^[.2-5]" nil t)
756 (delete-region (match-beginning 0)
757 (progn (forward-line 1) (point))))
758 (copy-to-buffer nntp-server-buffer (point-min) (point-max))
761 (deffoo nntp-retrieve-articles (articles &optional group server)
762 (nntp-with-open-group
765 (let ((number (length articles))
769 (last-point (point-min))
770 (buf (nntp-find-connection-buffer nntp-server-buffer))
771 (nntp-inhibit-erase t)
772 (map (apply 'vector articles))
777 ;; Send ARTICLE command.
778 (while (setq article (pop articles))
781 "ARTICLE" (if (numberp article)
782 (int-to-string article)
783 ;; `articles' is either a list of article numbers
784 ;; or a list of article IDs.
787 ;; Every 400 requests we have to read the stream in
788 ;; order to avoid deadlocks.
789 (when (or (null articles) ;All requests have been sent.
790 (zerop (% count nntp-maximum-request)))
791 (nntp-accept-response)
794 (goto-char last-point)
796 (while (nntp-next-result-arrived-p)
797 (aset map received (cons (aref map received) (point)))
798 (setq last-point (point))
801 ;; If number of headers is greater than 100, give
802 ;; informative messages.
803 (and (numberp nntp-large-newsgroup)
804 (> number nntp-large-newsgroup)
805 (zerop (% received 20))
806 (nnheader-message 6 "NNTP: Receiving articles... %d%%"
807 (/ (* received 100) number)))
808 (nntp-accept-response))))
809 (and (numberp nntp-large-newsgroup)
810 (> number nntp-large-newsgroup)
811 (nnheader-message 6 "NNTP: Receiving articles...done"))
813 ;; Now we have all the responses. We go through the results,
814 ;; wash it and copy it over to the server buffer.
815 (set-buffer nntp-server-buffer)
817 (setq last-point (point-min))
821 (setq point (goto-char (point-max)))
823 (insert-buffer-substring buf last-point (cdr entry))
825 (setq last-point (cdr entry))
828 (cons (car entry) point))
831 (defun nntp-try-list-active (group)
832 (nntp-list-active-group group)
834 (set-buffer nntp-server-buffer)
835 (goto-char (point-min))
837 (looking-at "5[0-9]+"))
838 (setq nntp-server-list-active-group nil))
840 (setq nntp-server-list-active-group t)))))
842 (deffoo nntp-list-active-group (group &optional server)
843 "Return the active info on GROUP (which can be a regexp)."
844 (nntp-with-open-group
846 (nntp-send-command "^\\.*\r?\n" "LIST ACTIVE" group)))
848 (deffoo nntp-request-group-articles (group &optional server)
849 "Return the list of existing articles in GROUP."
850 (nntp-with-open-group
852 (nntp-send-command "^\\.*\r?\n" "LISTGROUP" group)))
854 (deffoo nntp-request-article (article &optional group server buffer command)
855 (nntp-with-open-group
857 (when (nntp-send-command-and-decode
858 "\r?\n\\.\r?\n" "ARTICLE"
859 (if (numberp article) (int-to-string article) article))
861 (not (equal buffer nntp-server-buffer)))
863 (set-buffer nntp-server-buffer)
864 (copy-to-buffer buffer (point-min) (point-max))
865 (nntp-find-group-and-number group))
866 (nntp-find-group-and-number group)))))
868 (deffoo nntp-request-head (article &optional group server)
869 (nntp-with-open-group
871 (when (nntp-send-command
872 "\r?\n\\.\r?\n" "HEAD"
873 (if (numberp article) (int-to-string article) article))
875 (nntp-find-group-and-number group)
876 (nntp-decode-text)))))
878 (deffoo nntp-request-body (article &optional group server)
879 (nntp-with-open-group
881 (nntp-send-command-and-decode
882 "\r?\n\\.\r?\n" "BODY"
883 (if (numberp article) (int-to-string article) article))))
885 (deffoo nntp-request-group (group &optional server dont-check)
886 (nntp-with-open-group
888 (when (nntp-send-command "^[245].*\n" "GROUP" group)
889 (let ((entry (nntp-find-connection-entry nntp-server-buffer)))
890 (setcar (cddr entry) group)))))
892 (deffoo nntp-close-group (group &optional server)
895 (deffoo nntp-server-opened (&optional server)
896 "Say whether a connection to SERVER has been opened."
897 (and (nnoo-current-server-p 'nntp server)
899 (gnus-buffer-live-p nntp-server-buffer)
900 (nntp-find-connection nntp-server-buffer)))
902 (deffoo nntp-open-server (server &optional defs connectionless)
903 (nnheader-init-server-buffer)
904 (if (nntp-server-opened server)
906 (when (or (stringp (car defs))
907 (numberp (car defs)))
908 (setq defs (cons (list 'nntp-port-number (car defs)) (cdr defs))))
909 (unless (assq 'nntp-address defs)
910 (setq defs (append defs (list (list 'nntp-address server)))))
911 (nnoo-change-server 'nntp server defs)
912 (unless connectionless
913 (or (nntp-find-connection nntp-server-buffer)
914 (nntp-open-connection nntp-server-buffer)))))
916 (deffoo nntp-close-server (&optional server)
917 (nntp-possibly-change-group nil server t)
918 (let ((process (nntp-find-connection nntp-server-buffer)))
920 (when (memq (process-status process) '(open run))
922 (nntp-send-string process "QUIT")
923 (unless (eq nntp-open-connection-function 'nntp-open-network-stream)
924 ;; Ok, this is evil, but when using telnet and stuff
925 ;; as the connection method, it's important that the
926 ;; QUIT command actually is sent out before we kill
929 (nntp-kill-buffer (process-buffer process))
930 (setq process (car (pop nntp-connection-alist))))
931 (nnoo-close-server 'nntp)))
933 (deffoo nntp-request-close ()
935 (while (setq process (pop nntp-connection-list))
936 (when (memq (process-status process) '(open run))
938 (nntp-send-string process "QUIT")