1 ;;; nntp.el --- nntp access for Gnus
2 ;; Copyright (C) 1987, 1988, 1989, 1990, 1992, 1993, 1994, 1995, 1996,
3 ;; 1997, 1998, 2000, 2001
4 ;; 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 by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU 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
23 ;; the 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-telnet-stream'.
81 - `nntp-open-via-rlogin-and-telnet',
82 - `nntp-open-via-telnet-and-telnet'.")
84 (defvoo nntp-pre-command nil
85 "*Pre-command to use with the various nntp-open-via-* methods.
86 This is where you would put \"runsocks\" or stuff like that.")
88 (defvoo nntp-telnet-command "telnet"
89 "*Telnet command used to connect to the nntp server.
90 This command is used by the various nntp-open-via-* methods.")
92 (defvoo nntp-telnet-switches '("-8")
93 "*Switches given to the telnet command `nntp-telnet-command'.")
95 (defvoo nntp-end-of-line "\r\n"
96 "*String to use on the end of lines when talking to the NNTP server.
97 This is \"\\r\\n\" by default, but should be \"\\n\" when
98 using and indirect connection method (nntp-open-via-*).")
100 (defvoo nntp-via-rlogin-command "rsh"
101 "*Rlogin command used to connect to an intermediate host.
102 This command is used by the `nntp-open-via-rlogin-and-telnet' method.
103 The default is \"rsh\", but \"ssh\" is a popular alternative.")
105 (defvoo nntp-via-telnet-command "telnet"
106 "*Telnet command used to connect to an intermediate host.
107 This command is used by the `nntp-open-via-telnet-and-telnet' method.")
109 (defvoo nntp-via-telnet-switches '("-8")
110 "*Switches given to the telnet command `nntp-via-telnet-command'.")
112 (defvoo nntp-via-user-name nil
113 "*User name to log in on an intermediate host with.
114 This variable is used by the `nntp-open-via-telnet-and-telnet' method.")
116 (defvoo nntp-via-user-password nil
117 "*Password to use to log in on an intermediate host with.
118 This variable is used by the `nntp-open-via-telnet-and-telnet' method.")
120 (defvoo nntp-via-address nil
121 "*Address of an intermediate host to connect to.
122 This variable is used by the `nntp-open-via-rlogin-and-telnet' and
123 `nntp-open-via-telnet-and-telnet' methods.")
125 (defvoo nntp-via-envuser nil
126 "*Whether both telnet client and server support the ENVIRON option.
127 If non-nil, there will be no prompt for a login name.")
129 (defvoo nntp-via-shell-prompt "bash\\|\$ *\r?$\\|> *\r?"
130 "*Regular expression to match the shell prompt on an intermediate host.
131 This variable is used by the `nntp-open-via-telnet-and-telnet' method.")
133 (defvoo nntp-large-newsgroup 50
134 "*The number of the articles which indicates a large newsgroup.
135 If the number of the articles is greater than the value, verbose
136 messages will be shown to indicate the current status.")
138 (defvoo nntp-maximum-request 400
139 "*The maximum number of the requests sent to the NNTP server at one time.
140 If Emacs hangs up while retrieving headers, set the variable to a
143 (defvoo nntp-nov-is-evil nil
144 "*If non-nil, nntp will never attempt to use XOVER when talking to the server.")
146 (defvoo nntp-xover-commands '("XOVER" "XOVERVIEW")
147 "*List of strings that are used as commands to fetch NOV lines from a server.
148 The strings are tried in turn until a positive response is gotten. If
149 none of the commands are successful, nntp will just grab headers one
152 (defvoo nntp-nov-gap 5
153 "*Maximum allowed gap between two articles.
154 If the gap between two consecutive articles is bigger than this
155 variable, split the XOVER request into two requests.")
157 (defvoo nntp-prepare-server-hook nil
158 "*Hook run before a server is opened.
159 If can be used to set up a server remotely, for instance. Say you
160 have an account at the machine \"other.machine\". This machine has
161 access to an NNTP server that you can't access locally. You could
162 then use this hook to rsh to the remote machine and start a proxy NNTP
163 server there that you can connect to. See also
164 `nntp-open-connection-function'")
166 (defvoo nntp-warn-about-losing-connection t
167 "*If non-nil, beep when a server closes connection.")
169 (defvoo nntp-coding-system-for-read 'binary
170 "*Coding system to read from NNTP.")
172 (defvoo nntp-coding-system-for-write 'binary
173 "*Coding system to write to NNTP.")
175 (defcustom nntp-authinfo-file "~/.authinfo"
176 ".netrc-like file that holds nntp authinfo passwords."
179 (repeat :tag "Entries"
182 :value ("" ("login" . "") ("password" . ""))
186 (const :format "" "login")
187 (string :format "Login: %v"))
189 (const :format "" "password")
190 (string :format "Password: %v")))))))
194 (defvoo nntp-connection-timeout nil
195 "*Number of seconds to wait before an nntp connection times out.
196 If this variable is nil, which is the default, no timers are set.
197 NOTE: This variable is never seen to work in Emacs 20 and XEmacs 21.")
199 ;;; Internal variables.
201 (defvar nntp-record-commands nil
202 "*If non-nil, nntp will record all commands in the \"*nntp-log*\" buffer.")
204 (defvar nntp-have-messaged nil)
206 (defvar nntp-process-wait-for nil)
207 (defvar nntp-process-to-buffer nil)
208 (defvar nntp-process-callback nil)
209 (defvar nntp-process-decode nil)
210 (defvar nntp-process-start-point nil)
211 (defvar nntp-inside-change-function nil)
212 (defvoo nntp-last-command-time nil)
213 (defvoo nntp-last-command nil)
214 (defvoo nntp-authinfo-password nil)
215 (defvoo nntp-authinfo-user nil)
217 (defvar nntp-connection-list nil)
219 (defvoo nntp-server-type nil)
220 (defvoo nntp-connection-alist nil)
221 (defvoo nntp-status-string "")
222 (defconst nntp-version "nntp 5.0")
223 (defvoo nntp-inhibit-erase nil)
224 (defvoo nntp-inhibit-output nil)
226 (defvoo nntp-server-xover 'try)
227 (defvoo nntp-server-list-active-group 'try)
229 (defvar nntp-async-needs-kluge
230 (string-match "^GNU Emacs 20\\.3\\." (emacs-version))
231 "*When non-nil, nntp will poll asynchronous connections
232 once a second. By default, this is turned on only for Emacs
233 20.3, which has a bug that breaks nntp's normal method of
234 noticing asynchronous data.")
236 (defvar nntp-async-timer nil)
237 (defvar nntp-async-process-list nil)
240 (autoload 'mail-source-read-passwd "mail-source")
241 (autoload 'open-ssl-stream "ssl"))
245 ;;; Internal functions.
247 (defsubst nntp-send-string (process string)
248 "Send STRING to PROCESS."
249 ;; We need to store the time to provide timeouts, and
250 ;; to store the command so the we can replay the command
251 ;; if the server gives us an AUTHINFO challenge.
252 (setq nntp-last-command-time (current-time)
253 nntp-last-command string)
254 (when nntp-record-commands
255 (nntp-record-command string))
256 (process-send-string process (concat string nntp-end-of-line)))
258 (defun nntp-record-command (string)
259 "Record the command STRING."
261 (set-buffer (get-buffer-create "*nntp-log*"))
262 (goto-char (point-max))
263 (let ((time (current-time)))
264 (insert (format-time-string "%Y%m%dT%H%M%S" time)
265 "." (format "%03d" (/ (nth 2 time) 1000))
266 " " nntp-address " " string "\n"))))
268 (defsubst nntp-wait-for (process wait-for buffer &optional decode discard)
269 "Wait for WAIT-FOR to arrive from PROCESS."
271 (set-buffer (process-buffer process))
272 (goto-char (point-min))
273 (while (and (or (not (memq (char-after (point)) '(?2 ?3 ?4 ?5)))
275 (memq (process-status process) '(open run)))
276 (when (looking-at "480")
277 (nntp-handle-authinfo process))
278 (when (looking-at "^.*\n")
279 (delete-region (point) (progn (forward-line 1) (point))))
280 (nntp-accept-process-output process)
281 (goto-char (point-min)))
286 (nntp-snarf-error-message)
288 ((not (memq (process-status process) '(open run)))
289 (nnheader-report 'nntp "Server closed connection"))
291 (goto-char (point-max))
292 (let ((limit (point-min)))
293 (while (not (re-search-backward wait-for limit t))
294 (nntp-accept-process-output process)
295 ;; We assume that whatever we wait for is less than 1000
297 (setq limit (max (- (point-max) 1000) (point-min)))
298 (goto-char (point-max))))
299 (nntp-decode-text (not decode))
303 (goto-char (point-max))
304 (insert-buffer-substring (process-buffer process))
305 ;; Nix out "nntp reading...." message.
306 (when nntp-have-messaged
307 (setq nntp-have-messaged nil)
308 (nnheader-message 5 ""))))
313 (defun nntp-kill-buffer (buffer)
314 (when (buffer-name buffer)
316 (nnheader-init-server-buffer)))
318 (defsubst nntp-find-connection (buffer)
319 "Find the connection delivering to BUFFER."
320 (let ((alist nntp-connection-alist)
321 (buffer (if (stringp buffer) (get-buffer buffer) buffer))
323 (while (and alist (setq entry (pop alist)))
324 (when (eq buffer (cadr entry))
325 (setq process (car entry)
328 (if (memq (process-status process) '(open run))
330 (nntp-kill-buffer (process-buffer process))
331 (setq nntp-connection-alist (delq entry nntp-connection-alist))
334 (defsubst nntp-find-connection-entry (buffer)
335 "Return the entry for the connection to BUFFER."
336 (assq (nntp-find-connection buffer) nntp-connection-alist))
338 (defun nntp-find-connection-buffer (buffer)
339 "Return the process connection buffer tied to BUFFER."
340 (let ((process (nntp-find-connection buffer)))
342 (process-buffer process))))
344 (defsubst nntp-retrieve-data (command address port buffer
345 &optional wait-for callback decode)
346 "Use COMMAND to retrieve data into BUFFER from PORT on ADDRESS."
347 (let ((process (or (nntp-find-connection buffer)
348 (nntp-open-connection buffer))))
350 (nnheader-report 'nntp "Couldn't open connection to %s" address)
351 (unless (or nntp-inhibit-erase nnheader-callback-function)
353 (set-buffer (process-buffer process))
358 (nntp-send-string process command))
360 ((eq callback 'ignore)
362 ((and callback wait-for)
363 (nntp-async-wait process wait-for buffer decode callback)
366 (nntp-wait-for process wait-for buffer decode))
369 (nnheader-report 'nntp "Couldn't open connection to %s: %s"
372 (message "Quit retrieving data from nntp")
376 (defsubst nntp-send-command (wait-for &rest strings)
377 "Send STRINGS to server and wait until WAIT-FOR returns."
378 (when (and (not nnheader-callback-function)
379 (not nntp-inhibit-output))
381 (set-buffer nntp-server-buffer)
383 (let* ((command (mapconcat 'identity strings " "))
384 (buffer (process-buffer (nntp-find-connection nntp-server-buffer)))
385 (pos (with-current-buffer buffer (point))))
387 (nntp-retrieve-data command
388 nntp-address nntp-port-number nntp-server-buffer
389 wait-for nnheader-callback-function)
390 ;; If nothing to wait for, still remove possibly echo'ed commands
392 (nntp-accept-response)
396 (if (looking-at (regexp-quote command))
397 (delete-region pos (progn (forward-line 1) (gnus-point-at-bol))))
401 (defun nntp-send-command-nodelete (wait-for &rest strings)
402 "Send STRINGS to server and wait until WAIT-FOR returns."
403 (let* ((command (mapconcat 'identity strings " "))
404 (buffer (process-buffer (nntp-find-connection nntp-server-buffer)))
405 (pos (with-current-buffer buffer (point))))
407 (nntp-retrieve-data command
408 nntp-address nntp-port-number nntp-server-buffer
409 wait-for nnheader-callback-function)
410 ;; If nothing to wait for, still remove possibly echo'ed commands
412 (nntp-accept-response)
416 (if (looking-at (regexp-quote command))
417 (delete-region pos (progn (forward-line 1) (gnus-point-at-bol))))
421 (defun nntp-send-command-and-decode (wait-for &rest strings)
422 "Send STRINGS to server and wait until WAIT-FOR returns."
423 (when (and (not nnheader-callback-function)
424 (not nntp-inhibit-output))
426 (set-buffer nntp-server-buffer)
428 (let* ((command (mapconcat 'identity strings " "))
429 (buffer (process-buffer (nntp-find-connection nntp-server-buffer)))
430 (pos (with-current-buffer buffer (point))))
432 (nntp-retrieve-data command
433 nntp-address nntp-port-number nntp-server-buffer
434 wait-for nnheader-callback-function t)
435 ;; If nothing to wait for, still remove possibly echo'ed commands
437 (nntp-accept-response)
441 (if (looking-at (regexp-quote command))
442 (delete-region pos (progn (forward-line 1) (gnus-point-at-bol))))
447 (defun nntp-send-buffer (wait-for)
448 "Send the current buffer to server and wait until WAIT-FOR returns."
449 (when (and (not nnheader-callback-function)
450 (not nntp-inhibit-output))
452 (set-buffer (nntp-find-connection-buffer nntp-server-buffer))
455 (process-send-region (nntp-find-connection nntp-server-buffer)
456 (point-min) (point-max))
458 nil nntp-address nntp-port-number nntp-server-buffer
459 wait-for nnheader-callback-function))
463 ;;; Interface functions.
465 (nnoo-define-basics nntp)
467 (defsubst nntp-next-result-arrived-p ()
469 ;; A result that starts with a 2xx code is terminated by
470 ;; a line with only a "." on it.
471 ((eq (char-after) ?2)
472 (if (re-search-forward "\n\\.\r?\n" nil t)
475 ;; A result that starts with a 3xx or 4xx code is terminated
478 (if (search-forward "\n" nil t)
485 (deffoo nntp-retrieve-headers (articles &optional group server fetch-old)
486 "Retrieve the headers of ARTICLES."
487 (nntp-possibly-change-group group server)
489 (set-buffer (nntp-find-connection-buffer nntp-server-buffer))
491 (if (and (not gnus-nov-is-evil)
492 (not nntp-nov-is-evil)
493 (nntp-retrieve-headers-with-xover articles fetch-old))
494 ;; We successfully retrieved the headers via XOVER.
496 ;; XOVER didn't work, so we do it the hard, slow and inefficient
498 (let ((number (length articles))
501 (last-point (point-min))
502 (buf (nntp-find-connection-buffer nntp-server-buffer))
503 (nntp-inhibit-erase t)
505 ;; Send HEAD commands.
506 (while (setq article (pop articles))
509 "HEAD" (if (numberp article)
510 (int-to-string article)
511 ;; `articles' is either a list of article numbers
512 ;; or a list of article IDs.
515 ;; Every 400 requests we have to read the stream in
516 ;; order to avoid deadlocks.
517 (when (or (null articles) ;All requests have been sent.
518 (zerop (% count nntp-maximum-request)))
519 (nntp-accept-response)
522 (goto-char last-point)
524 (while (nntp-next-result-arrived-p)
525 (setq last-point (point))
528 ;; If number of headers is greater than 100, give
529 ;; informative messages.
530 (and (numberp nntp-large-newsgroup)
531 (> number nntp-large-newsgroup)
532 (zerop (% received 20))
533 (nnheader-message 6 "NNTP: Receiving headers... %d%%"
534 (/ (* received 100) number)))
535 (nntp-accept-response))))
536 (and (numberp nntp-large-newsgroup)
537 (> number nntp-large-newsgroup)
538 (nnheader-message 6 "NNTP: Receiving headers...done"))
540 ;; Now all of replies are received. Fold continuation lines.
541 (nnheader-fold-continuation-lines)
542 ;; Remove all "\r"'s.
544 (copy-to-buffer nntp-server-buffer (point-min) (point-max))
547 (deffoo nntp-retrieve-groups (groups &optional server)
548 "Retrieve group info on GROUPS."
549 (nntp-possibly-change-group nil server)
550 (when (nntp-find-connection-buffer nntp-server-buffer)
553 ;; Erase nntp-server-buffer before nntp-inhibit-erase.
554 (set-buffer nntp-server-buffer)
556 (set-buffer (nntp-find-connection-buffer nntp-server-buffer))
557 ;; The first time this is run, this variable is `try'. So we
559 (when (eq nntp-server-list-active-group 'try)
560 (nntp-try-list-active (car groups)))
564 (last-point (point-min))
565 (nntp-inhibit-erase t)
566 (buf (nntp-find-connection-buffer nntp-server-buffer))
567 (command (if nntp-server-list-active-group "LIST ACTIVE" "GROUP")))
569 ;; Send the command to the server.
570 (nntp-send-command nil command (pop groups))
572 ;; Every 400 requests we have to read the stream in
573 ;; order to avoid deadlocks.
574 (when (or (null groups) ;All requests have been sent.
575 (zerop (% count nntp-maximum-request)))
576 (nntp-accept-response)
577 (while (and (gnus-buffer-live-p buf)
579 ;; Search `blue moon' in this file for the
580 ;; reason why set-buffer here.
582 (goto-char last-point)
584 (while (re-search-forward "^[0-9]" nil t)
586 (setq last-point (point))
588 (nntp-accept-response))))
590 ;; Wait for the reply from the final command.
591 (unless (gnus-buffer-live-p buf)
592 (nnheader-report 'nntp "Connection to %s is closed." server)
595 (goto-char (point-max))
596 (re-search-backward "^[0-9]" nil t)
597 (when (looking-at "^[23]")
598 (while (and (gnus-buffer-live-p buf)
601 (goto-char (point-max))
602 (if (not nntp-server-list-active-group)
603 (not (re-search-backward "\r?\n" (- (point) 3) t))
604 (not (re-search-backward "^\\.\r?\n"
606 (nntp-accept-response)))
608 ;; Now all replies are received. We remove CRs.
609 (unless (gnus-buffer-live-p buf)
610 (nnheader-report 'nntp "Connection to %s is closed." server)
613 (goto-char (point-min))
614 (while (search-forward "\r" nil t)
615 (replace-match "" t t))
617 (if (not nntp-server-list-active-group)
619 (copy-to-buffer nntp-server-buffer (point-min) (point-max))
621 ;; We have read active entries, so we just delete the
623 (goto-char (point-min))
624 (while (re-search-forward "^[.2-5]" nil t)
625 (delete-region (match-beginning 0)
626 (progn (forward-line 1) (point))))
627 (copy-to-buffer nntp-server-buffer (point-min) (point-max))
630 (deffoo nntp-retrieve-articles (articles &optional group server)
631 (nntp-possibly-change-group group server)
633 (let ((number (length articles))
636 (last-point (point-min))
637 (buf (nntp-find-connection-buffer nntp-server-buffer))
638 (nntp-inhibit-erase t)
639 (map (apply 'vector articles))
644 ;; Send ARTICLE command.
645 (while (setq article (pop articles))
648 "ARTICLE" (if (numberp article)
649 (int-to-string article)
650 ;; `articles' is either a list of article numbers
651 ;; or a list of article IDs.
654 ;; Every 400 requests we have to read the stream in
655 ;; order to avoid deadlocks.
656 (when (or (null articles) ;All requests have been sent.
657 (zerop (% count nntp-maximum-request)))
658 (nntp-accept-response)
661 (goto-char last-point)
663 (while (nntp-next-result-arrived-p)
664 (aset map received (cons (aref map received) (point)))
665 (setq last-point (point))
668 ;; If number of headers is greater than 100, give
669 ;; informative messages.
670 (and (numberp nntp-large-newsgroup)
671 (> number nntp-large-newsgroup)
672 (zerop (% received 20))
673 (nnheader-message 6 "NNTP: Receiving articles... %d%%"
674 (/ (* received 100) number)))
675 (nntp-accept-response))))
676 (and (numberp nntp-large-newsgroup)
677 (> number nntp-large-newsgroup)
678 (nnheader-message 6 "NNTP: Receiving articles...done"))
680 ;; Now we have all the responses. We go through the results,
681 ;; wash it and copy it over to the server buffer.
682 (set-buffer nntp-server-buffer)
684 (setq last-point (point-min))
688 (setq point (goto-char (point-max)))
690 (insert-buffer-substring buf last-point (cdr entry))
692 (setq last-point (cdr entry))
695 (cons (car entry) point))
698 (defun nntp-try-list-active (group)
699 (nntp-list-active-group group)
701 (set-buffer nntp-server-buffer)
702 (goto-char (point-min))
704 (looking-at "5[0-9]+"))
705 (setq nntp-server-list-active-group nil))
707 (setq nntp-server-list-active-group t)))))
709 (deffoo nntp-list-active-group (group &optional server)
710 "Return the active info on GROUP (which can be a regexp)."
711 (nntp-possibly-change-group nil server)
712 (nntp-send-command "^\\.*\r?\n" "LIST ACTIVE" group))
714 (deffoo nntp-request-group-articles (group &optional server)
715 "Return the list of existing articles in GROUP."
716 (nntp-possibly-change-group nil server)
717 (nntp-send-command "^\\.*\r?\n" "LISTGROUP" group))
719 (deffoo nntp-request-article (article &optional group server buffer command)
720 (nntp-possibly-change-group group server)
721 (when (nntp-send-command-and-decode
722 "\r?\n\\.\r?\n" "ARTICLE"
723 (if (numberp article) (int-to-string article) article))
725 (not (equal buffer nntp-server-buffer)))
727 (set-buffer nntp-server-buffer)
728 (copy-to-buffer buffer (point-min) (point-max))
729 (nntp-find-group-and-number))
730 (nntp-find-group-and-number))))
732 (deffoo nntp-request-head (article &optional group server)
733 (nntp-possibly-change-group group server)
734 (when (nntp-send-command
735 "\r?\n\\.\r?\n" "HEAD"
736 (if (numberp article) (int-to-string article) article))
738 (nntp-find-group-and-number)
739 (nntp-decode-text))))
741 (deffoo nntp-request-body (article &optional group server)
742 (nntp-possibly-change-group group server)
743 (nntp-send-command-and-decode
744 "\r?\n\\.\r?\n" "BODY"
745 (if (numberp article) (int-to-string article) article)))
747 (deffoo nntp-request-group (group &optional server dont-check)
748 (nntp-possibly-change-group nil server)
749 (when (nntp-send-command "^[245].*\n" "GROUP" group)
750 (let ((entry (nntp-find-connection-entry nntp-server-buffer)))
751 (setcar (cddr entry) group))))
753 (deffoo nntp-close-group (group &optional server)
756 (deffoo nntp-server-opened (&optional server)
757 "Say whether a connection to SERVER has been opened."
758 (and (nnoo-current-server-p 'nntp server)
760 (gnus-buffer-live-p nntp-server-buffer)
761 (nntp-find-connection nntp-server-buffer)))
763 (deffoo nntp-open-server (server &optional defs connectionless)
764 (nnheader-init-server-buffer)
765 (if (nntp-server-opened server)
767 (when (or (stringp (car defs))
768 (numberp (car defs)))
769 (setq defs (cons (list 'nntp-port-number (car defs)) (cdr defs))))
770 (unless (assq 'nntp-address defs)
771 (setq defs (append defs (list (list 'nntp-address server)))))
772 (nnoo-change-server 'nntp server defs)
773 (unless connectionless
774 (or (nntp-find-connection nntp-server-buffer)
775 (nntp-open-connection nntp-server-buffer)))))
777 (deffoo nntp-close-server (&optional server)
778 (nntp-possibly-change-group nil server t)
779 (let ((process (nntp-find-connection nntp-server-buffer)))
781 (when (memq (process-status process) '(open run))
783 (nntp-send-string process "QUIT")
784 (unless (eq nntp-open-connection-function 'nntp-open-network-stream)
785 ;; Ok, this is evil, but when using telnet and stuff
786 ;; as the connection method, it's important that the
787 ;; QUIT command actually is sent out before we kill
790 (nntp-kill-buffer (process-buffer process))
791 (setq process (car (pop nntp-connection-alist))))
792 (nnoo-close-server 'nntp)))
794 (deffoo nntp-request-close ()
796 (while (setq process (pop nntp-connection-list))
797 (when (memq (process-status process) '(open run))
799 (nntp-send-string process "QUIT")
800 (unless (eq nntp-open-connection-function 'nntp-open-network-stream)
801 ;; Ok, this is evil, but when using telnet and stuff
802 ;; as the connection method, it's important that the
803 ;; QUIT command actually is sent out before we kill
806 (nntp-kill-buffer (process-buffer process)))))
808 (deffoo nntp-request-list (&optional server)
809 (nntp-possibly-change-group nil server)
810 (nntp-send-command-and-decode "\r?\n\\.\r?\n" "LIST"))
812 (deffoo nntp-request-list-newsgroups (&optional server)
813 (nntp-possibly-change-group nil server)
814 (nntp-send-command "\r?\n\\.\r?\n" "LIST NEWSGROUPS"))
816 (deffoo nntp-request-newgroups (date &optional server)
817 (nntp-possibly-change-group nil server)
819 (set-buffer nntp-server-buffer)
820 (let* ((time (date-to-time date))
821 (ls (- (cadr time) (nth 8 (decode-time time)))))
823 (setcar time (1- (car time)))
824 (setcar (cdr time) (+ ls 65536)))
826 (setcar time (1+ (car time)))
827 (setcar (cdr time) (- ls 65536)))
829 (setcar (cdr time) ls)))
832 "^\\.\r?\n" "NEWGROUPS"
833 (format-time-string "%y%m%d %H%M%S" time)
835 (nntp-decode-text)))))
837 (deffoo nntp-request-post (&optional server)
838 (nntp-possibly-change-group nil server)
839 (when (nntp-send-command "^[23].*\r?\n" "POST")
840 (nntp-send-buffer "^[23].*\n")))
842 (deffoo nntp-request-type (group article)
845 (deffoo nntp-asynchronous-p ()
850 (defun nntp-send-mode-reader ()
851 "Send the MODE READER command to the nntp server.
852 This function is supposed to be called from `nntp-server-opened-hook'.
853 It will make innd servers spawn an nnrpd process to allow actual article
855 (nntp-send-command "^.*\n" "MODE READER"))
857 (defun nntp-send-authinfo (&optional send-if-force)
858 "Send the AUTHINFO to the nntp server.
859 It will look in the \"~/.authinfo\" file for matching entries. If
860 nothing suitable is found there, it will prompt for a user name
863 If SEND-IF-FORCE, only send authinfo to the server if the
864 .authinfo file has the FORCE token."
865 (let* ((list (gnus-parse-netrc nntp-authinfo-file))
866 (alist (gnus-netrc-machine list nntp-address "nntp"))
867 (force (gnus-netrc-get alist "force"))
868 (user (or (gnus-netrc-get alist "login") nntp-authinfo-user))
869 (passwd (gnus-netrc-get alist "password")))
870 (when (or (not send-if-force)
873 (setq user (read-string (format "NNTP (%s) user name: " nntp-address))
874 nntp-authinfo-user user))
875 (unless (member user '(nil ""))
876 (nntp-send-command "^3.*\r?\n" "AUTHINFO USER" user)
877 (when t ;???Should check if AUTHINFO succeeded
879 "^2.*\r?\n" "AUTHINFO PASS"
881 nntp-authinfo-password
882 (setq nntp-authinfo-password
883 (mail-source-read-passwd
884 (format "NNTP (%s@%s) password: "
885 user nntp-address))))))))))
887 (defun nntp-send-nosy-authinfo ()
888 "Send the AUTHINFO to the nntp server."
889 (let ((user (read-string (format "NNTP (%s) user name: " nntp-address))))
890 (unless (member user '(nil ""))
891 (nntp-send-command "^3.*\r?\n" "AUTHINFO USER" user)
892 (when t ;???Should check if AUTHINFO succeeded
893 (nntp-send-command "^2.*\r?\n" "AUTHINFO PASS"
894 (mail-source-read-passwd "NNTP (%s@%s) password: "
895 user nntp-address))))))
897 (defun nntp-send-authinfo-from-file ()
898 "Send the AUTHINFO to the nntp server.
900 The authinfo login name is taken from the user's login name and the
901 password contained in '~/.nntp-authinfo'."
902 (when (file-exists-p "~/.nntp-authinfo")
904 (insert-file-contents "~/.nntp-authinfo")
905 (goto-char (point-min))
906 (nntp-send-command "^3.*\r?\n" "AUTHINFO USER" (user-login-name))