1 ;;; nntp.el --- nntp access for Gnus
3 ;; Copyright (C) 1987-1990, 1992-1998, 2000-2011
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 3 of the License, or
14 ;; (at your option) any later version.
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. If not, see <http://www.gnu.org/licenses/>.
28 ;; For Emacs <22.2 and XEmacs.
30 (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
36 (require 'proto-stream)
37 (require 'gnus-group) ;; gnus-group-name-charset
41 (eval-when-compile (require 'cl))
43 (autoload 'auth-source-user-or-password "auth-source")
46 "NNTP access for Gnus."
49 (defvoo nntp-address nil
50 "Address of the physical nntp server.")
52 (defvoo nntp-port-number "nntp"
53 "Port number on the physical nntp server.")
55 (defvoo nntp-server-opened-hook '(nntp-send-mode-reader)
56 "*Hook used for sending commands to the server at startup.
57 The default value is `nntp-send-mode-reader', which makes an innd
58 server spawn an nnrpd server.")
60 (defvoo nntp-authinfo-function 'nntp-send-authinfo
61 "Function used to send AUTHINFO to the server.
62 It is called with no parameters.")
64 (defvoo nntp-server-action-alist
65 '(("nntpd 1\\.5\\.11t"
66 (remove-hook 'nntp-server-opened-hook 'nntp-send-mode-reader))
67 ("NNRP server Netscape"
68 (setq nntp-server-list-active-group nil)))
69 "Alist of regexps to match on server types and actions to be taken.
70 For instance, if you want Gnus to beep every time you connect
71 to innd, you could say something like:
73 \(setq nntp-server-action-alist
76 You probably don't want to do that, though.")
78 (defvoo nntp-open-connection-function 'nntp-open-network-stream
79 "*Function used for connecting to a remote system.
80 It will be called with the buffer to output in as argument.
82 Currently, five such functions are provided (please refer to their
83 respective doc string for more information), three of them establishing
84 direct connections to the nntp server, and two of them using an indirect
88 - `nntp-open-network-stream' (the default),
89 - `network-only' (the same as the above, but don't do automatic
91 - `nntp-open-ssl-stream',
92 - `nntp-open-tls-stream',
93 - `nntp-open-netcat-stream'.
94 - `nntp-open-telnet-stream'.
97 - `nntp-open-via-rlogin-and-netcat',
98 - `nntp-open-via-rlogin-and-telnet',
99 - `nntp-open-via-telnet-and-telnet'.")
101 (defvoo nntp-never-echoes-commands nil
102 "*Non-nil means the nntp server never echoes commands.
103 It is reported that some nntps server doesn't echo commands. So, you
104 may want to set this to non-nil in the method for such a server setting
105 `nntp-open-connection-function' to `nntp-open-ssl-stream' for example.
106 Note that the `nntp-open-connection-functions-never-echo-commands'
107 variable overrides the nil value of this variable.")
109 (defvoo nntp-open-connection-functions-never-echo-commands
110 '(nntp-open-network-stream)
111 "*List of functions that never echo commands.
112 Add or set a function which you set to `nntp-open-connection-function'
113 to this list if it does not echo commands. Note that a non-nil value
114 of the `nntp-never-echoes-commands' variable overrides this variable.")
116 (defvoo nntp-pre-command nil
117 "*Pre-command to use with the various nntp-open-via-* methods.
118 This is where you would put \"runsocks\" or stuff like that.")
120 (defvoo nntp-telnet-command "telnet"
121 "*Telnet command used to connect to the nntp server.
122 This command is used by the methods `nntp-open-telnet-stream',
123 `nntp-open-via-rlogin-and-telnet' and `nntp-open-via-telnet-and-telnet'.")
125 (defvoo nntp-telnet-switches '("-8")
126 "*Switches given to the telnet command `nntp-telnet-command'.")
128 (defvoo nntp-end-of-line "\r\n"
129 "*String to use on the end of lines when talking to the NNTP server.
130 This is \"\\r\\n\" by default, but should be \"\\n\" when using an indirect
131 connection method (nntp-open-via-*).")
133 (defvoo nntp-via-rlogin-command "rsh"
134 "*Rlogin command used to connect to an intermediate host.
135 This command is used by the methods `nntp-open-via-rlogin-and-telnet'
136 and `nntp-open-via-rlogin-and-netcat'. The default is \"rsh\", but \"ssh\"
137 is a popular alternative.")
139 (defvoo nntp-via-rlogin-command-switches nil
140 "*Switches given to the rlogin command `nntp-via-rlogin-command'.
141 If you use \"ssh\" for `nntp-via-rlogin-command', you may set this to
142 \(\"-C\") in order to compress all data connections, otherwise set this
143 to \(\"-t\" \"-e\" \"none\") or (\"-C\" \"-t\" \"-e\" \"none\") if the telnet
144 command requires a pseudo-tty allocation on an intermediate host.")
146 (defvoo nntp-via-telnet-command "telnet"
147 "*Telnet command used to connect to an intermediate host.
148 This command is used by the `nntp-open-via-telnet-and-telnet' method.")
150 (defvoo nntp-via-telnet-switches '("-8")
151 "*Switches given to the telnet command `nntp-via-telnet-command'.")
153 (defvoo nntp-netcat-command "nc"
154 "*Netcat command used to connect to the nntp server.
155 This command is used by the `nntp-open-netcat-stream' and
156 `nntp-open-via-rlogin-and-netcat' methods.")
158 (defvoo nntp-netcat-switches nil
159 "*Switches given to the netcat command `nntp-netcat-command'.")
161 (defvoo nntp-via-user-name nil
162 "*User name to log in on an intermediate host with.
163 This variable is used by the various nntp-open-via-* methods.")
165 (defvoo nntp-via-user-password nil
166 "*Password to use to log in on an intermediate host with.
167 This variable is used by the `nntp-open-via-telnet-and-telnet' method.")
169 (defvoo nntp-via-address nil
170 "*Address of an intermediate host to connect to.
171 This variable is used by the various nntp-open-via-* methods.")
173 (defvoo nntp-via-envuser nil
174 "*Whether both telnet client and server support the ENVIRON option.
175 If non-nil, there will be no prompt for a login name.")
177 (defvoo nntp-via-shell-prompt "bash\\|\$ *\r?$\\|> *\r?"
178 "*Regular expression to match the shell prompt on an intermediate host.
179 This variable is used by the `nntp-open-via-telnet-and-telnet' method.")
181 (defvoo nntp-large-newsgroup 50
182 "*The number of articles which indicates a large newsgroup.
183 If the number of articles is greater than the value, verbose
184 messages will be shown to indicate the current status.")
186 (defvoo nntp-maximum-request 400
187 "*The maximum number of the requests sent to the NNTP server at one time.
188 If Emacs hangs up while retrieving headers, set the variable to a
191 (defvoo nntp-nov-is-evil nil
192 "*If non-nil, nntp will never attempt to use XOVER when talking to the server.")
194 (defvoo nntp-xover-commands '("XOVER" "XOVERVIEW")
195 "*List of strings that are used as commands to fetch NOV lines from a server.
196 The strings are tried in turn until a positive response is gotten. If
197 none of the commands are successful, nntp will just grab headers one
200 (defvoo nntp-nov-gap 5
201 "*Maximum allowed gap between two articles.
202 If the gap between two consecutive articles is bigger than this
203 variable, split the XOVER request into two requests.")
205 (defvoo nntp-xref-number-is-evil nil
206 "*If non-nil, Gnus never trusts article numbers in the Xref header.
207 Some news servers, e.g., ones running Diablo, run multiple engines
208 having the same articles but article numbers are not kept synchronized
209 between them. If you connect to such a server, set this to a non-nil
210 value, and Gnus never uses article numbers (that appear in the Xref
211 header and vary by which engine is chosen) to refer to articles.")
213 (defvoo nntp-prepare-server-hook nil
214 "*Hook run before a server is opened.
215 If can be used to set up a server remotely, for instance. Say you
216 have an account at the machine \"other.machine\". This machine has
217 access to an NNTP server that you can't access locally. You could
218 then use this hook to rsh to the remote machine and start a proxy NNTP
219 server there that you can connect to. See also
220 `nntp-open-connection-function'")
222 (defvoo nntp-coding-system-for-read 'binary
223 "*Coding system to read from NNTP.")
225 (defvoo nntp-coding-system-for-write 'binary
226 "*Coding system to write to NNTP.")
229 (defvoo nntp-marks-is-evil nil
230 "*If non-nil, Gnus will never generate and use marks file for nntp groups.
231 See `nnml-marks-is-evil' for more information.")
233 (defvoo nntp-marks-file-name ".marks")
234 (defvoo nntp-marks nil)
235 (defvar nntp-marks-modtime (gnus-make-hashtable))
237 (defcustom nntp-marks-directory
238 (nnheader-concat gnus-directory "marks/")
239 "*The directory where marks for nntp groups will be stored."
243 (defcustom nntp-authinfo-file "~/.authinfo"
244 ".netrc-like file that holds nntp authinfo passwords."
248 (repeat :tag "Entries"
251 :value ("" ("login" . "") ("password" . ""))
255 (const :format "" "login")
256 (string :format "Login: %v"))
258 (const :format "" "password")
259 (string :format "Password: %v")))))))
263 (defvoo nntp-connection-timeout nil
264 "*Number of seconds to wait before an nntp connection times out.
265 If this variable is nil, which is the default, no timers are set.
266 NOTE: This variable is never seen to work in Emacs 20 and XEmacs 21.")
268 (defvoo nntp-prepare-post-hook nil
269 "*Hook run just before posting an article. It is supposed to be used
270 to insert Cancel-Lock headers.")
272 (defvoo nntp-server-list-active-group 'try
273 "If nil, then always use GROUP instead of LIST ACTIVE.
274 This is usually slower, but on misconfigured servers that don't
275 update their active files often, this can help.")
277 ;;; Internal variables.
279 (defvar nntp-record-commands nil
280 "*If non-nil, nntp will record all commands in the \"*nntp-log*\" buffer.")
282 (defvar nntp-have-messaged nil)
284 (defvar nntp-process-wait-for nil)
285 (defvar nntp-process-to-buffer nil)
286 (defvar nntp-process-callback nil)
287 (defvar nntp-process-decode nil)
288 (defvar nntp-process-start-point nil)
289 (defvar nntp-inside-change-function nil)
290 (defvoo nntp-last-command-time nil)
291 (defvoo nntp-last-command nil)
292 (defvoo nntp-authinfo-password nil)
293 (defvoo nntp-authinfo-user nil)
294 (defvoo nntp-authinfo-force nil)
296 (defvar nntp-connection-list nil)
298 (defvoo nntp-server-type nil)
299 (defvoo nntp-connection-alist nil)
300 (defvoo nntp-status-string "")
301 (defconst nntp-version "nntp 5.0")
302 (defvoo nntp-inhibit-erase nil)
303 (defvoo nntp-inhibit-output nil)
305 (defvoo nntp-server-xover 'try)
307 (defvar nntp-async-timer nil)
308 (defvar nntp-async-process-list nil)
310 (defvar nntp-authinfo-rejected nil
311 "A custom error condition used to report 'Authentication Rejected' errors.
312 Condition handlers that match just this condition ensure that the nntp
313 backend doesn't catch this error.")
314 (put 'nntp-authinfo-rejected 'error-conditions '(error nntp-authinfo-rejected))
315 (put 'nntp-authinfo-rejected 'error-message "Authorization Rejected")
319 ;;; Internal functions.
321 (defsubst nntp-send-string (process string)
322 "Send STRING to PROCESS."
323 ;; We need to store the time to provide timeouts, and
324 ;; to store the command so the we can replay the command
325 ;; if the server gives us an AUTHINFO challenge.
326 (setq nntp-last-command-time (current-time)
327 nntp-last-command string)
328 (when nntp-record-commands
329 (nntp-record-command string))
330 (process-send-string process (concat string nntp-end-of-line))
331 (or (memq (process-status process) '(open run))
332 (nntp-report "Server closed connection")))
334 (defun nntp-record-command (string)
335 "Record the command STRING."
336 (with-current-buffer (get-buffer-create "*nntp-log*")
337 (goto-char (point-max))
338 (let ((time (current-time)))
339 (insert (format-time-string "%Y%m%dT%H%M%S" time)
340 "." (format "%03d" (/ (nth 2 time) 1000))
341 " " nntp-address " " string "\n"))))
343 (defun nntp-report (&rest args)
344 "Report an error from the nntp backend. The first string in ARGS
345 can be a format string. For some commands, the failed command may be
346 retried once before actually displaying the error report."
348 (when nntp-record-commands
349 (nntp-record-command "*** CALLED nntp-report ***"))
351 (nnheader-report 'nntp args)
355 (defun nntp-report-1 (&rest args)
356 "Throws out to nntp-with-open-group-error so that the connection may
357 be restored and the command retried."
359 (when nntp-record-commands
360 (nntp-record-command "*** CONNECTION LOST ***"))
362 (throw 'nntp-with-open-group-error t))
364 (defmacro nntp-insert-buffer-substring (buffer &optional start end)
365 "Copy string from unibyte buffer to multibyte current buffer."
366 (if (featurep 'xemacs)
367 `(insert-buffer-substring ,buffer ,start ,end)
368 `(if enable-multibyte-characters
369 (insert (with-current-buffer ,buffer
370 (mm-string-to-multibyte
372 `(buffer-substring (or ,start (point-min))
373 (or ,end (point-max)))
375 (insert-buffer-substring ,buffer ,start ,end))))
377 (defmacro nntp-copy-to-buffer (buffer start end)
378 "Copy string from unibyte current buffer to multibyte buffer."
379 (if (featurep 'xemacs)
380 `(copy-to-buffer ,buffer ,start ,end)
381 `(let ((string (buffer-substring ,start ,end)))
382 (with-current-buffer ,buffer
384 (insert (if enable-multibyte-characters
385 (mm-string-to-multibyte string)
387 (goto-char (point-min))
390 (defsubst nntp-wait-for (process wait-for buffer &optional decode discard)
391 "Wait for WAIT-FOR to arrive from PROCESS."
393 (with-current-buffer (process-buffer process)
394 (goto-char (point-min))
396 (while (and (or (not (memq (char-after (point)) '(?2 ?3 ?4 ?5)))
397 (looking-at "48[02]"))
398 (memq (process-status process) '(open run)))
399 (cond ((looking-at "480")
400 (nntp-handle-authinfo process))
402 (nnheader-report 'nntp "%s"
403 (get 'nntp-authinfo-rejected 'error-message))
404 (signal 'nntp-authinfo-rejected nil))
405 ((looking-at "^.*\n")
406 (delete-region (point) (progn (forward-line 1) (point)))))
407 (nntp-accept-process-output process)
408 (goto-char (point-min)))
413 (nntp-snarf-error-message)
415 ((not (memq (process-status process) '(open run)))
416 (nntp-report "Server closed connection"))
418 (goto-char (point-max))
419 (let ((limit (point-min))
421 (while (not (re-search-backward wait-for limit t))
422 (nntp-accept-process-output process)
423 ;; We assume that whatever we wait for is less than 1000
425 (setq limit (max (- (point-max) 1000) (point-min)))
426 (goto-char (point-max)))
427 (setq response (match-string 0))
428 (with-current-buffer nntp-server-buffer
429 (setq nntp-process-response response)))
430 (nntp-decode-text (not decode))
432 (with-current-buffer buffer
433 (goto-char (point-max))
434 (nntp-insert-buffer-substring (process-buffer process))
435 ;; Nix out "nntp reading...." message.
436 (when nntp-have-messaged
437 (setq nntp-have-messaged nil)
438 (nnheader-message 5 ""))))
443 (defun nntp-kill-buffer (buffer)
444 (when (buffer-name buffer)
446 (nnheader-init-server-buffer)))
448 (defun nntp-erase-buffer (buffer)
449 "Erase contents of BUFFER."
450 (with-current-buffer buffer
453 (defsubst nntp-find-connection (buffer)
454 "Find the connection delivering to BUFFER."
455 (let ((alist nntp-connection-alist)
456 (buffer (if (stringp buffer) (get-buffer buffer) buffer))
458 (while (and alist (setq entry (pop alist)))
459 (when (eq buffer (cadr entry))
460 (setq process (car entry)
463 (if (memq (process-status process) '(open run))
465 (nntp-kill-buffer (process-buffer process))
466 (setq nntp-connection-alist (delq entry nntp-connection-alist))
469 (defsubst nntp-find-connection-entry (buffer)
470 "Return the entry for the connection to BUFFER."
471 (assq (nntp-find-connection buffer) nntp-connection-alist))
473 (defun nntp-find-connection-buffer (buffer)
474 "Return the process connection buffer tied to BUFFER."
475 (let ((process (nntp-find-connection buffer)))
477 (process-buffer process))))
479 (defsubst nntp-retrieve-data (command address port buffer
480 &optional wait-for callback decode)
481 "Use COMMAND to retrieve data into BUFFER from PORT on ADDRESS."
482 (let ((process (or (nntp-find-connection buffer)
483 (nntp-open-connection buffer))))
486 (unless (or nntp-inhibit-erase nnheader-callback-function)
487 (nntp-erase-buffer (process-buffer process)))
491 (nntp-send-string process command))
493 ((eq callback 'ignore)
495 ((and callback wait-for)
496 (nntp-async-wait process wait-for buffer decode callback)
499 (nntp-wait-for process wait-for buffer decode))
501 (nntp-authinfo-rejected
502 (signal 'nntp-authinfo-rejected (cdr err)))
504 (nnheader-report 'nntp "Couldn't open connection to %s: %s"
507 (message "Quit retrieving data from nntp")
510 (nnheader-report 'nntp "Couldn't open connection to %s" address))))
512 (defsubst nntp-send-command (wait-for &rest strings)
513 "Send STRINGS to server and wait until WAIT-FOR returns."
514 (when (and (not nnheader-callback-function)
515 (not nntp-inhibit-output))
516 (nntp-erase-buffer nntp-server-buffer))
517 (let* ((command (mapconcat 'identity strings " "))
518 (process (nntp-find-connection nntp-server-buffer))
519 (buffer (and process (process-buffer process)))
520 (pos (and buffer (with-current-buffer buffer (point)))))
523 (nntp-retrieve-data command
524 nntp-address nntp-port-number
526 wait-for nnheader-callback-function)
527 ;; If nothing to wait for, still remove possibly echo'ed commands.
528 ;; We don't have echoes if `nntp-never-echoes-commands' is non-nil
529 ;; or the value of `nntp-open-connection-function' is in
530 ;; `nntp-open-connection-functions-never-echo-commands', so we
531 ;; skip this in that cases.
533 nntp-never-echoes-commands
535 nntp-open-connection-function
536 nntp-open-connection-functions-never-echo-commands))
537 (nntp-accept-response)
538 (with-current-buffer buffer
540 (if (looking-at (regexp-quote command))
541 (delete-region pos (progn (forward-line 1)
543 (nnheader-report 'nntp "Couldn't open connection to %s."
546 (defun nntp-send-command-nodelete (wait-for &rest strings)
547 "Send STRINGS to server and wait until WAIT-FOR returns."
548 (let* ((command (mapconcat 'identity strings " "))
549 (process (nntp-find-connection nntp-server-buffer))
550 (buffer (and process (process-buffer process)))
551 (pos (and buffer (with-current-buffer buffer (point)))))
554 (nntp-retrieve-data command
555 nntp-address nntp-port-number
557 wait-for nnheader-callback-function)
558 ;; If nothing to wait for, still remove possibly echo'ed commands
560 (nntp-accept-response)
561 (with-current-buffer buffer
563 (if (looking-at (regexp-quote command))
564 (delete-region pos (progn (forward-line 1)
566 (nnheader-report 'nntp "Couldn't open connection to %s."
569 (defun nntp-send-command-and-decode (wait-for &rest strings)
570 "Send STRINGS to server and wait until WAIT-FOR returns."
571 (when (and (not nnheader-callback-function)
572 (not nntp-inhibit-output))
573 (nntp-erase-buffer nntp-server-buffer))
574 (let* ((command (mapconcat 'identity strings " "))
575 (process (nntp-find-connection nntp-server-buffer))
576 (buffer (and process (process-buffer process)))
577 (pos (and buffer (with-current-buffer buffer (point)))))
580 (nntp-retrieve-data command
581 nntp-address nntp-port-number
583 wait-for nnheader-callback-function t)
584 ;; If nothing to wait for, still remove possibly echo'ed commands
586 (nntp-accept-response)
587 (with-current-buffer buffer
589 (if (looking-at (regexp-quote command))
590 (delete-region pos (progn (forward-line 1) (point-at-bol))))
592 (nnheader-report 'nntp "Couldn't open connection to %s."
596 (defun nntp-send-buffer (wait-for)
597 "Send the current buffer to server and wait until WAIT-FOR returns."
598 (when (and (not nnheader-callback-function)
599 (not nntp-inhibit-output))
601 (nntp-find-connection-buffer nntp-server-buffer)))
603 ;; Make sure we did not forget to encode some of the content.
604 (assert (save-excursion (goto-char (point-min))
605 (not (re-search-forward "[^\000-\377]" nil t))))
606 (mm-disable-multibyte)
607 (process-send-region (nntp-find-connection nntp-server-buffer)
608 (point-min) (point-max))
610 nil nntp-address nntp-port-number nntp-server-buffer
611 wait-for nnheader-callback-function))
615 ;;; Interface functions.
617 (nnoo-define-basics nntp)
619 (defsubst nntp-next-result-arrived-p ()
621 ;; A result that starts with a 2xx code is terminated by
622 ;; a line with only a "." on it.
623 ((eq (char-after) ?2)
624 (if (re-search-forward "\n\\.\r?\n" nil t)
626 ;; Some broken news servers add another dot at the end.
627 ;; Protect against inflooping there.
628 (while (looking-at "^\\.\r?\n")
632 ;; A result that starts with a 3xx or 4xx code is terminated
635 (if (search-forward "\n" nil t)
643 (defvar nntp-with-open-group-internal nil)
644 (defvar nntp-report-n nil))
646 (defun nntp-with-open-group-function (-group -server -connectionless -bodyfun)
647 "Protect against servers that don't like clients that keep idle connections opens.
648 The problem being that these servers may either close a connection or
649 simply ignore any further requests on a connection. Closed
650 connections are not detected until `accept-process-output' has updated
651 the `process-status'. Dropped connections are not detected until the
652 connection timeouts (which may be several minutes) or
653 `nntp-connection-timeout' has expired. When these occur
654 `nntp-with-open-group', opens a new connection then re-issues the NNTP
655 command whose response triggered the error."
656 (letf ((nntp-report-n (symbol-function 'nntp-report))
657 ((symbol-function 'nntp-report) (symbol-function 'nntp-report-1))
658 (nntp-with-open-group-internal nil))
659 (while (catch 'nntp-with-open-group-error
660 ;; Open the connection to the server
661 ;; NOTE: Existing connections are NOT tested.
662 (nntp-possibly-change-group -group -server -connectionless)
665 (and nntp-connection-timeout
667 nntp-connection-timeout nil
669 (let* ((-process (nntp-find-connection
671 (-buffer (and -process
672 (process-buffer -process))))
673 ;; When I an able to identify the
674 ;; connection to the server AND I've
675 ;; received NO reponse for
676 ;; nntp-connection-timeout seconds.
677 (when (and -buffer (eq 0 (buffer-size -buffer)))
678 ;; Close the connection. Take no
679 ;; other action as the accept input
680 ;; code will handle the closed
682 (nntp-kill-buffer -buffer))))))))
684 (setq nntp-with-open-group-internal
688 (unless debug-on-quit
690 (signal 'quit nil))))
692 (nnheader-cancel-timer -timer)))
694 (setf (symbol-function 'nntp-report) nntp-report-n))
695 nntp-with-open-group-internal))
697 (defmacro nntp-with-open-group (group server &optional connectionless &rest forms)
698 "Protect against servers that don't like clients that keep idle connections opens.
699 The problem being that these servers may either close a connection or
700 simply ignore any further requests on a connection. Closed
701 connections are not detected until `accept-process-output' has updated
702 the `process-status'. Dropped connections are not detected until the
703 connection timeouts (which may be several minutes) or
704 `nntp-connection-timeout' has expired. When these occur
705 `nntp-with-open-group', opens a new connection then re-issues the NNTP
706 command whose response triggered the error."
707 (declare (indent 2) (debug (form form [&optional symbolp] def-body)))
708 (when (and (listp connectionless)
709 (not (eq connectionless nil)))
710 (setq forms (cons connectionless forms)
712 `(nntp-with-open-group-function ,group ,server ,connectionless (lambda () ,@forms)))
714 (deffoo nntp-retrieve-headers (articles &optional group server fetch-old)
715 "Retrieve the headers of ARTICLES."
716 (nntp-with-open-group
718 (with-current-buffer (nntp-find-connection-buffer nntp-server-buffer)
720 (if (and (not gnus-nov-is-evil)
721 (not nntp-nov-is-evil)
722 (nntp-retrieve-headers-with-xover articles fetch-old))
723 ;; We successfully retrieved the headers via XOVER.
725 ;; XOVER didn't work, so we do it the hard, slow and inefficient
727 (let ((number (length articles))
731 (last-point (point-min))
732 (buf (nntp-find-connection-buffer nntp-server-buffer))
733 (nntp-inhibit-erase t)
735 ;; Send HEAD commands.
736 (while (setq article (pop articles))
739 "HEAD" (if (numberp article)
740 (int-to-string article)
741 ;; `articles' is either a list of article numbers
742 ;; or a list of article IDs.
745 ;; Every 400 requests we have to read the stream in
746 ;; order to avoid deadlocks.
747 (when (or (null articles) ;All requests have been sent.
748 (zerop (% count nntp-maximum-request)))
749 (nntp-accept-response)
752 (goto-char last-point)
754 (while (nntp-next-result-arrived-p)
755 (setq last-point (point))
758 ;; If number of headers is greater than 100, give
759 ;; informative messages.
760 (and (numberp nntp-large-newsgroup)
761 (> number nntp-large-newsgroup)
762 (zerop (% received 20))
763 (nnheader-message 6 "NNTP: Receiving headers... %d%%"
764 (/ (* received 100) number)))
765 (nntp-accept-response))))
766 (and (numberp nntp-large-newsgroup)
767 (> number nntp-large-newsgroup)
768 (nnheader-message 6 "NNTP: Receiving headers...done"))
770 ;; Now all of replies are received. Fold continuation lines.
771 (nnheader-fold-continuation-lines)
772 ;; Remove all "\r"'s.
774 (nntp-copy-to-buffer nntp-server-buffer (point-min) (point-max))
777 (deffoo nntp-retrieve-groups (groups &optional server)
778 "Retrieve group info on GROUPS."
779 (nntp-with-open-group
781 (when (nntp-find-connection-buffer nntp-server-buffer)
784 ;; Erase nntp-server-buffer before nntp-inhibit-erase.
785 (nntp-erase-buffer nntp-server-buffer)
786 (set-buffer (nntp-find-connection-buffer nntp-server-buffer))
787 ;; The first time this is run, this variable is `try'. So we
789 (when (eq nntp-server-list-active-group 'try)
790 (nntp-try-list-active (car groups)))
795 (last-point (point-min))
796 (nntp-inhibit-erase t)
797 (buf (nntp-find-connection-buffer nntp-server-buffer))
798 (command (if nntp-server-list-active-group
799 "LIST ACTIVE" "GROUP")))
801 ;; Timeout may have killed the buffer.
802 (unless (gnus-buffer-live-p buf)
803 (nnheader-report 'nntp "Connection to %s is closed." server)
805 ;; Send the command to the server.
806 (nntp-send-command nil command (pop groups))
808 ;; Every 400 requests we have to read the stream in
809 ;; order to avoid deadlocks.
810 (when (or (null groups) ;All requests have been sent.
811 (zerop (% count nntp-maximum-request)))
812 (nntp-accept-response)
813 (while (and (gnus-buffer-live-p buf)
815 ;; Search `blue moon' in this file for the
816 ;; reason why set-buffer here.
818 (goto-char last-point)
820 (while (re-search-forward "^[0-9]" nil t)
822 (setq last-point (point))
824 (nntp-accept-response))))
826 ;; Wait for the reply from the final command.
827 (unless (gnus-buffer-live-p buf)
828 (nnheader-report 'nntp "Connection to %s is closed." server)
831 (goto-char (point-max))
832 (re-search-backward "^[0-9]" nil t)
833 (when (looking-at "^[23]")
834 (while (and (gnus-buffer-live-p buf)
837 (goto-char (point-max))
838 (if (not nntp-server-list-active-group)
839 (not (re-search-backward "\r?\n"
841 (not (re-search-backward "^\\.\r?\n"
843 (nntp-accept-response)))
845 ;; Now all replies are received. We remove CRs.
846 (unless (gnus-buffer-live-p buf)
847 (nnheader-report 'nntp "Connection to %s is closed." server)
850 (goto-char (point-min))
851 (while (search-forward "\r" nil t)
852 (replace-match "" t t))
854 (if (not nntp-server-list-active-group)
856 (nntp-copy-to-buffer nntp-server-buffer
857 (point-min) (point-max))
859 ;; We have read active entries, so we just delete the
861 (goto-char (point-min))
862 (while (re-search-forward "^[.2-5]" nil t)
863 (delete-region (match-beginning 0)
864 (progn (forward-line 1) (point))))
865 (nntp-copy-to-buffer nntp-server-buffer (point-min) (point-max))
868 (deffoo nntp-retrieve-articles (articles &optional group server)
869 (nntp-with-open-group
872 (let ((number (length articles))
876 (last-point (point-min))
877 (buf (nntp-find-connection-buffer nntp-server-buffer))
878 (nntp-inhibit-erase t)
879 (map (apply 'vector articles))
884 ;; Send ARTICLE command.
885 (while (setq article (pop articles))
888 "ARTICLE" (if (numberp article)
889 (int-to-string article)
890 ;; `articles' is either a list of article numbers
891 ;; or a list of article IDs.
894 ;; Every 400 requests we have to read the stream in
895 ;; order to avoid deadlocks.
896 (when (or (null articles) ;All requests have been sent.
897 (zerop (% count nntp-maximum-request)))
898 (nntp-accept-response)
901 (goto-char last-point)
903 (while (nntp-next-result-arrived-p)
904 (aset map received (cons (aref map received) (point)))
905 (setq last-point (point))
908 ;; If number of headers is greater than 100, give
909 ;; informative messages.
910 (and (numberp nntp-large-newsgroup)
911 (> number nntp-large-newsgroup)
912 (zerop (% received 20))
913 (nnheader-message 6 "NNTP: Receiving articles... %d%%"
914 (/ (* received 100) number)))
915 (nntp-accept-response))))
916 (and (numberp nntp-large-newsgroup)
917 (> number nntp-large-newsgroup)
918 (nnheader-message 6 "NNTP: Receiving articles...done"))
920 ;; Now we have all the responses. We go through the results,
921 ;; wash it and copy it over to the server buffer.
922 (set-buffer nntp-server-buffer)
924 (setq last-point (point-min))
928 (setq point (goto-char (point-max)))
930 (nntp-insert-buffer-substring buf last-point (cdr entry))
932 (setq last-point (cdr entry))
935 (cons (car entry) point))
938 (defun nntp-try-list-active (group)
939 (nntp-list-active-group group)
940 (with-current-buffer nntp-server-buffer
941 (goto-char (point-min))
943 (looking-at "5[0-9]+"))
944 (setq nntp-server-list-active-group nil))
946 (setq nntp-server-list-active-group t)))))
948 (deffoo nntp-list-active-group (group &optional server)
949 "Return the active info on GROUP (which can be a regexp)."
950 (nntp-with-open-group
952 (nntp-send-command "^\\.*\r?\n" "LIST ACTIVE" group)))
954 (deffoo nntp-request-group-articles (group &optional server)
955 "Return the list of existing articles in GROUP."
956 (nntp-with-open-group
958 (nntp-send-command "^\\.*\r?\n" "LISTGROUP" group)))
960 (deffoo nntp-request-article (article &optional group server buffer command)
961 (nntp-with-open-group
963 (when (nntp-send-command-and-decode
964 "\r?\n\\.\r?\n" "ARTICLE"
965 (if (numberp article) (int-to-string article) article))
967 (not (equal buffer nntp-server-buffer)))
968 (with-current-buffer nntp-server-buffer
969 (copy-to-buffer buffer (point-min) (point-max))
970 (nntp-find-group-and-number group))
971 (nntp-find-group-and-number group)))))
973 (deffoo nntp-request-head (article &optional group server)
974 (nntp-with-open-group
976 (when (nntp-send-command
977 "\r?\n\\.\r?\n" "HEAD"
978 (if (numberp article) (int-to-string article) article))
980 (nntp-find-group-and-number group)
981 (nntp-decode-text)))))
983 (deffoo nntp-request-body (article &optional group server)
984 (nntp-with-open-group
986 (nntp-send-command-and-decode
987 "\r?\n\\.\r?\n" "BODY"
988 (if (numberp article) (int-to-string article) article))))
990 (deffoo nntp-request-group (group &optional server dont-check info)
991 (nntp-with-open-group
993 (when (nntp-send-command "^[245].*\n" "GROUP" group)
994 (let ((entry (nntp-find-connection-entry nntp-server-buffer)))
995 (setcar (cddr entry) group)))))
997 (deffoo nntp-close-group (group &optional server)
1000 (deffoo nntp-server-opened (&optional server)
1001 "Say whether a connection to SERVER has been opened."
1002 (and (nnoo-current-server-p 'nntp server)
1004 (gnus-buffer-live-p nntp-server-buffer)
1005 (nntp-find-connection nntp-server-buffer)))
1007 (deffoo nntp-open-server (server &optional defs connectionless)
1008 (nnheader-init-server-buffer)
1009 (if (nntp-server-opened server)
1011 (when (or (stringp (car defs))
1012 (numberp (car defs)))
1013 (setq defs (cons (list 'nntp-port-number (car defs)) (cdr defs))))
1014 (unless (assq 'nntp-address defs)
1015 (setq defs (append defs (list (list 'nntp-address server)))))
1016 (nnoo-change-server 'nntp server defs)
1019 (or (nntp-find-connection nntp-server-buffer)
1020 (nntp-open-connection nntp-server-buffer)))))
1022 (deffoo nntp-close-server (&optional server)
1023 (nntp-possibly-change-group nil server t)
1024 (let ((process (nntp-find-connection nntp-server-buffer)))
1026 (when (memq (process-status process) '(open run))
1028 (nntp-send-string process "QUIT")
1029 (unless (eq nntp-open-connection-function 'nntp-open-network-stream)
1030 ;; Ok, this is evil, but when using telnet and stuff
1031 ;; as the connection method, it's important that the
1032 ;; QUIT command actually is sent out before we kill
1035 (nntp-kill-buffer (process-buffer process))
1036 (setq process (car (pop nntp-connection-alist))))
1037 (nnoo-close-server 'nntp)))
1039 (deffoo nntp-request-close ()
1041 (while (setq process (pop nntp-connection-list))
1042 (when (memq (process-status process) '(open run))
1044 (nntp-send-string process "QUIT")
1045 (unless (eq nntp-open-connection-function 'nntp-open-network-stream)
1046 ;; Ok, this is evil, but when using telnet and stuff
1047 ;; as the connection method, it's important that the
1048 ;; QUIT command actually is sent out before we kill
1051 (nntp-kill-buffer (process-buffer process)))))
1053 (deffoo nntp-request-list (&optional server)
1054 (nntp-with-open-group
1056 (nntp-send-command-and-decode "\r?\n\\.\r?\n" "LIST")))
1058 (deffoo nntp-request-list-newsgroups (&optional server)
1059 (nntp-with-open-group
1061 (nntp-send-command "\r?\n\\.\r?\n" "LIST NEWSGROUPS")))
1063 (deffoo nntp-request-newgroups (date &optional server)
1064 (nntp-with-open-group
1066 (with-current-buffer nntp-server-buffer
1067 (let* ((time (date-to-time date))
1068 (ls (- (cadr time) (nth 8 (decode-time time)))))
1070 (setcar time (1- (car time)))
1071 (setcar (cdr time) (+ ls 65536)))
1073 (setcar time (1+ (car time)))
1074 (setcar (cdr time) (- ls 65536)))
1076 (setcar (cdr time) ls)))
1079 "^\\.\r?\n" "NEWGROUPS"
1080 (format-time-string "%y%m%d %H%M%S" time)
1082 (nntp-decode-text))))))
1084 (deffoo nntp-request-post (&optional server)
1085 (nntp-with-open-group
1087 (when (nntp-send-command "^[23].*\r?\n" "POST")
1088 (let ((response (with-current-buffer nntp-server-buffer
1089 nntp-process-response))
1092 (string-match "^[23].*\\(<[^\t\n @<>]+@[^\t\n @<>]+>\\)"
1094 (setq server-id (match-string 1 response))
1095 (narrow-to-region (goto-char (point-min))
1096 (if (search-forward "\n\n" nil t)
1099 (unless (mail-fetch-field "Message-ID")
1100 (goto-char (point-min))
1101 (insert "Message-ID: " server-id "\n"))
1103 (run-hooks 'nntp-prepare-post-hook)
1104 (nntp-send-buffer "^[23].*\n")))))
1106 (deffoo nntp-request-type (group article)
1109 (deffoo nntp-asynchronous-p ()
1112 (deffoo nntp-request-set-mark (group actions &optional server)
1113 (when (and (not nntp-marks-is-evil)
1114 nntp-marks-file-name)
1115 (nntp-possibly-create-directory group server)
1116 (nntp-open-marks group server)
1117 (setq nntp-marks (nnheader-update-marks-actions nntp-marks actions))
1118 (nntp-save-marks group server))
1121 (deffoo nntp-request-marks (group info &optional server)
1122 (when (and (not nntp-marks-is-evil)
1123 nntp-marks-file-name)
1124 (nntp-possibly-create-directory group server)
1125 (when (nntp-marks-changed-p group server)
1126 (nnheader-message 8 "Updating marks for %s..." group)
1127 (nntp-open-marks group server)
1128 ;; Update info using `nntp-marks'.
1129 (mapc (lambda (pred)
1130 (unless (memq (cdr pred) gnus-article-unpropagated-mark-lists)
1131 (gnus-info-set-marks
1133 (gnus-update-alist-soft
1135 (cdr (assq (cdr pred) nntp-marks))
1136 (gnus-info-marks info))
1138 gnus-article-mark-lists)
1139 (let ((seen (cdr (assq 'read nntp-marks))))
1140 (gnus-info-set-read info
1141 (if (and (integerp (car seen))
1143 (list (cons (car seen) (car seen)))
1145 (nnheader-message 8 "Updating marks for %s...done" group)))
1150 ;;; Hooky functions.
1152 (defun nntp-send-mode-reader ()
1153 "Send the MODE READER command to the nntp server.
1154 This function is supposed to be called from `nntp-server-opened-hook'.
1155 It will make innd servers spawn an nnrpd process to allow actual article
1157 (nntp-send-command "^.*\n" "MODE READER"))
1159 (declare-function netrc-parse "netrc" (&optional file))
1160 (declare-function netrc-machine "netrc"
1161 (list machine &optional port defaultport))
1162 (declare-function netrc-get "netrc" (alist type))
1164 (defun nntp-send-authinfo (&optional send-if-force)
1165 "Send the AUTHINFO to the nntp server.
1166 It will look in the \"~/.authinfo\" file for matching entries. If
1167 nothing suitable is found there, it will prompt for a user name
1170 If SEND-IF-FORCE, only send authinfo to the server if the
1171 .authinfo file has the FORCE token."
1173 (let* ((list (netrc-parse nntp-authinfo-file))
1174 (alist (netrc-machine list nntp-address "nntp"))
1175 (force (or (netrc-get alist "force") nntp-authinfo-force))
1177 (auth-source-user-or-password '("login" "password") nntp-address "nntp"))
1178 (auth-user (nth 0 auth-info))
1179 (auth-passwd (nth 1 auth-info))
1181 ;; this is preferred to netrc-*
1183 (netrc-get alist "login")
1184 nntp-authinfo-user))
1186 ;; this is preferred to netrc-*
1188 (netrc-get alist "password"))))
1189 (when (or (not send-if-force)
1192 (setq user (read-string (format "NNTP (%s) user name: " nntp-address))
1193 nntp-authinfo-user user))
1194 (unless (member user '(nil ""))
1195 (nntp-send-command "^3.*\r?\n" "AUTHINFO USER" user)
1196 (when t ;???Should check if AUTHINFO succeeded
1198 "^2.*\r?\n" "AUTHINFO PASS"
1200 nntp-authinfo-password
1201 (setq nntp-authinfo-password
1202 (read-passwd (format "NNTP (%s@%s) password: "
1203 user nntp-address))))))))))
1205 (defun nntp-send-nosy-authinfo ()
1206 "Send the AUTHINFO to the nntp server."
1207 (let ((user (read-string (format "NNTP (%s) user name: " nntp-address))))
1208 (unless (member user '(nil ""))
1209 (nntp-send-command "^3.*\r?\n" "AUTHINFO USER" user)
1210 (when t ;???Should check if AUTHINFO succeeded
1211 (nntp-send-command "^2.*\r?\n" "AUTHINFO PASS"
1212 (read-passwd (format "NNTP (%s@%s) password: "
1213 user nntp-address)))))))
1215 (defun nntp-send-authinfo-from-file ()
1216 "Send the AUTHINFO to the nntp server.
1218 The authinfo login name is taken from the user's login name and the
1219 password contained in '~/.nntp-authinfo'."
1220 (when (file-exists-p "~/.nntp-authinfo")
1222 (insert-file-contents "~/.nntp-authinfo")
1223 (goto-char (point-min))
1224 (nntp-send-command "^3.*\r?\n" "AUTHINFO USER" (user-login-name))
1226 "^2.*\r?\n" "AUTHINFO PASS"
1227 (buffer-substring (point) (point-at-eol))))))
1229 ;;; Internal functions.
1231 (defun nntp-handle-authinfo (process)
1232 "Take care of an authinfo response from the server."
1233 (let ((last nntp-last-command))
1234 (funcall nntp-authinfo-function)
1235 ;; We have to re-send the function that was interrupted by
1236 ;; the authinfo request.
1237 (nntp-erase-buffer nntp-server-buffer)
1238 (nntp-send-string process last)))
1240 (defun nntp-make-process-buffer (buffer)
1241 "Create a new, fresh buffer usable for nntp process connections."
1242 (with-current-buffer
1243 (generate-new-buffer
1244 (format " *server %s %s %s*"
1245 nntp-address nntp-port-number
1246 (gnus-buffer-exists-p buffer)))
1247 (mm-disable-multibyte)
1248 (set (make-local-variable 'after-change-functions) nil)
1249 (set (make-local-variable 'nntp-process-wait-for) nil)
1250 (set (make-local-variable 'nntp-process-callback) nil)
1251 (set (make-local-variable 'nntp-process-to-buffer) nil)
1252 (set (make-local-variable 'nntp-process-start-point) nil)
1253 (set (make-local-variable 'nntp-process-decode) nil)
1256 (defun nntp-open-connection (buffer)
1257 "Open a connection to PORT on ADDRESS delivering output to BUFFER."
1258 (run-hooks 'nntp-prepare-server-hook)
1259 (let* ((pbuffer (nntp-make-process-buffer buffer))
1261 (and nntp-connection-timeout
1263 nntp-connection-timeout nil
1265 (nntp-kill-buffer ,pbuffer)))))
1268 (let ((coding-system-for-read nntp-coding-system-for-read)
1269 (coding-system-for-write nntp-coding-system-for-write)
1270 (map '((nntp-open-network-stream network)
1271 (network-only network-only)
1272 (nntp-open-ssl-stream tls)
1273 (nntp-open-tls-stream tls))))
1274 (if (assoc nntp-open-connection-function map)
1275 (car (open-protocol-stream
1276 "nntpd" pbuffer nntp-address nntp-port-number
1278 (assoc nntp-open-connection-function map))
1279 :end-of-command "^\\([2345]\\|[.]\\).*\n"
1280 :capability-command "CAPABILITIES\r\n"
1283 (lambda (capabilities)
1284 (if (not (string-match "STARTTLS" capabilities))
1287 (funcall nntp-open-connection-function pbuffer)))
1289 (nnheader-report 'nntp "%s" err))
1291 (message "Quit opening connection to %s" nntp-address)
1292 (nntp-kill-buffer pbuffer)
1296 (nnheader-cancel-timer timer))
1298 (nntp-kill-buffer pbuffer))
1299 (when (and (buffer-name pbuffer)
1301 (gnus-set-process-query-on-exit-flag process nil)
1302 (if (and (nntp-wait-for process "^2.*\n" buffer nil t)
1303 (memq (process-status process) '(open run)))
1305 (caar (push (list process buffer nil) nntp-connection-alist))
1306 (push process nntp-connection-list)
1307 (with-current-buffer pbuffer
1308 (nntp-read-server-type)
1310 (set-buffer nntp-server-buffer)
1311 (let ((nnheader-callback-function nil))
1312 (run-hooks 'nntp-server-opened-hook)
1313 (nntp-send-authinfo t))))
1314 (nntp-kill-buffer (process-buffer process))
1317 (defun nntp-read-server-type ()
1318 "Find out what the name of the server we have connected to is."
1319 ;; Wait for the status string to arrive.
1320 (setq nntp-server-type (buffer-string))
1321 (let ((case-fold-search t))
1322 ;; Run server-specific commands.
1323 (dolist (entry nntp-server-action-alist)
1324 (when (string-match (car entry) nntp-server-type)
1325 (if (and (listp (cadr entry))
1326 (not (eq 'lambda (caadr entry))))
1328 (funcall (cadr entry)))))))
1330 (defun nntp-async-wait (process wait-for buffer decode callback)
1331 (with-current-buffer (process-buffer process)
1332 (unless nntp-inside-change-function
1334 (setq nntp-process-wait-for wait-for
1335 nntp-process-to-buffer buffer
1336 nntp-process-decode decode
1337 nntp-process-callback callback
1338 nntp-process-start-point (point-max))
1339 (setq after-change-functions '(nntp-after-change-function))))
1341 (defun nntp-async-timer-handler ()
1344 (if (memq (process-status proc) '(open run))
1345 (nntp-async-trigger proc)
1346 (nntp-async-stop proc)))
1347 nntp-async-process-list))
1349 (defun nntp-async-stop (proc)
1350 (setq nntp-async-process-list (delq proc nntp-async-process-list))
1351 (when (and nntp-async-timer (not nntp-async-process-list))
1352 (nnheader-cancel-timer nntp-async-timer)
1353 (setq nntp-async-timer nil)))
1355 (defun nntp-after-change-function (beg end len)
1357 ;; we only care about insertions at eob
1358 (when (and (eq 0 len) (eq (point-max) end))
1360 (let ((proc (get-buffer-process (current-buffer))))
1362 (nntp-async-trigger proc)))))
1363 ;; any throw from after-change-functions will leave it
1364 ;; set to nil. so we reset it here, if necessary.
1366 (setq after-change-functions '(nntp-after-change-function)))))
1368 (defun nntp-async-trigger (process)
1369 (with-current-buffer (process-buffer process)
1370 (when nntp-process-callback
1371 ;; do we have an error message?
1372 (goto-char nntp-process-start-point)
1373 (if (memq (following-char) '(?4 ?5))
1374 ;; wants credentials?
1375 (if (looking-at "480")
1376 (nntp-handle-authinfo process)
1377 ;; report error message.
1378 (nntp-snarf-error-message)
1379 (nntp-do-callback nil))
1381 ;; got what we expect?
1382 (goto-char (point-max))
1383 (when (re-search-backward
1384 nntp-process-wait-for nntp-process-start-point t)
1385 (let ((response (match-string 0)))
1386 (with-current-buffer nntp-server-buffer
1387 (setq nntp-process-response response)))
1388 (nntp-async-stop process)
1390 (when (gnus-buffer-exists-p nntp-process-to-buffer)
1391 (let ((buf (current-buffer))
1392 (start nntp-process-start-point)
1393 (decode nntp-process-decode))
1394 (with-current-buffer nntp-process-to-buffer
1395 (goto-char (point-max))
1397 (narrow-to-region (point) (point))
1398 (nntp-insert-buffer-substring buf start)
1400 (nntp-decode-text))))))
1402 (goto-char (point-max))
1404 (buffer-name (get-buffer nntp-process-to-buffer))))))))
1406 (defun nntp-do-callback (arg)
1407 (let ((callback nntp-process-callback)
1408 (nntp-inside-change-function t))
1409 (setq nntp-process-callback nil)
1410 (funcall callback arg)))
1412 (defun nntp-snarf-error-message ()
1413 "Save the error message in the current buffer."
1414 (let ((message (buffer-string)))
1415 (while (string-match "[\r\n]+" message)
1416 (setq message (replace-match " " t t message)))
1417 (nnheader-report 'nntp "%s" message)
1420 (defun nntp-accept-process-output (process)
1421 "Wait for output from PROCESS and message some dots."
1422 (with-current-buffer (or (nntp-find-connection-buffer nntp-server-buffer)
1424 (let ((len (/ (buffer-size) 1024))
1427 (setq nntp-have-messaged t)
1428 (nnheader-message 7 "nntp read: %dk" len)))
1430 (nnheader-accept-process-output process)
1431 ;; accept-process-output may update status of process to indicate
1432 ;; that the server has closed the connection. This MUST be
1433 ;; handled here as the buffer restored by the save-excursion may
1434 ;; be the process's former output buffer (i.e. now killed)
1436 (memq (process-status process) '(open run)))
1437 (nntp-report "Server closed connection")))))
1439 (defun nntp-accept-response ()
1440 "Wait for output from the process that outputs to BUFFER."
1441 (nntp-accept-process-output (nntp-find-connection nntp-server-buffer)))
1443 (defun nntp-possibly-change-group (group server &optional connectionless)
1444 (let ((nnheader-callback-function nil))
1446 (or (nntp-server-opened server)
1447 (nntp-open-server server nil connectionless)))
1449 (unless connectionless
1450 (or (nntp-find-connection nntp-server-buffer)
1451 (nntp-open-connection nntp-server-buffer))))
1454 (let ((entry (nntp-find-connection-entry nntp-server-buffer)))
1456 (nntp-report "Server closed connection"))
1457 ((not (equal group (caddr entry)))
1458 (with-current-buffer (process-buffer (car entry))
1460 (nntp-send-command "^[245].*\n" "GROUP" group)
1461 (setcar (cddr entry) group)
1463 (nntp-erase-buffer nntp-server-buffer)))))))
1465 (defun nntp-decode-text (&optional cr-only)
1466 "Decode the text in the current buffer."
1467 (goto-char (point-min))
1468 (while (search-forward "\r" nil t)
1471 ;; Remove trailing ".\n" end-of-transfer marker.
1472 (goto-char (point-max))
1474 (when (looking-at ".\n")
1476 ;; Delete status line.
1477 (goto-char (point-min))
1478 (while (looking-at "[1-5][0-9][0-9] .*\n")
1479 ;; For some unknown reason, there is more than one status line.
1480 (delete-region (point) (progn (forward-line 1) (point))))
1481 ;; Remove "." -> ".." encoding.
1482 (while (search-forward "\n.." nil t)
1485 (defun nntp-encode-text ()
1486 "Encode the text in the current buffer."
1488 ;; Replace "." at beginning of line with "..".
1489 (goto-char (point-min))
1490 (while (re-search-forward "^\\." nil t)
1492 (goto-char (point-max))
1493 ;; Insert newline at the end of the buffer.
1496 ;; Insert `.' at end of buffer (end of text mark).
1497 (goto-char (point-max))
1499 (goto-char (point-min))
1503 (insert nntp-end-of-line))))
1505 (defun nntp-retrieve-headers-with-xover (articles &optional fetch-old)
1506 (set-buffer nntp-server-buffer)
1510 ;; This server does not talk NOV.
1511 ((not nntp-server-xover)
1514 ;; We don't care about gaps.
1515 ((or (not nntp-nov-gap)
1517 (nntp-send-xover-command
1519 (if (numberp fetch-old)
1520 (max 1 (- (car articles) fetch-old))
1523 (car (last articles)) 'wait)
1525 (goto-char (point-min))
1526 (when (looking-at "[1-5][0-9][0-9] .*\n")
1527 (delete-region (point) (progn (forward-line 1) (point))))
1528 (while (search-forward "\r" nil t)
1529 (replace-match "" t t))
1530 (goto-char (point-max))
1532 (when (looking-at "\\.")
1533 (delete-region (point) (progn (forward-line 1) (point)))))
1535 ;; We do it the hard way. For each gap, an XOVER command is sent
1536 ;; to the server. We do not wait for a reply from the server, we
1537 ;; just send them off as fast as we can. That means that we have
1538 ;; to count the number of responses we get back to find out when we
1539 ;; have gotten all we asked for.
1540 ((numberp nntp-nov-gap)
1545 (buf nntp-server-buffer)
1546 (process-buffer (nntp-find-connection-buffer nntp-server-buffer))
1548 ;; We have to check `nntp-server-xover'. If it gets set to nil,
1549 ;; that means that the server does not understand XOVER, but we
1550 ;; won't know that until we try.
1551 (while (and nntp-server-xover articles)
1552 (setq first (car articles))
1553 ;; Search forward until we find a gap, or until we run out of
1555 (while (and (cdr articles)
1556 (< (- (nth 1 articles) (car articles)) nntp-nov-gap))
1557 (setq articles (cdr articles)))
1559 (setq in-process-buffer-p (stringp nntp-server-xover))
1560 (nntp-send-xover-command first (setq last (car articles)))
1561 (setq articles (cdr articles))
1563 (when (and nntp-server-xover in-process-buffer-p)
1564 ;; Don't count tried request.
1565 (setq count (1+ count))
1567 ;; Every 400 requests we have to read the stream in
1568 ;; order to avoid deadlocks.
1569 (when (or (null articles) ;All requests have been sent.
1570 (= 1 (% count nntp-maximum-request)))
1572 (nntp-accept-response)
1573 ;; On some Emacs versions the preceding function has a
1574 ;; tendency to change the buffer. Perhaps. It's quite
1575 ;; difficult to reproduce, because it only seems to happen
1576 ;; once in a blue moon.
1577 (set-buffer process-buffer)
1579 (goto-char (or last-point (point-min)))
1581 (while (re-search-forward "^\\([0-9][0-9][0-9]\\) .*\n"
1584 (setq status (match-string 1))
1585 (if (string-match "^[45]" status)
1586 (setq status 'error)
1588 (setq last-point (point))
1589 (or (< received count)
1590 (if (eq status 'error)
1592 ;; I haven't started reading the final response
1594 (goto-char (point-max))
1596 (not (looking-at "^\\.\r?\n"))))))
1597 ;; I haven't read the end of the final response
1598 (nntp-accept-response)
1599 (set-buffer process-buffer))))
1601 ;; Some nntp servers seem to have an extension to the XOVER
1602 ;; extension. On these servers, requesting an article range
1603 ;; preceeding the active range does not return an error as
1604 ;; specified in the RFC. What we instead get is the NOV entry
1605 ;; for the first available article. Obviously, a client can
1606 ;; use that entry to avoid making unnecessary requests. The
1607 ;; only problem is for a client that assumes that the response
1608 ;; will always be within the requested ranage. For such a
1609 ;; client, we can get N copies of the same entry (one for each
1610 ;; XOVER command sent to the server).
1613 (goto-char (point-min))
1614 (when (re-search-forward "^[0-9][0-9][0-9] .*\n\\([0-9]+\\)" nil t)
1615 (let ((low-limit (string-to-number
1616 (buffer-substring (match-beginning 1)
1618 (while (and articles (<= (car articles) low-limit))
1619 (setq articles (cdr articles))))))
1622 (when nntp-server-xover
1623 (when in-process-buffer-p
1625 (goto-char (point-max))
1626 (nntp-insert-buffer-substring process-buffer)
1627 (set-buffer process-buffer)
1631 ;; We remove any "." lines and status lines.
1632 (goto-char (point-min))
1633 (while (search-forward "\r" nil t)
1635 (goto-char (point-min))
1636 (delete-matching-lines "^\\.$\\|^[1-5][0-9][0-9] ")
1641 (defun nntp-send-xover-command (beg end &optional wait-for-reply)
1642 "Send the XOVER command to the server."
1643 (let ((range (format "%d-%d" beg end))
1644 (nntp-inhibit-erase t))
1645 (if (stringp nntp-server-xover)
1646 ;; If `nntp-server-xover' is a string, then we just send this
1649 (nntp-send-command-nodelete
1650 "\r?\n\\.\r?\n" nntp-server-xover range)
1651 ;; We do not wait for the reply.
1652 (nntp-send-command-nodelete nil nntp-server-xover range))
1653 (let ((commands nntp-xover-commands))
1654 ;; `nntp-xover-commands' is a list of possible XOVER commands.
1655 ;; We try them all until we get at positive response.
1656 (while (and commands (eq nntp-server-xover 'try))
1657 (nntp-send-command-nodelete "\r?\n\\.\r?\n" (car commands) range)
1658 (with-current-buffer nntp-server-buffer
1659 (goto-char (point-min))
1660 (and (looking-at "[23]") ; No error message.
1661 ;; We also have to look at the lines. Some buggy
1662 ;; servers give back simple lines with just the
1663 ;; article number. How... helpful.
1666 ;; More text after number, or a dot.
1667 (looking-at "[0-9]+\t...\\|\\.\r?\n"))
1668 (setq nntp-server-xover (car commands))))
1669 (setq commands (cdr commands)))
1670 ;; If none of the commands worked, we disable XOVER.
1671 (when (eq nntp-server-xover 'try)
1672 (nntp-erase-buffer nntp-server-buffer)
1673 (setq nntp-server-xover nil))
1674 nntp-server-xover))))
1676 (defun nntp-find-group-and-number (&optional group)
1679 ;; FIXME: This is REALLY FISHY: set-buffer after save-restriction?!?
1680 (set-buffer nntp-server-buffer)
1681 (narrow-to-region (goto-char (point-min))
1682 (or (search-forward "\n\n" nil t) (point-max)))
1683 (goto-char (point-min))
1684 ;; We first find the number by looking at the status line.
1685 (let ((number (and (looking-at "2[0-9][0-9] +\\([0-9]+\\) ")
1687 (buffer-substring (match-beginning 1)
1690 (and number (zerop number) (setq number nil))
1692 ;; Then we find the group name.
1695 ;; If there is only one group in the Newsgroups
1696 ;; header, then it seems quite likely that this
1697 ;; article comes from that group, I'd say.
1698 ((and (setq newsgroups
1699 (mail-fetch-field "newsgroups"))
1700 (not (string-match "," newsgroups)))
1702 ;; If there is more than one group in the
1703 ;; Newsgroups header, then the Xref header should
1704 ;; be filled out. We hazard a guess that the group
1705 ;; that has this article number in the Xref header
1706 ;; is the one we are looking for. This might very
1707 ;; well be wrong if this article happens to have
1708 ;; the same number in several groups, but that's
1710 ((and (setq xref (mail-fetch-field "xref"))
1713 (format "\\([^ :]+\\):%d" number) xref))
1714 (match-string 1 xref))
1717 ((and (not nntp-xref-number-is-evil)
1718 (setq xref (mail-fetch-field "xref"))
1721 (concat "\\(" (regexp-quote group) "\\):\\([0-9]+\\)")
1722 "\\([^ :]+\\):\\([0-9]+\\)")
1724 (setq group (match-string 1 xref)
1725 number (string-to-number (match-string 2 xref))))
1726 ((and (setq newsgroups
1727 (mail-fetch-field "newsgroups"))
1728 (not (string-match "," newsgroups)))
1729 (setq group newsgroups))
1731 (t (setq group ""))))
1732 (when (string-match "\r" group)
1733 (setq group (substring group 0 (match-beginning 0))))
1734 (cons group number)))))
1736 (defun nntp-wait-for-string (regexp)
1737 "Wait until string arrives in the buffer."
1738 (let ((buf (current-buffer))
1740 (goto-char (point-min))
1741 (while (and (setq proc (get-buffer-process buf))
1742 (memq (process-status proc) '(open run))
1743 (not (re-search-forward regexp nil t)))
1744 (accept-process-output proc 0.1)
1746 (goto-char (point-min)))))
1749 ;; ==========================================================================
1750 ;; Obsolete nntp-open-* connection methods -- drv
1751 ;; ==========================================================================
1753 (defvoo nntp-open-telnet-envuser nil
1754 "*If non-nil, telnet session (client and server both) will support the ENVIRON option and not prompt for login name.")
1756 (defvoo nntp-telnet-shell-prompt "bash\\|\$ *\r?$\\|> *\r?"
1757 "*Regular expression to match the shell prompt on the remote machine.")
1759 (defvoo nntp-rlogin-program "rsh"
1760 "*Program used to log in on remote machines.
1761 The default is \"rsh\", but \"ssh\" is a popular alternative.")
1763 (defvoo nntp-rlogin-parameters '("telnet" "-8" "${NNTPSERVER:=news}" "nntp")
1764 "*Parameters to `nntp-open-rlogin'.
1765 That function may be used as `nntp-open-connection-function'. In that
1766 case, this list will be used as the parameter list given to rsh.")
1768 (defvoo nntp-rlogin-user-name nil
1769 "*User name on remote system when using the rlogin connect method.")
1771 (defvoo nntp-telnet-parameters
1772 '("exec" "telnet" "-8" "${NNTPSERVER:=news}" "nntp")
1773 "*Parameters to `nntp-open-telnet'.
1774 That function may be used as `nntp-open-connection-function'. In that
1775 case, this list will be executed as a command after logging in
1778 (defvoo nntp-telnet-user-name nil
1779 "User name to log in via telnet with.")
1781 (defvoo nntp-telnet-passwd nil
1782 "Password to use to log in via telnet with.")
1784 (defun nntp-service-to-port (svc)
1786 ((integerp svc) (number-to-string svc))
1787 ((string-match "\\`[0-9]+\\'" svc) svc)
1790 (ignore-errors (insert-file-contents "/etc/services"))
1791 (goto-char (point-min))
1792 (if (re-search-forward (concat "^" (regexp-quote svc)
1793 "[ \t]+\\([0-9]+\\)/tcp"))
1797 (defun nntp-open-telnet (buffer)
1798 (with-current-buffer buffer
1802 "nntpd" buffer nntp-telnet-command nntp-telnet-switches))
1803 (case-fold-search t))
1804 (when (memq (process-status proc) '(open run))
1805 (nntp-wait-for-string "^r?telnet")
1806 (process-send-string proc "set escape \^X\n")
1808 ((and nntp-open-telnet-envuser nntp-telnet-user-name)
1809 (process-send-string proc (concat "open " "-l" nntp-telnet-user-name
1810 nntp-address "\n")))
1812 (process-send-string proc (concat "open " nntp-address "\n"))))
1814 ((not nntp-open-telnet-envuser)
1815 (nntp-wait-for-string "^\r*.?login:")
1816 (process-send-string
1818 (or nntp-telnet-user-name
1819 (setq nntp-telnet-user-name (read-string "login: ")))
1821 (nntp-wait-for-string "^\r*.?password:")
1822 (process-send-string
1824 (or nntp-telnet-passwd
1825 (setq nntp-telnet-passwd
1826 (read-passwd "Password: ")))
1828 (nntp-wait-for-string nntp-telnet-shell-prompt)
1829 (process-send-string
1830 proc (concat (mapconcat 'identity nntp-telnet-parameters " ") "\n"))
1831 (nntp-wait-for-string "^\r*20[01]")
1833 (delete-region (point-min) (point))
1834 (process-send-string proc "\^]")
1835 (nntp-wait-for-string "^r?telnet")
1836 (process-send-string proc "mode character\n")
1837 (accept-process-output proc 1)
1839 (goto-char (point-min))
1841 (delete-region (point) (point-max)))
1844 (defun nntp-open-rlogin (buffer)
1845 "Open a connection to SERVER using rsh."
1846 (let ((proc (if nntp-rlogin-user-name
1847 (apply 'start-process
1848 "nntpd" buffer nntp-rlogin-program
1849 nntp-address "-l" nntp-rlogin-user-name
1850 nntp-rlogin-parameters)
1851 (apply 'start-process
1852 "nntpd" buffer nntp-rlogin-program nntp-address
1853 nntp-rlogin-parameters))))
1854 (with-current-buffer buffer
1855 (nntp-wait-for-string "^\r*20[01]")
1857 (delete-region (point-min) (point))
1861 ;; ==========================================================================
1862 ;; Replacements for the nntp-open-* functions -- drv
1863 ;; ==========================================================================
1865 (defun nntp-open-telnet-stream (buffer)
1866 "Open a nntp connection by telnet'ing the news server.
1867 `nntp-open-netcat-stream' is recommended in place of this function
1868 because it is more reliable.
1870 Please refer to the following variables to customize the connection:
1871 - `nntp-pre-command',
1872 - `nntp-telnet-command',
1873 - `nntp-telnet-switches',
1875 - `nntp-port-number',
1876 - `nntp-end-of-line'."
1877 (let ((command `(,nntp-telnet-command
1878 ,@nntp-telnet-switches
1880 ,(nntp-service-to-port nntp-port-number)))
1882 (and nntp-pre-command
1883 (push nntp-pre-command command))
1884 (setq proc (apply 'start-process "nntpd" buffer command))
1885 (with-current-buffer buffer
1886 (nntp-wait-for-string "^\r*20[01]")
1888 (delete-region (point-min) (point))
1891 (defun nntp-open-via-rlogin-and-telnet (buffer)
1892 "Open a connection to an nntp server through an intermediate host.
1893 First rlogin to the remote host, and then telnet the real news server
1895 `nntp-open-via-rlogin-and-netcat' is recommended in place of this function
1896 because it is more reliable.
1898 Please refer to the following variables to customize the connection:
1899 - `nntp-pre-command',
1900 - `nntp-via-rlogin-command',
1901 - `nntp-via-rlogin-command-switches',
1902 - `nntp-via-user-name',
1903 - `nntp-via-address',
1904 - `nntp-telnet-command',
1905 - `nntp-telnet-switches',
1907 - `nntp-port-number',
1908 - `nntp-end-of-line'."
1909 (let ((command `(,nntp-via-address
1910 ,nntp-telnet-command
1911 ,@nntp-telnet-switches))
1913 (when nntp-via-user-name
1914 (setq command `("-l" ,nntp-via-user-name ,@command)))
1915 (when nntp-via-rlogin-command-switches
1916 (setq command (append nntp-via-rlogin-command-switches command)))
1917 (push nntp-via-rlogin-command command)
1918 (and nntp-pre-command
1919 (push nntp-pre-command command))
1920 (setq proc (apply 'start-process "nntpd" buffer command))
1921 (with-current-buffer buffer
1922 (nntp-wait-for-string "^r?telnet")
1923 (process-send-string proc (concat "open " nntp-address " "
1924 (nntp-service-to-port nntp-port-number)
1926 (nntp-wait-for-string "^\r*20[01]")
1928 (delete-region (point-min) (point))
1929 (process-send-string proc "\^]")
1930 (nntp-wait-for-string "^r?telnet")
1931 (process-send-string proc "mode character\n")
1932 (accept-process-output proc 1)
1934 (goto-char (point-min))
1936 (delete-region (point) (point-max)))
1939 (defun nntp-open-via-rlogin-and-netcat (buffer)
1940 "Open a connection to an nntp server through an intermediate host.
1941 First rlogin to the remote host, and then connect to the real news
1942 server from there using the netcat command.
1944 Please refer to the following variables to customize the connection:
1945 - `nntp-pre-command',
1946 - `nntp-via-rlogin-command',
1947 - `nntp-via-rlogin-command-switches',
1948 - `nntp-via-user-name',
1949 - `nntp-via-address',
1950 - `nntp-netcat-command',
1951 - `nntp-netcat-switches',
1953 - `nntp-port-number'."
1954 (let ((command `(,@(when nntp-pre-command
1955 (list nntp-pre-command))
1956 ,nntp-via-rlogin-command
1957 ,@nntp-via-rlogin-command-switches
1958 ,@(when nntp-via-user-name
1959 (list "-l" nntp-via-user-name))
1961 ,nntp-netcat-command
1962 ,@nntp-netcat-switches
1964 ,(nntp-service-to-port nntp-port-number))))
1965 ;; A non-nil connection type results in mightily odd behavior where
1966 ;; (process-send-string proc "\^M") ends up sending a "\n" to the
1967 ;; ssh process. --Stef
1968 ;; Also a nil connection allow ssh-askpass to work under X11.
1969 (let ((process-connection-type nil))
1970 (apply 'start-process "nntpd" buffer command))))
1972 (defun nntp-open-netcat-stream (buffer)
1973 "Open a connection to an nntp server through netcat.
1974 I.e. use the `nc' command rather than Emacs's builtin networking code.
1976 Please refer to the following variables to customize the connection:
1977 - `nntp-pre-command',
1978 - `nntp-netcat-command',
1979 - `nntp-netcat-switches',
1981 - `nntp-port-number'."
1982 (let ((command `(,nntp-netcat-command
1983 ,@nntp-netcat-switches
1985 ,(nntp-service-to-port nntp-port-number))))
1986 (and nntp-pre-command (push nntp-pre-command command))
1987 (let ((process-connection-type nil)) ;See `nntp-open-via-rlogin-and-netcat'.
1988 (apply 'start-process "nntpd" buffer command))))
1991 (defun nntp-open-via-telnet-and-telnet (buffer)
1992 "Open a connection to an nntp server through an intermediate host.
1993 First telnet the remote host, and then telnet the real news server
1996 Please refer to the following variables to customize the connection:
1997 - `nntp-pre-command',
1998 - `nntp-via-telnet-command',
1999 - `nntp-via-telnet-switches',
2000 - `nntp-via-address',
2001 - `nntp-via-envuser',
2002 - `nntp-via-user-name',
2003 - `nntp-via-user-password',
2004 - `nntp-via-shell-prompt',
2005 - `nntp-telnet-command',
2006 - `nntp-telnet-switches',
2008 - `nntp-port-number',
2009 - `nntp-end-of-line'."
2010 (with-current-buffer buffer
2012 (let ((command `(,nntp-via-telnet-command ,@nntp-via-telnet-switches))
2013 (case-fold-search t)
2015 (and nntp-pre-command (push nntp-pre-command command))
2016 (setq proc (apply 'start-process "nntpd" buffer command))
2017 (when (memq (process-status proc) '(open run))
2018 (nntp-wait-for-string "^r?telnet")
2019 (process-send-string proc "set escape \^X\n")
2021 ((and nntp-via-envuser nntp-via-user-name)
2022 (process-send-string proc (concat "open " "-l" nntp-via-user-name
2023 nntp-via-address "\n")))
2025 (process-send-string proc (concat "open " nntp-via-address
2027 (when (not nntp-via-envuser)
2028 (nntp-wait-for-string "^\r*.?login:")
2029 (process-send-string proc
2031 (or nntp-via-user-name
2032 (setq nntp-via-user-name
2033 (read-string "login: ")))
2035 (nntp-wait-for-string "^\r*.?password:")
2036 (process-send-string proc
2038 (or nntp-via-user-password
2039 (setq nntp-via-user-password
2040 (read-passwd "Password: ")))
2042 (nntp-wait-for-string nntp-via-shell-prompt)
2043 (let ((real-telnet-command `("exec"
2044 ,nntp-telnet-command
2045 ,@nntp-telnet-switches
2047 ,(nntp-service-to-port nntp-port-number))))
2048 (process-send-string proc
2049 (concat (mapconcat 'identity
2050 real-telnet-command " ")
2052 (nntp-wait-for-string "^\r*20[01]")
2054 (delete-region (point-min) (point))
2055 (process-send-string proc "\^]")
2056 (nntp-wait-for-string "^r?telnet")
2057 (process-send-string proc "mode character\n")
2058 (accept-process-output proc 1)
2060 (goto-char (point-min))
2062 (delete-region (point) (point-max)))
2067 (defun nntp-marks-directory (server)
2068 (expand-file-name server nntp-marks-directory))
2070 (defvar nntp-server-to-method-cache nil
2071 "Alist of servers and select methods.")
2073 (defun nntp-group-pathname (server group &optional file)
2074 "Return an absolute file name of FILE for GROUP on SERVER."
2075 (let ((method (cdr (assoc server nntp-server-to-method-cache))))
2077 (push (cons server (setq method (or (gnus-server-to-method server)
2078 (gnus-find-method-for-group group))))
2079 nntp-server-to-method-cache))
2080 (nnmail-group-pathname
2081 (mm-decode-coding-string group
2082 (inline (gnus-group-name-charset method group)))
2083 (nntp-marks-directory server)
2086 (defun nntp-possibly-create-directory (group server)
2087 (let ((dir (nntp-group-pathname server group))
2088 (file-name-coding-system nnmail-pathname-coding-system))
2089 (unless (file-exists-p dir)
2090 (make-directory (directory-file-name dir) t)
2091 (nnheader-message 5 "Creating nntp marks directory %s" dir))))
2093 (autoload 'time-less-p "time-date")
2095 (defun nntp-marks-changed-p (group server)
2096 (let ((file (nntp-group-pathname server group nntp-marks-file-name))
2097 (file-name-coding-system nnmail-pathname-coding-system))
2098 (if (null (gnus-gethash file nntp-marks-modtime))
2099 t ;; never looked at marks file, assume it has changed
2100 (time-less-p (gnus-gethash file nntp-marks-modtime)
2101 (nth 5 (file-attributes file))))))
2103 (defun nntp-save-marks (group server)
2104 (let ((file-name-coding-system nnmail-pathname-coding-system)
2105 (file (nntp-group-pathname server group nntp-marks-file-name)))
2108 (nntp-possibly-create-directory group server)
2109 (with-temp-file file
2111 (gnus-prin1 nntp-marks)
2114 (nth 5 (file-attributes file))
2115 nntp-marks-modtime))
2116 (error (or (gnus-yes-or-no-p
2117 (format "Could not write to %s (%s). Continue? " file err))
2118 (error "Cannot write to %s (%s)" file err))))))
2120 (defun nntp-open-marks (group server)
2121 (let ((file (nntp-group-pathname server group nntp-marks-file-name))
2122 (file-name-coding-system nnmail-pathname-coding-system))
2123 (if (file-exists-p file)
2126 (gnus-sethash file (nth 5 (file-attributes file))
2128 (nnheader-insert-file-contents file)
2129 (setq nntp-marks (read (current-buffer)))
2130 (dolist (el gnus-article-unpropagated-mark-lists)
2131 (setq nntp-marks (gnus-remassoc el nntp-marks))))
2132 (error (or (gnus-yes-or-no-p
2133 (format "Error reading nntp marks file %s (%s). Continuing will use marks from .newsrc.eld. Continue? " file err))
2134 (error "Cannot read nntp marks file %s (%s)" file err))))
2135 ;; User didn't have a .marks file. Probably first time
2136 ;; user of the .marks stuff. Bootstrap it from .newsrc.eld.
2137 (let ((info (gnus-get-info
2138 (gnus-group-prefixed-name
2140 (gnus-server-to-method (format "nntp:%s" server)))))
2141 (decoded-name (mm-decode-coding-string
2143 (gnus-group-name-charset
2144 (gnus-server-to-method server) group))))
2145 (nnheader-message 7 "Bootstrapping marks for %s..." decoded-name)
2146 (setq nntp-marks (gnus-info-marks info))
2147 (push (cons 'read (gnus-info-read info)) nntp-marks)
2148 (dolist (el gnus-article-unpropagated-mark-lists)
2149 (setq nntp-marks (gnus-remassoc el nntp-marks)))
2150 (nntp-save-marks group server)
2151 (nnheader-message 7 "Bootstrapping marks for %s...done"
2156 ;;; nntp.el ends here