nntp.el (nntp-open-connection): Check if process-type is available.
[bpt/emacs.git] / lisp / gnus / nntp.el
CommitLineData
16409b0b 1;;; nntp.el --- nntp access for Gnus
f9936da6 2
95df8112
GM
3;; Copyright (C) 1987-1990, 1992-1998, 2000-2011
4;; Free Software Foundation, Inc.
eec82323 5
6748645f 6;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
eec82323
LMI
7;; Keywords: news
8
9;; This file is part of GNU Emacs.
10
5e809f55
GM
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.
eec82323 15
5e809f55
GM
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.
eec82323
LMI
20
21;; You should have received a copy of the GNU General Public License
5e809f55 22;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
eec82323
LMI
23
24;;; Commentary:
25
26;;; Code:
27
f0b7f5a8 28;; For Emacs <22.2 and XEmacs.
aa8f8277 29(eval-and-compile
da91b5f2
CY
30 (unless (fboundp 'declare-function) (defmacro declare-function (&rest r)))
31 ;; In Emacs 24, `open-protocol-stream' is an autoloaded alias for
32 ;; `make-network-stream'.
33 (unless (fboundp 'open-protocol-stream)
34 (require 'proto-stream)))
aa8f8277 35
eec82323
LMI
36(require 'nnheader)
37(require 'nnoo)
38(require 'gnus-util)
01c52d31
MB
39(require 'gnus)
40(require 'gnus-group) ;; gnus-group-name-charset
eec82323
LMI
41
42(nnoo-declare nntp)
43
16409b0b 44(eval-when-compile (require 'cl))
eec82323 45
b8e0f0cd 46(autoload 'auth-source-search "auth-source")
e952b711 47
e79f14a4
RS
48(defgroup nntp nil
49 "NNTP access for Gnus."
50 :group 'gnus)
51
eec82323
LMI
52(defvoo nntp-address nil
53 "Address of the physical nntp server.")
54
55(defvoo nntp-port-number "nntp"
56 "Port number on the physical nntp server.")
57
58(defvoo nntp-server-opened-hook '(nntp-send-mode-reader)
59 "*Hook used for sending commands to the server at startup.
60The default value is `nntp-send-mode-reader', which makes an innd
6748645f 61server spawn an nnrpd server.")
eec82323
LMI
62
63(defvoo nntp-authinfo-function 'nntp-send-authinfo
6748645f
LMI
64 "Function used to send AUTHINFO to the server.
65It is called with no parameters.")
eec82323
LMI
66
67(defvoo nntp-server-action-alist
16409b0b
GM
68 '(("nntpd 1\\.5\\.11t"
69 (remove-hook 'nntp-server-opened-hook 'nntp-send-mode-reader))
70 ("NNRP server Netscape"
71 (setq nntp-server-list-active-group nil)))
eec82323
LMI
72 "Alist of regexps to match on server types and actions to be taken.
73For instance, if you want Gnus to beep every time you connect
74to innd, you could say something like:
75
76\(setq nntp-server-action-alist
77 '((\"innd\" (ding))))
78
79You probably don't want to do that, though.")
80
81(defvoo nntp-open-connection-function 'nntp-open-network-stream
e742e117
CY
82 "Method for connecting to a remote system.
83It should be a function, which is called with the output buffer
84as its single argument, or one of the following special values:
85
86- `nntp-open-network-stream' specifies a network connection,
87 upgrading to a TLS connection via STARTTLS if possible.
88- `nntp-open-plain-stream' specifies an unencrypted network
89 connection (no STARTTLS upgrade is attempted).
90- `nntp-open-ssl-stream' or `nntp-open-tls-stream' specify a TLS
91 network connection.
92
93Apart from the above special values, valid functions are as
94follows; please refer to their respective doc string for more
95information.
96For direct connections:
97- `nntp-open-netcat-stream'
98- `nntp-open-telnet-stream'
99For indirect connections:
100- `nntp-open-via-rlogin-and-netcat'
101- `nntp-open-via-rlogin-and-telnet'
102- `nntp-open-via-telnet-and-telnet'")
eec82323 103
45cb30ee
MB
104(defvoo nntp-never-echoes-commands nil
105 "*Non-nil means the nntp server never echoes commands.
106It is reported that some nntps server doesn't echo commands. So, you
107may want to set this to non-nil in the method for such a server setting
108`nntp-open-connection-function' to `nntp-open-ssl-stream' for example.
109Note that the `nntp-open-connection-functions-never-echo-commands'
110variable overrides the nil value of this variable.")
111
112(defvoo nntp-open-connection-functions-never-echo-commands
113 '(nntp-open-network-stream)
114 "*List of functions that never echo commands.
115Add or set a function which you set to `nntp-open-connection-function'
116to this list if it does not echo commands. Note that a non-nil value
117of the `nntp-never-echoes-commands' variable overrides this variable.")
118
23f87bed
MB
119(defvoo nntp-pre-command nil
120 "*Pre-command to use with the various nntp-open-via-* methods.
121This is where you would put \"runsocks\" or stuff like that.")
eec82323 122
23f87bed
MB
123(defvoo nntp-telnet-command "telnet"
124 "*Telnet command used to connect to the nntp server.
01c52d31
MB
125This command is used by the methods `nntp-open-telnet-stream',
126`nntp-open-via-rlogin-and-telnet' and `nntp-open-via-telnet-and-telnet'.")
eec82323 127
23f87bed
MB
128(defvoo nntp-telnet-switches '("-8")
129 "*Switches given to the telnet command `nntp-telnet-command'.")
eec82323 130
23f87bed
MB
131(defvoo nntp-end-of-line "\r\n"
132 "*String to use on the end of lines when talking to the NNTP server.
01c52d31
MB
133This is \"\\r\\n\" by default, but should be \"\\n\" when using an indirect
134connection method (nntp-open-via-*).")
eec82323 135
23f87bed
MB
136(defvoo nntp-via-rlogin-command "rsh"
137 "*Rlogin command used to connect to an intermediate host.
01c52d31
MB
138This command is used by the methods `nntp-open-via-rlogin-and-telnet'
139and `nntp-open-via-rlogin-and-netcat'. The default is \"rsh\", but \"ssh\"
140is a popular alternative.")
6748645f 141
23f87bed
MB
142(defvoo nntp-via-rlogin-command-switches nil
143 "*Switches given to the rlogin command `nntp-via-rlogin-command'.
144If you use \"ssh\" for `nntp-via-rlogin-command', you may set this to
145\(\"-C\") in order to compress all data connections, otherwise set this
146to \(\"-t\" \"-e\" \"none\") or (\"-C\" \"-t\" \"-e\" \"none\") if the telnet
147command requires a pseudo-tty allocation on an intermediate host.")
6748645f 148
23f87bed
MB
149(defvoo nntp-via-telnet-command "telnet"
150 "*Telnet command used to connect to an intermediate host.
151This command is used by the `nntp-open-via-telnet-and-telnet' method.")
a8151ef7 152
23f87bed
MB
153(defvoo nntp-via-telnet-switches '("-8")
154 "*Switches given to the telnet command `nntp-via-telnet-command'.")
a8151ef7 155
990e2c2f 156(defvoo nntp-netcat-command "nc"
01c52d31 157 "*Netcat command used to connect to the nntp server.
990e2c2f
SM
158This command is used by the `nntp-open-netcat-stream' and
159`nntp-open-via-rlogin-and-netcat' methods.")
01c52d31 160
990e2c2f
SM
161(defvoo nntp-netcat-switches nil
162 "*Switches given to the netcat command `nntp-netcat-command'.")
01c52d31 163
23f87bed
MB
164(defvoo nntp-via-user-name nil
165 "*User name to log in on an intermediate host with.
01c52d31 166This variable is used by the various nntp-open-via-* methods.")
23f87bed
MB
167
168(defvoo nntp-via-user-password nil
169 "*Password to use to log in on an intermediate host with.
170This variable is used by the `nntp-open-via-telnet-and-telnet' method.")
171
172(defvoo nntp-via-address nil
173 "*Address of an intermediate host to connect to.
01c52d31 174This variable is used by the various nntp-open-via-* methods.")
23f87bed
MB
175
176(defvoo nntp-via-envuser nil
177 "*Whether both telnet client and server support the ENVIRON option.
178If non-nil, there will be no prompt for a login name.")
179
180(defvoo nntp-via-shell-prompt "bash\\|\$ *\r?$\\|> *\r?"
181 "*Regular expression to match the shell prompt on an intermediate host.
182This variable is used by the `nntp-open-via-telnet-and-telnet' method.")
eec82323
LMI
183
184(defvoo nntp-large-newsgroup 50
23f87bed
MB
185 "*The number of articles which indicates a large newsgroup.
186If the number of articles is greater than the value, verbose
eec82323
LMI
187messages will be shown to indicate the current status.")
188
189(defvoo nntp-maximum-request 400
190 "*The maximum number of the requests sent to the NNTP server at one time.
191If Emacs hangs up while retrieving headers, set the variable to a
192lower value.")
193
194(defvoo nntp-nov-is-evil nil
195 "*If non-nil, nntp will never attempt to use XOVER when talking to the server.")
196
197(defvoo nntp-xover-commands '("XOVER" "XOVERVIEW")
198 "*List of strings that are used as commands to fetch NOV lines from a server.
199The strings are tried in turn until a positive response is gotten. If
200none of the commands are successful, nntp will just grab headers one
201by one.")
202
a8151ef7 203(defvoo nntp-nov-gap 5
eec82323
LMI
204 "*Maximum allowed gap between two articles.
205If the gap between two consecutive articles is bigger than this
206variable, split the XOVER request into two requests.")
207
37cc095b
MB
208(defvoo nntp-xref-number-is-evil nil
209 "*If non-nil, Gnus never trusts article numbers in the Xref header.
210Some news servers, e.g., ones running Diablo, run multiple engines
211having the same articles but article numbers are not kept synchronized
212between them. If you connect to such a server, set this to a non-nil
213value, and Gnus never uses article numbers (that appear in the Xref
214header and vary by which engine is chosen) to refer to articles.")
215
eec82323
LMI
216(defvoo nntp-prepare-server-hook nil
217 "*Hook run before a server is opened.
218If can be used to set up a server remotely, for instance. Say you
219have an account at the machine \"other.machine\". This machine has
220access to an NNTP server that you can't access locally. You could
221then use this hook to rsh to the remote machine and start a proxy NNTP
6748645f
LMI
222server there that you can connect to. See also
223`nntp-open-connection-function'")
eec82323 224
6748645f
LMI
225(defvoo nntp-coding-system-for-read 'binary
226 "*Coding system to read from NNTP.")
227
228(defvoo nntp-coding-system-for-write 'binary
229 "*Coding system to write to NNTP.")
230
01c52d31
MB
231;; Marks
232(defvoo nntp-marks-is-evil nil
233 "*If non-nil, Gnus will never generate and use marks file for nntp groups.
234See `nnml-marks-is-evil' for more information.")
235
236(defvoo nntp-marks-file-name ".marks")
237(defvoo nntp-marks nil)
238(defvar nntp-marks-modtime (gnus-make-hashtable))
239
240(defcustom nntp-marks-directory
241 (nnheader-concat gnus-directory "marks/")
242 "*The directory where marks for nntp groups will be stored."
243 :group 'nntp
244 :type 'directory)
245
6748645f
LMI
246(defcustom nntp-authinfo-file "~/.authinfo"
247 ".netrc-like file that holds nntp authinfo passwords."
e79f14a4 248 :group 'nntp
6748645f
LMI
249 :type
250 '(choice file
251 (repeat :tag "Entries"
252 :menu-tag "Inline"
253 (list :format "%v"
254 :value ("" ("login" . "") ("password" . ""))
255 (string :tag "Host")
256 (checklist :inline t
257 (cons :format "%v"
258 (const :format "" "login")
259 (string :format "Login: %v"))
260 (cons :format "%v"
261 (const :format "" "password")
23f87bed 262 (string :format "Password: %v")))))))
6748645f 263
eec82323
LMI
264\f
265
6748645f
LMI
266(defvoo nntp-connection-timeout nil
267 "*Number of seconds to wait before an nntp connection times out.
2eebe218
DL
268If this variable is nil, which is the default, no timers are set.
269NOTE: This variable is never seen to work in Emacs 20 and XEmacs 21.")
6748645f 270
23f87bed
MB
271(defvoo nntp-prepare-post-hook nil
272 "*Hook run just before posting an article. It is supposed to be used
273to insert Cancel-Lock headers.")
274
6b958814
G
275(defvoo nntp-server-list-active-group 'try
276 "If nil, then always use GROUP instead of LIST ACTIVE.
277This is usually slower, but on misconfigured servers that don't
278update their active files often, this can help.")
279
eec82323
LMI
280;;; Internal variables.
281
6748645f
LMI
282(defvar nntp-record-commands nil
283 "*If non-nil, nntp will record all commands in the \"*nntp-log*\" buffer.")
284
eec82323
LMI
285(defvar nntp-have-messaged nil)
286
287(defvar nntp-process-wait-for nil)
288(defvar nntp-process-to-buffer nil)
289(defvar nntp-process-callback nil)
290(defvar nntp-process-decode nil)
291(defvar nntp-process-start-point nil)
292(defvar nntp-inside-change-function nil)
6748645f
LMI
293(defvoo nntp-last-command-time nil)
294(defvoo nntp-last-command nil)
295(defvoo nntp-authinfo-password nil)
296(defvoo nntp-authinfo-user nil)
01c52d31 297(defvoo nntp-authinfo-force nil)
eec82323
LMI
298
299(defvar nntp-connection-list nil)
300
301(defvoo nntp-server-type nil)
302(defvoo nntp-connection-alist nil)
303(defvoo nntp-status-string "")
304(defconst nntp-version "nntp 5.0")
305(defvoo nntp-inhibit-erase nil)
306(defvoo nntp-inhibit-output nil)
307
308(defvoo nntp-server-xover 'try)
eec82323 309
16409b0b
GM
310(defvar nntp-async-timer nil)
311(defvar nntp-async-process-list nil)
312
58090a8d 313(defvar nntp-authinfo-rejected nil
c9fc72fa
LMI
314"A custom error condition used to report 'Authentication Rejected' errors.
315Condition handlers that match just this condition ensure that the nntp
58090a8d
MB
316backend doesn't catch this error.")
317(put 'nntp-authinfo-rejected 'error-conditions '(error nntp-authinfo-rejected))
318(put 'nntp-authinfo-rejected 'error-message "Authorization Rejected")
319
eec82323
LMI
320\f
321
322;;; Internal functions.
323
324(defsubst nntp-send-string (process string)
325 "Send STRING to PROCESS."
6748645f
LMI
326 ;; We need to store the time to provide timeouts, and
327 ;; to store the command so the we can replay the command
328 ;; if the server gives us an AUTHINFO challenge.
329 (setq nntp-last-command-time (current-time)
330 nntp-last-command string)
331 (when nntp-record-commands
332 (nntp-record-command string))
23f87bed
MB
333 (process-send-string process (concat string nntp-end-of-line))
334 (or (memq (process-status process) '(open run))
335 (nntp-report "Server closed connection")))
eec82323 336
6748645f
LMI
337(defun nntp-record-command (string)
338 "Record the command STRING."
ed075cb4 339 (with-current-buffer (get-buffer-create "*nntp-log*")
6748645f
LMI
340 (goto-char (point-max))
341 (let ((time (current-time)))
342 (insert (format-time-string "%Y%m%dT%H%M%S" time)
343 "." (format "%03d" (/ (nth 2 time) 1000))
344 " " nntp-address " " string "\n"))))
345
23f87bed
MB
346(defun nntp-report (&rest args)
347 "Report an error from the nntp backend. The first string in ARGS
348can be a format string. For some commands, the failed command may be
349retried once before actually displaying the error report."
350
351 (when nntp-record-commands
352 (nntp-record-command "*** CALLED nntp-report ***"))
353
354 (nnheader-report 'nntp args)
355
356 (apply 'error args))
357
358(defun nntp-report-1 (&rest args)
359 "Throws out to nntp-with-open-group-error so that the connection may
360be restored and the command retried."
361
362 (when nntp-record-commands
363 (nntp-record-command "*** CONNECTION LOST ***"))
364
365 (throw 'nntp-with-open-group-error t))
366
1428d46b
MB
367(defmacro nntp-copy-to-buffer (buffer start end)
368 "Copy string from unibyte current buffer to multibyte buffer."
369 (if (featurep 'xemacs)
370 `(copy-to-buffer ,buffer ,start ,end)
371 `(let ((string (buffer-substring ,start ,end)))
372 (with-current-buffer ,buffer
373 (erase-buffer)
374 (insert (if enable-multibyte-characters
375 (mm-string-to-multibyte string)
376 string))
377 (goto-char (point-min))
378 nil))))
379
eec82323
LMI
380(defsubst nntp-wait-for (process wait-for buffer &optional decode discard)
381 "Wait for WAIT-FOR to arrive from PROCESS."
01c52d31 382
ed075cb4 383 (with-current-buffer (process-buffer process)
eec82323 384 (goto-char (point-min))
01c52d31 385
6748645f 386 (while (and (or (not (memq (char-after (point)) '(?2 ?3 ?4 ?5)))
58090a8d 387 (looking-at "48[02]"))
6748645f 388 (memq (process-status process) '(open run)))
58090a8d 389 (cond ((looking-at "480")
01c52d31 390 (nntp-handle-authinfo process))
58090a8d 391 ((looking-at "482")
04db63bc
G
392 (nnheader-report 'nntp "%s"
393 (get 'nntp-authinfo-rejected 'error-message))
58090a8d
MB
394 (signal 'nntp-authinfo-rejected nil))
395 ((looking-at "^.*\n")
396 (delete-region (point) (progn (forward-line 1) (point)))))
eec82323
LMI
397 (nntp-accept-process-output process)
398 (goto-char (point-min)))
399 (prog1
6748645f
LMI
400 (cond
401 ((looking-at "[45]")
402 (progn
403 (nntp-snarf-error-message)
404 nil))
405 ((not (memq (process-status process) '(open run)))
23f87bed 406 (nntp-report "Server closed connection"))
6748645f 407 (t
eec82323 408 (goto-char (point-max))
23f87bed
MB
409 (let ((limit (point-min))
410 response)
eec82323 411 (while (not (re-search-backward wait-for limit t))
6748645f 412 (nntp-accept-process-output process)
eec82323
LMI
413 ;; We assume that whatever we wait for is less than 1000
414 ;; characters long.
415 (setq limit (max (- (point-max) 1000) (point-min)))
23f87bed
MB
416 (goto-char (point-max)))
417 (setq response (match-string 0))
418 (with-current-buffer nntp-server-buffer
419 (setq nntp-process-response response)))
eec82323
LMI
420 (nntp-decode-text (not decode))
421 (unless discard
ed075cb4 422 (with-current-buffer buffer
23f87bed 423 (goto-char (point-max))
9f5e78f7 424 (nnheader-insert-buffer-substring (process-buffer process))
eec82323
LMI
425 ;; Nix out "nntp reading...." message.
426 (when nntp-have-messaged
427 (setq nntp-have-messaged nil)
23f87bed
MB
428 (nnheader-message 5 ""))))
429 t))
eec82323
LMI
430 (unless discard
431 (erase-buffer)))))
432
16409b0b
GM
433(defun nntp-kill-buffer (buffer)
434 (when (buffer-name buffer)
435 (kill-buffer buffer)
436 (nnheader-init-server-buffer)))
437
01c52d31
MB
438(defun nntp-erase-buffer (buffer)
439 "Erase contents of BUFFER."
440 (with-current-buffer buffer
441 (erase-buffer)))
442
eec82323
LMI
443(defsubst nntp-find-connection (buffer)
444 "Find the connection delivering to BUFFER."
445 (let ((alist nntp-connection-alist)
446 (buffer (if (stringp buffer) (get-buffer buffer) buffer))
447 process entry)
23f87bed 448 (while (and alist (setq entry (pop alist)))
eec82323
LMI
449 (when (eq buffer (cadr entry))
450 (setq process (car entry)
451 alist nil)))
452 (when process
453 (if (memq (process-status process) '(open run))
454 process
16409b0b 455 (nntp-kill-buffer (process-buffer process))
eec82323
LMI
456 (setq nntp-connection-alist (delq entry nntp-connection-alist))
457 nil))))
458
459(defsubst nntp-find-connection-entry (buffer)
460 "Return the entry for the connection to BUFFER."
461 (assq (nntp-find-connection buffer) nntp-connection-alist))
462
463(defun nntp-find-connection-buffer (buffer)
464 "Return the process connection buffer tied to BUFFER."
465 (let ((process (nntp-find-connection buffer)))
466 (when process
467 (process-buffer process))))
468
469(defsubst nntp-retrieve-data (command address port buffer
6748645f 470 &optional wait-for callback decode)
eec82323
LMI
471 "Use COMMAND to retrieve data into BUFFER from PORT on ADDRESS."
472 (let ((process (or (nntp-find-connection buffer)
473 (nntp-open-connection buffer))))
23f87bed
MB
474 (if process
475 (progn
476 (unless (or nntp-inhibit-erase nnheader-callback-function)
01c52d31 477 (nntp-erase-buffer (process-buffer process)))
23f87bed
MB
478 (condition-case err
479 (progn
480 (when command
481 (nntp-send-string process command))
482 (cond
483 ((eq callback 'ignore)
484 t)
485 ((and callback wait-for)
486 (nntp-async-wait process wait-for buffer decode callback)
487 t)
488 (wait-for
489 (nntp-wait-for process wait-for buffer decode))
490 (t t)))
58090a8d
MB
491 (nntp-authinfo-rejected
492 (signal 'nntp-authinfo-rejected (cdr err)))
23f87bed
MB
493 (error
494 (nnheader-report 'nntp "Couldn't open connection to %s: %s"
495 address err))
496 (quit
497 (message "Quit retrieving data from nntp")
498 (signal 'quit nil)
499 nil)))
500 (nnheader-report 'nntp "Couldn't open connection to %s" address))))
eec82323
LMI
501
502(defsubst nntp-send-command (wait-for &rest strings)
503 "Send STRINGS to server and wait until WAIT-FOR returns."
504 (when (and (not nnheader-callback-function)
505 (not nntp-inhibit-output))
01c52d31 506 (nntp-erase-buffer nntp-server-buffer))
23f87bed
MB
507 (let* ((command (mapconcat 'identity strings " "))
508 (process (nntp-find-connection nntp-server-buffer))
509 (buffer (and process (process-buffer process)))
510 (pos (and buffer (with-current-buffer buffer (point)))))
511 (if process
512 (prog1
513 (nntp-retrieve-data command
514 nntp-address nntp-port-number
515 nntp-server-buffer
516 wait-for nnheader-callback-function)
517 ;; If nothing to wait for, still remove possibly echo'ed commands.
45cb30ee
MB
518 ;; We don't have echoes if `nntp-never-echoes-commands' is non-nil
519 ;; or the value of `nntp-open-connection-function' is in
520 ;; `nntp-open-connection-functions-never-echo-commands', so we
521 ;; skip this in that cases.
23f87bed 522 (unless (or wait-for
45cb30ee
MB
523 nntp-never-echoes-commands
524 (memq
525 nntp-open-connection-function
526 nntp-open-connection-functions-never-echo-commands))
23f87bed 527 (nntp-accept-response)
ed075cb4 528 (with-current-buffer buffer
23f87bed
MB
529 (goto-char pos)
530 (if (looking-at (regexp-quote command))
531 (delete-region pos (progn (forward-line 1)
01c52d31 532 (point-at-bol)))))))
23f87bed
MB
533 (nnheader-report 'nntp "Couldn't open connection to %s."
534 nntp-address))))
eec82323
LMI
535
536(defun nntp-send-command-nodelete (wait-for &rest strings)
537 "Send STRINGS to server and wait until WAIT-FOR returns."
23f87bed
MB
538 (let* ((command (mapconcat 'identity strings " "))
539 (process (nntp-find-connection nntp-server-buffer))
540 (buffer (and process (process-buffer process)))
541 (pos (and buffer (with-current-buffer buffer (point)))))
542 (if process
543 (prog1
544 (nntp-retrieve-data command
545 nntp-address nntp-port-number
546 nntp-server-buffer
547 wait-for nnheader-callback-function)
548 ;; If nothing to wait for, still remove possibly echo'ed commands
549 (unless wait-for
550 (nntp-accept-response)
ed075cb4 551 (with-current-buffer buffer
23f87bed
MB
552 (goto-char pos)
553 (if (looking-at (regexp-quote command))
554 (delete-region pos (progn (forward-line 1)
01c52d31 555 (point-at-bol)))))))
23f87bed
MB
556 (nnheader-report 'nntp "Couldn't open connection to %s."
557 nntp-address))))
eec82323
LMI
558
559(defun nntp-send-command-and-decode (wait-for &rest strings)
560 "Send STRINGS to server and wait until WAIT-FOR returns."
561 (when (and (not nnheader-callback-function)
562 (not nntp-inhibit-output))
01c52d31 563 (nntp-erase-buffer nntp-server-buffer))
23f87bed
MB
564 (let* ((command (mapconcat 'identity strings " "))
565 (process (nntp-find-connection nntp-server-buffer))
566 (buffer (and process (process-buffer process)))
567 (pos (and buffer (with-current-buffer buffer (point)))))
568 (if process
569 (prog1
570 (nntp-retrieve-data command
571 nntp-address nntp-port-number
572 nntp-server-buffer
573 wait-for nnheader-callback-function t)
574 ;; If nothing to wait for, still remove possibly echo'ed commands
575 (unless wait-for
576 (nntp-accept-response)
ed075cb4 577 (with-current-buffer buffer
01c52d31
MB
578 (goto-char pos)
579 (if (looking-at (regexp-quote command))
580 (delete-region pos (progn (forward-line 1) (point-at-bol))))
581 )))
23f87bed
MB
582 (nnheader-report 'nntp "Couldn't open connection to %s."
583 nntp-address))))
584
eec82323
LMI
585
586(defun nntp-send-buffer (wait-for)
587 "Send the current buffer to server and wait until WAIT-FOR returns."
588 (when (and (not nnheader-callback-function)
589 (not nntp-inhibit-output))
01c52d31
MB
590 (nntp-erase-buffer
591 (nntp-find-connection-buffer nntp-server-buffer)))
eec82323 592 (nntp-encode-text)
ed075cb4
SM
593 ;; Make sure we did not forget to encode some of the content.
594 (assert (save-excursion (goto-char (point-min))
595 (not (re-search-forward "[^\000-\377]" nil t))))
596 (mm-disable-multibyte)
597 (process-send-region (nntp-find-connection nntp-server-buffer)
598 (point-min) (point-max))
eec82323
LMI
599 (nntp-retrieve-data
600 nil nntp-address nntp-port-number nntp-server-buffer
601 wait-for nnheader-callback-function))
602
603\f
604
605;;; Interface functions.
606
607(nnoo-define-basics nntp)
608
6748645f
LMI
609(defsubst nntp-next-result-arrived-p ()
610 (cond
611 ;; A result that starts with a 2xx code is terminated by
612 ;; a line with only a "." on it.
16409b0b 613 ((eq (char-after) ?2)
6748645f 614 (if (re-search-forward "\n\\.\r?\n" nil t)
01c52d31
MB
615 (progn
616 ;; Some broken news servers add another dot at the end.
617 ;; Protect against inflooping there.
618 (while (looking-at "^\\.\r?\n")
619 (forward-line 1))
620 t)
6748645f
LMI
621 nil))
622 ;; A result that starts with a 3xx or 4xx code is terminated
623 ;; by a newline.
624 ((looking-at "[34]")
625 (if (search-forward "\n" nil t)
626 t
627 nil))
628 ;; No result here.
629 (t
630 nil)))
631
23f87bed
MB
632(eval-when-compile
633 (defvar nntp-with-open-group-internal nil)
634 (defvar nntp-report-n nil))
635
ed075cb4
SM
636(defun nntp-with-open-group-function (-group -server -connectionless -bodyfun)
637 "Protect against servers that don't like clients that keep idle connections opens.
638The problem being that these servers may either close a connection or
639simply ignore any further requests on a connection. Closed
640connections are not detected until `accept-process-output' has updated
641the `process-status'. Dropped connections are not detected until the
642connection timeouts (which may be several minutes) or
643`nntp-connection-timeout' has expired. When these occur
644`nntp-with-open-group', opens a new connection then re-issues the NNTP
645command whose response triggered the error."
646 (letf ((nntp-report-n (symbol-function 'nntp-report))
647 ((symbol-function 'nntp-report) (symbol-function 'nntp-report-1))
648 (nntp-with-open-group-internal nil))
649 (while (catch 'nntp-with-open-group-error
650 ;; Open the connection to the server
651 ;; NOTE: Existing connections are NOT tested.
652 (nntp-possibly-change-group -group -server -connectionless)
653
654 (let ((-timer
655 (and nntp-connection-timeout
656 (run-at-time
657 nntp-connection-timeout nil
658 (lambda ()
659 (let* ((-process (nntp-find-connection
660 nntp-server-buffer))
661 (-buffer (and -process
662 (process-buffer -process))))
663 ;; When I an able to identify the
664 ;; connection to the server AND I've
665 ;; received NO reponse for
666 ;; nntp-connection-timeout seconds.
667 (when (and -buffer (eq 0 (buffer-size -buffer)))
668 ;; Close the connection. Take no
669 ;; other action as the accept input
670 ;; code will handle the closed
671 ;; connection.
672 (nntp-kill-buffer -buffer))))))))
673 (unwind-protect
674 (setq nntp-with-open-group-internal
675 (condition-case nil
676 (funcall -bodyfun)
677 (quit
678 (unless debug-on-quit
679 (nntp-close-server))
680 (signal 'quit nil))))
681 (when -timer
682 (nnheader-cancel-timer -timer)))
683 nil))
684 (setf (symbol-function 'nntp-report) nntp-report-n))
685 nntp-with-open-group-internal))
686
23f87bed
MB
687(defmacro nntp-with-open-group (group server &optional connectionless &rest forms)
688 "Protect against servers that don't like clients that keep idle connections opens.
689The problem being that these servers may either close a connection or
690simply ignore any further requests on a connection. Closed
ed075cb4
SM
691connections are not detected until `accept-process-output' has updated
692the `process-status'. Dropped connections are not detected until the
23f87bed 693connection timeouts (which may be several minutes) or
ed075cb4
SM
694`nntp-connection-timeout' has expired. When these occur
695`nntp-with-open-group', opens a new connection then re-issues the NNTP
23f87bed 696command whose response triggered the error."
ed075cb4 697 (declare (indent 2) (debug (form form [&optional symbolp] def-body)))
23f87bed
MB
698 (when (and (listp connectionless)
699 (not (eq connectionless nil)))
700 (setq forms (cons connectionless forms)
701 connectionless nil))
ed075cb4 702 `(nntp-with-open-group-function ,group ,server ,connectionless (lambda () ,@forms)))
23f87bed 703
eec82323
LMI
704(deffoo nntp-retrieve-headers (articles &optional group server fetch-old)
705 "Retrieve the headers of ARTICLES."
23f87bed
MB
706 (nntp-with-open-group
707 group server
ed075cb4 708 (with-current-buffer (nntp-find-connection-buffer nntp-server-buffer)
23f87bed
MB
709 (erase-buffer)
710 (if (and (not gnus-nov-is-evil)
711 (not nntp-nov-is-evil)
712 (nntp-retrieve-headers-with-xover articles fetch-old))
713 ;; We successfully retrieved the headers via XOVER.
714 'nov
715 ;; XOVER didn't work, so we do it the hard, slow and inefficient
716 ;; way.
717 (let ((number (length articles))
718 (articles articles)
719 (count 0)
720 (received 0)
721 (last-point (point-min))
722 (buf (nntp-find-connection-buffer nntp-server-buffer))
723 (nntp-inhibit-erase t)
724 article)
725 ;; Send HEAD commands.
726 (while (setq article (pop articles))
727 (nntp-send-command
728 nil
729 "HEAD" (if (numberp article)
730 (int-to-string article)
731 ;; `articles' is either a list of article numbers
732 ;; or a list of article IDs.
733 article))
734 (incf count)
735 ;; Every 400 requests we have to read the stream in
736 ;; order to avoid deadlocks.
737 (when (or (null articles) ;All requests have been sent.
738 (zerop (% count nntp-maximum-request)))
739 (nntp-accept-response)
740 (while (progn
741 (set-buffer buf)
742 (goto-char last-point)
743 ;; Count replies.
744 (while (nntp-next-result-arrived-p)
745 (setq last-point (point))
746 (incf received))
747 (< received count))
748 ;; If number of headers is greater than 100, give
749 ;; informative messages.
750 (and (numberp nntp-large-newsgroup)
751 (> number nntp-large-newsgroup)
752 (zerop (% received 20))
753 (nnheader-message 6 "NNTP: Receiving headers... %d%%"
754 (/ (* received 100) number)))
755 (nntp-accept-response))))
756 (and (numberp nntp-large-newsgroup)
757 (> number nntp-large-newsgroup)
758 (nnheader-message 6 "NNTP: Receiving headers...done"))
759
760 ;; Now all of replies are received. Fold continuation lines.
761 (nnheader-fold-continuation-lines)
762 ;; Remove all "\r"'s.
763 (nnheader-strip-cr)
1428d46b 764 (nntp-copy-to-buffer nntp-server-buffer (point-min) (point-max))
23f87bed 765 'headers)))))
eec82323 766
5415d076 767(deffoo nntp-retrieve-group-data-early (server infos)
1d88c091
LI
768 "Retrieve group info on INFOS."
769 (nntp-with-open-group nil server
770 (when (nntp-find-connection-buffer nntp-server-buffer)
771 ;; The first time this is run, this variable is `try'. So we
772 ;; try.
773 (when (eq nntp-server-list-active-group 'try)
76b8d9dd
LI
774 (nntp-try-list-active
775 (gnus-group-real-name (gnus-info-group (car infos)))))
1d88c091
LI
776 (with-current-buffer (nntp-find-connection-buffer nntp-server-buffer)
777 (erase-buffer)
778 (let ((nntp-inhibit-erase t)
779 (command (if nntp-server-list-active-group
780 "LIST ACTIVE" "GROUP")))
781 (dolist (info infos)
782 (nntp-send-command
783 nil command (gnus-group-real-name (gnus-info-group info)))))
784 (length infos)))))
785
5415d076 786(deffoo nntp-finish-retrieve-group-infos (server infos count)
1d88c091
LI
787 (nntp-with-open-group nil server
788 (let ((buf (nntp-find-connection-buffer nntp-server-buffer))
789 (method (gnus-find-method-for-group
790 (gnus-info-group (car infos))
791 (car infos)))
792 (received 0)
793 (last-point 1))
76b8d9dd
LI
794 (when (and buf
795 count)
1d88c091
LI
796 (with-current-buffer buf
797 (while (and (gnus-buffer-live-p buf)
798 (progn
799 (goto-char last-point)
800 ;; Count replies.
06b840e0
LI
801 (while (re-search-forward
802 (if nntp-server-list-active-group
803 "^[.]"
804 "^[0-9]")
805 nil t)
1d88c091
LI
806 (incf received))
807 (setq last-point (point))
808 (< received count)))
809 (nntp-accept-response))
810 ;; We now have all the entries. Remove CRs.
5415d076 811 (nnheader-strip-cr)
1d88c091
LI
812 (if (not nntp-server-list-active-group)
813 (progn
814 (nntp-copy-to-buffer nntp-server-buffer
815 (point-min) (point-max))
816 (gnus-groups-to-gnus-format method gnus-active-hashtb t))
817 ;; We have read active entries, so we just delete the
818 ;; superfluous gunk.
819 (goto-char (point-min))
820 (while (re-search-forward "^[.2-5]" nil t)
821 (delete-region (match-beginning 0)
822 (progn (forward-line 1) (point))))
823 (nntp-copy-to-buffer nntp-server-buffer (point-min) (point-max))
5415d076 824 (with-current-buffer nntp-server-buffer
06b840e0
LI
825 (gnus-active-to-gnus-format
826 ;; Kludge to use the extended method name if you have
827 ;; an extended one.
828 (if (consp (gnus-info-method (car infos)))
829 (gnus-info-method (car infos))
830 method)
831 gnus-active-hashtb nil t))))))))
1d88c091 832
eec82323
LMI
833(deffoo nntp-retrieve-groups (groups &optional server)
834 "Retrieve group info on GROUPS."
23f87bed
MB
835 (nntp-with-open-group
836 nil server
837 (when (nntp-find-connection-buffer nntp-server-buffer)
838 (catch 'done
839 (save-excursion
840 ;; Erase nntp-server-buffer before nntp-inhibit-erase.
01c52d31 841 (nntp-erase-buffer nntp-server-buffer)
23f87bed
MB
842 (set-buffer (nntp-find-connection-buffer nntp-server-buffer))
843 ;; The first time this is run, this variable is `try'. So we
844 ;; try.
845 (when (eq nntp-server-list-active-group 'try)
846 (nntp-try-list-active (car groups)))
847 (erase-buffer)
848 (let ((count 0)
849 (groups groups)
850 (received 0)
851 (last-point (point-min))
852 (nntp-inhibit-erase t)
853 (buf (nntp-find-connection-buffer nntp-server-buffer))
854 (command (if nntp-server-list-active-group
855 "LIST ACTIVE" "GROUP")))
856 (while groups
857 ;; Timeout may have killed the buffer.
858 (unless (gnus-buffer-live-p buf)
859 (nnheader-report 'nntp "Connection to %s is closed." server)
860 (throw 'done nil))
861 ;; Send the command to the server.
862 (nntp-send-command nil command (pop groups))
863 (incf count)
864 ;; Every 400 requests we have to read the stream in
865 ;; order to avoid deadlocks.
866 (when (or (null groups) ;All requests have been sent.
867 (zerop (% count nntp-maximum-request)))
868 (nntp-accept-response)
869 (while (and (gnus-buffer-live-p buf)
870 (progn
871 ;; Search `blue moon' in this file for the
872 ;; reason why set-buffer here.
873 (set-buffer buf)
874 (goto-char last-point)
875 ;; Count replies.
876 (while (re-search-forward "^[0-9]" nil t)
877 (incf received))
878 (setq last-point (point))
879 (< received count)))
880 (nntp-accept-response))))
881
882 ;; Wait for the reply from the final command.
883 (unless (gnus-buffer-live-p buf)
884 (nnheader-report 'nntp "Connection to %s is closed." server)
885 (throw 'done nil))
886 (set-buffer buf)
887 (goto-char (point-max))
888 (re-search-backward "^[0-9]" nil t)
889 (when (looking-at "^[23]")
890 (while (and (gnus-buffer-live-p buf)
891 (progn
892 (set-buffer buf)
893 (goto-char (point-max))
894 (if (not nntp-server-list-active-group)
895 (not (re-search-backward "\r?\n"
896 (- (point) 3) t))
897 (not (re-search-backward "^\\.\r?\n"
898 (- (point) 4) t)))))
899 (nntp-accept-response)))
900
901 ;; Now all replies are received. We remove CRs.
902 (unless (gnus-buffer-live-p buf)
903 (nnheader-report 'nntp "Connection to %s is closed." server)
904 (throw 'done nil))
905 (set-buffer buf)
906 (goto-char (point-min))
907 (while (search-forward "\r" nil t)
908 (replace-match "" t t))
909
910 (if (not nntp-server-list-active-group)
911 (progn
1428d46b
MB
912 (nntp-copy-to-buffer nntp-server-buffer
913 (point-min) (point-max))
23f87bed
MB
914 'group)
915 ;; We have read active entries, so we just delete the
916 ;; superfluous gunk.
917 (goto-char (point-min))
918 (while (re-search-forward "^[.2-5]" nil t)
919 (delete-region (match-beginning 0)
920 (progn (forward-line 1) (point))))
1428d46b 921 (nntp-copy-to-buffer nntp-server-buffer (point-min) (point-max))
23f87bed 922 'active)))))))
eec82323
LMI
923
924(deffoo nntp-retrieve-articles (articles &optional group server)
23f87bed
MB
925 (nntp-with-open-group
926 group server
927 (save-excursion
928 (let ((number (length articles))
929 (articles articles)
930 (count 0)
931 (received 0)
932 (last-point (point-min))
933 (buf (nntp-find-connection-buffer nntp-server-buffer))
934 (nntp-inhibit-erase t)
935 (map (apply 'vector articles))
936 (point 1)
937 article)
938 (set-buffer buf)
939 (erase-buffer)
940 ;; Send ARTICLE command.
941 (while (setq article (pop articles))
942 (nntp-send-command
943 nil
944 "ARTICLE" (if (numberp article)
945 (int-to-string article)
946 ;; `articles' is either a list of article numbers
947 ;; or a list of article IDs.
948 article))
949 (incf count)
950 ;; Every 400 requests we have to read the stream in
951 ;; order to avoid deadlocks.
952 (when (or (null articles) ;All requests have been sent.
953 (zerop (% count nntp-maximum-request)))
954 (nntp-accept-response)
955 (while (progn
956 (set-buffer buf)
957 (goto-char last-point)
958 ;; Count replies.
959 (while (nntp-next-result-arrived-p)
960 (aset map received (cons (aref map received) (point)))
961 (setq last-point (point))
962 (incf received))
963 (< received count))
964 ;; If number of headers is greater than 100, give
965 ;; informative messages.
966 (and (numberp nntp-large-newsgroup)
967 (> number nntp-large-newsgroup)
968 (zerop (% received 20))
969 (nnheader-message 6 "NNTP: Receiving articles... %d%%"
970 (/ (* received 100) number)))
971 (nntp-accept-response))))
972 (and (numberp nntp-large-newsgroup)
973 (> number nntp-large-newsgroup)
974 (nnheader-message 6 "NNTP: Receiving articles...done"))
975
976 ;; Now we have all the responses. We go through the results,
977 ;; wash it and copy it over to the server buffer.
978 (set-buffer nntp-server-buffer)
979 (erase-buffer)
980 (setq last-point (point-min))
981 (mapcar
982 (lambda (entry)
983 (narrow-to-region
984 (setq point (goto-char (point-max)))
985 (progn
9f5e78f7 986 (nnheader-insert-buffer-substring buf last-point (cdr entry))
23f87bed
MB
987 (point-max)))
988 (setq last-point (cdr entry))
989 (nntp-decode-text)
990 (widen)
991 (cons (car entry) point))
992 map)))))
eec82323 993
eec82323
LMI
994(defun nntp-try-list-active (group)
995 (nntp-list-active-group group)
ed075cb4 996 (with-current-buffer nntp-server-buffer
eec82323
LMI
997 (goto-char (point-min))
998 (cond ((or (eobp)
999 (looking-at "5[0-9]+"))
1000 (setq nntp-server-list-active-group nil))
1001 (t
1002 (setq nntp-server-list-active-group t)))))
1003
1004(deffoo nntp-list-active-group (group &optional server)
16409b0b 1005 "Return the active info on GROUP (which can be a regexp)."
23f87bed
MB
1006 (nntp-with-open-group
1007 nil server
1008 (nntp-send-command "^\\.*\r?\n" "LIST ACTIVE" group)))
16409b0b
GM
1009
1010(deffoo nntp-request-group-articles (group &optional server)
1011 "Return the list of existing articles in GROUP."
23f87bed
MB
1012 (nntp-with-open-group
1013 nil server
1014 (nntp-send-command "^\\.*\r?\n" "LISTGROUP" group)))
eec82323
LMI
1015
1016(deffoo nntp-request-article (article &optional group server buffer command)
23f87bed 1017 (nntp-with-open-group
b87f32fc 1018 group server
23f87bed
MB
1019 (when (nntp-send-command-and-decode
1020 "\r?\n\\.\r?\n" "ARTICLE"
1021 (if (numberp article) (int-to-string article) article))
b87f32fc
G
1022 (when (and buffer
1023 (not (equal buffer nntp-server-buffer)))
1024 (with-current-buffer nntp-server-buffer
1025 (copy-to-buffer buffer (point-min) (point-max))))
1026 (nntp-find-group-and-number group))))
eec82323
LMI
1027
1028(deffoo nntp-request-head (article &optional group server)
23f87bed
MB
1029 (nntp-with-open-group
1030 group server
1031 (when (nntp-send-command
1032 "\r?\n\\.\r?\n" "HEAD"
1033 (if (numberp article) (int-to-string article) article))
1034 (prog1
1035 (nntp-find-group-and-number group)
1036 (nntp-decode-text)))))
eec82323
LMI
1037
1038(deffoo nntp-request-body (article &optional group server)
23f87bed
MB
1039 (nntp-with-open-group
1040 group server
1041 (nntp-send-command-and-decode
1042 "\r?\n\\.\r?\n" "BODY"
1043 (if (numberp article) (int-to-string article) article))))
eec82323 1044
286c4fc2 1045(deffoo nntp-request-group (group &optional server dont-check info)
e84b4b86 1046 (nntp-with-open-group
23f87bed
MB
1047 nil server
1048 (when (nntp-send-command "^[245].*\n" "GROUP" group)
1049 (let ((entry (nntp-find-connection-entry nntp-server-buffer)))
1050 (setcar (cddr entry) group)))))
eec82323
LMI
1051
1052(deffoo nntp-close-group (group &optional server)
1053 t)
1054
1055(deffoo nntp-server-opened (&optional server)
1056 "Say whether a connection to SERVER has been opened."
1057 (and (nnoo-current-server-p 'nntp server)
1058 nntp-server-buffer
1059 (gnus-buffer-live-p nntp-server-buffer)
1060 (nntp-find-connection nntp-server-buffer)))
1061
1062(deffoo nntp-open-server (server &optional defs connectionless)
1063 (nnheader-init-server-buffer)
1064 (if (nntp-server-opened server)
1065 t
1066 (when (or (stringp (car defs))
1067 (numberp (car defs)))
1068 (setq defs (cons (list 'nntp-port-number (car defs)) (cdr defs))))
1069 (unless (assq 'nntp-address defs)
1070 (setq defs (append defs (list (list 'nntp-address server)))))
1071 (nnoo-change-server 'nntp server defs)
20a673b2
KY
1072 (if connectionless
1073 t
eec82323
LMI
1074 (or (nntp-find-connection nntp-server-buffer)
1075 (nntp-open-connection nntp-server-buffer)))))
1076
1077(deffoo nntp-close-server (&optional server)
1078 (nntp-possibly-change-group nil server t)
6748645f
LMI
1079 (let ((process (nntp-find-connection nntp-server-buffer)))
1080 (while process
eec82323 1081 (when (memq (process-status process) '(open run))
6748645f
LMI
1082 (ignore-errors
1083 (nntp-send-string process "QUIT")
1084 (unless (eq nntp-open-connection-function 'nntp-open-network-stream)
1085 ;; Ok, this is evil, but when using telnet and stuff
1086 ;; as the connection method, it's important that the
1087 ;; QUIT command actually is sent out before we kill
1088 ;; the process.
1089 (sleep-for 1))))
16409b0b 1090 (nntp-kill-buffer (process-buffer process))
6748645f 1091 (setq process (car (pop nntp-connection-alist))))
eec82323
LMI
1092 (nnoo-close-server 'nntp)))
1093
1094(deffoo nntp-request-close ()
1095 (let (process)
1096 (while (setq process (pop nntp-connection-list))
1097 (when (memq (process-status process) '(open run))
eec82323 1098 (ignore-errors
6748645f
LMI
1099 (nntp-send-string process "QUIT")
1100 (unless (eq nntp-open-connection-function 'nntp-open-network-stream)
1101 ;; Ok, this is evil, but when using telnet and stuff
1102 ;; as the connection method, it's important that the
1103 ;; QUIT command actually is sent out before we kill
1104 ;; the process.
1105 (sleep-for 1))))
16409b0b 1106 (nntp-kill-buffer (process-buffer process)))))
eec82323
LMI
1107
1108(deffoo nntp-request-list (&optional server)
23f87bed
MB
1109 (nntp-with-open-group
1110 nil server
1111 (nntp-send-command-and-decode "\r?\n\\.\r?\n" "LIST")))
eec82323
LMI
1112
1113(deffoo nntp-request-list-newsgroups (&optional server)
23f87bed
MB
1114 (nntp-with-open-group
1115 nil server
1116 (nntp-send-command "\r?\n\\.\r?\n" "LIST NEWSGROUPS")))
eec82323
LMI
1117
1118(deffoo nntp-request-newgroups (date &optional server)
23f87bed
MB
1119 (nntp-with-open-group
1120 nil server
ed075cb4 1121 (with-current-buffer nntp-server-buffer
23f87bed
MB
1122 (let* ((time (date-to-time date))
1123 (ls (- (cadr time) (nth 8 (decode-time time)))))
1124 (cond ((< ls 0)
1125 (setcar time (1- (car time)))
1126 (setcar (cdr time) (+ ls 65536)))
1127 ((>= ls 65536)
1128 (setcar time (1+ (car time)))
1129 (setcar (cdr time) (- ls 65536)))
1130 (t
1131 (setcar (cdr time) ls)))
1132 (prog1
1133 (nntp-send-command
1134 "^\\.\r?\n" "NEWGROUPS"
1135 (format-time-string "%y%m%d %H%M%S" time)
1136 "GMT")
1137 (nntp-decode-text))))))
eec82323
LMI
1138
1139(deffoo nntp-request-post (&optional server)
23f87bed
MB
1140 (nntp-with-open-group
1141 nil server
1142 (when (nntp-send-command "^[23].*\r?\n" "POST")
1143 (let ((response (with-current-buffer nntp-server-buffer
1144 nntp-process-response))
1145 server-id)
1146 (when (and response
1147 (string-match "^[23].*\\(<[^\t\n @<>]+@[^\t\n @<>]+>\\)"
1148 response))
1149 (setq server-id (match-string 1 response))
1150 (narrow-to-region (goto-char (point-min))
1151 (if (search-forward "\n\n" nil t)
1152 (1- (point))
1153 (point-max)))
1154 (unless (mail-fetch-field "Message-ID")
1155 (goto-char (point-min))
1156 (insert "Message-ID: " server-id "\n"))
1157 (widen))
1158 (run-hooks 'nntp-prepare-post-hook)
1159 (nntp-send-buffer "^[23].*\n")))))
eec82323
LMI
1160
1161(deffoo nntp-request-type (group article)
1162 'news)
1163
1164(deffoo nntp-asynchronous-p ()
1165 t)
1166
01c52d31 1167(deffoo nntp-request-set-mark (group actions &optional server)
a93b858c
LMI
1168 (when (and (not nntp-marks-is-evil)
1169 nntp-marks-file-name)
01c52d31
MB
1170 (nntp-possibly-create-directory group server)
1171 (nntp-open-marks group server)
5f285722 1172 (setq nntp-marks (nnheader-update-marks-actions nntp-marks actions))
01c52d31
MB
1173 (nntp-save-marks group server))
1174 nil)
1175
b1ae92ba 1176(deffoo nntp-request-marks (group info &optional server)
a93b858c
LMI
1177 (when (and (not nntp-marks-is-evil)
1178 nntp-marks-file-name)
01c52d31
MB
1179 (nntp-possibly-create-directory group server)
1180 (when (nntp-marks-changed-p group server)
1181 (nnheader-message 8 "Updating marks for %s..." group)
1182 (nntp-open-marks group server)
1183 ;; Update info using `nntp-marks'.
1184 (mapc (lambda (pred)
1185 (unless (memq (cdr pred) gnus-article-unpropagated-mark-lists)
1186 (gnus-info-set-marks
1187 info
1188 (gnus-update-alist-soft
1189 (cdr pred)
1190 (cdr (assq (cdr pred) nntp-marks))
1191 (gnus-info-marks info))
1192 t)))
1193 gnus-article-mark-lists)
1194 (let ((seen (cdr (assq 'read nntp-marks))))
1195 (gnus-info-set-read info
1196 (if (and (integerp (car seen))
1197 (null (cdr seen)))
1198 (list (cons (car seen) (car seen)))
1199 seen)))
1200 (nnheader-message 8 "Updating marks for %s...done" group)))
1201 nil)
1202
1203
1204
eec82323
LMI
1205;;; Hooky functions.
1206
1207(defun nntp-send-mode-reader ()
1208 "Send the MODE READER command to the nntp server.
1209This function is supposed to be called from `nntp-server-opened-hook'.
1210It will make innd servers spawn an nnrpd process to allow actual article
1211reading."
16409b0b 1212 (nntp-send-command "^.*\n" "MODE READER"))
eec82323 1213
c8ccffb1 1214(declare-function netrc-parse "netrc" (&optional file))
aa8f8277
GM
1215(declare-function netrc-machine "netrc"
1216 (list machine &optional port defaultport))
1217(declare-function netrc-get "netrc" (alist type))
1218
6748645f 1219(defun nntp-send-authinfo (&optional send-if-force)
eec82323 1220 "Send the AUTHINFO to the nntp server.
6748645f
LMI
1221It will look in the \"~/.authinfo\" file for matching entries. If
1222nothing suitable is found there, it will prompt for a user name
1223and a password.
1224
1225If SEND-IF-FORCE, only send authinfo to the server if the
1226.authinfo file has the FORCE token."
aa8f8277 1227 (require 'netrc)
01c52d31
MB
1228 (let* ((list (netrc-parse nntp-authinfo-file))
1229 (alist (netrc-machine list nntp-address "nntp"))
1230 (force (or (netrc-get alist "force") nntp-authinfo-force))
b8e0f0cd
G
1231 (auth-info
1232 (nth 0 (auth-source-search :max 1
1233 ;; TODO: allow the virtual server name too
1234 :host nntp-address
1235 :port '("119" "nntp"))))
1236 (auth-user (plist-get auth-info :user))
1237 (auth-passwd (plist-get auth-info :secret))
1238 (auth-passwd (if (functionp auth-passwd)
1239 (funcall auth-passwd)
1240 auth-passwd))
8abf1b22 1241 (user (or
e952b711 1242 ;; this is preferred to netrc-*
3b36c17e 1243 auth-user
8abf1b22 1244 (netrc-get alist "login")
e952b711
MB
1245 nntp-authinfo-user))
1246 (passwd (or
1247 ;; this is preferred to netrc-*
3b36c17e 1248 auth-passwd
e952b711 1249 (netrc-get alist "password"))))
6748645f
LMI
1250 (when (or (not send-if-force)
1251 force)
1252 (unless user
1253 (setq user (read-string (format "NNTP (%s) user name: " nntp-address))
1254 nntp-authinfo-user user))
1255 (unless (member user '(nil ""))
1256 (nntp-send-command "^3.*\r?\n" "AUTHINFO USER" user)
1257 (when t ;???Should check if AUTHINFO succeeded
16409b0b
GM
1258 (nntp-send-command
1259 "^2.*\r?\n" "AUTHINFO PASS"
1260 (or passwd
1261 nntp-authinfo-password
1262 (setq nntp-authinfo-password
23f87bed
MB
1263 (read-passwd (format "NNTP (%s@%s) password: "
1264 user nntp-address))))))))))
6748645f
LMI
1265
1266(defun nntp-send-nosy-authinfo ()
1267 "Send the AUTHINFO to the nntp server."
1268 (let ((user (read-string (format "NNTP (%s) user name: " nntp-address))))
1269 (unless (member user '(nil ""))
1270 (nntp-send-command "^3.*\r?\n" "AUTHINFO USER" user)
1271 (when t ;???Should check if AUTHINFO succeeded
1272 (nntp-send-command "^2.*\r?\n" "AUTHINFO PASS"
23f87bed
MB
1273 (read-passwd (format "NNTP (%s@%s) password: "
1274 user nntp-address)))))))
eec82323
LMI
1275
1276(defun nntp-send-authinfo-from-file ()
1277 "Send the AUTHINFO to the nntp server.
6748645f
LMI
1278
1279The authinfo login name is taken from the user's login name and the
1280password contained in '~/.nntp-authinfo'."
eec82323 1281 (when (file-exists-p "~/.nntp-authinfo")
16409b0b 1282 (with-temp-buffer
eec82323
LMI
1283 (insert-file-contents "~/.nntp-authinfo")
1284 (goto-char (point-min))
6748645f 1285 (nntp-send-command "^3.*\r?\n" "AUTHINFO USER" (user-login-name))
eec82323 1286 (nntp-send-command
6748645f 1287 "^2.*\r?\n" "AUTHINFO PASS"
01c52d31 1288 (buffer-substring (point) (point-at-eol))))))
eec82323
LMI
1289
1290;;; Internal functions.
1291
6748645f
LMI
1292(defun nntp-handle-authinfo (process)
1293 "Take care of an authinfo response from the server."
1294 (let ((last nntp-last-command))
1295 (funcall nntp-authinfo-function)
1296 ;; We have to re-send the function that was interrupted by
1297 ;; the authinfo request.
01c52d31 1298 (nntp-erase-buffer nntp-server-buffer)
6748645f
LMI
1299 (nntp-send-string process last)))
1300
eec82323
LMI
1301(defun nntp-make-process-buffer (buffer)
1302 "Create a new, fresh buffer usable for nntp process connections."
ed075cb4
SM
1303 (with-current-buffer
1304 (generate-new-buffer
1305 (format " *server %s %s %s*"
1306 nntp-address nntp-port-number
1307 (gnus-buffer-exists-p buffer)))
1428d46b 1308 (mm-disable-multibyte)
eec82323
LMI
1309 (set (make-local-variable 'after-change-functions) nil)
1310 (set (make-local-variable 'nntp-process-wait-for) nil)
1311 (set (make-local-variable 'nntp-process-callback) nil)
1312 (set (make-local-variable 'nntp-process-to-buffer) nil)
1313 (set (make-local-variable 'nntp-process-start-point) nil)
1314 (set (make-local-variable 'nntp-process-decode) nil)
1315 (current-buffer)))
1316
1317(defun nntp-open-connection (buffer)
1318 "Open a connection to PORT on ADDRESS delivering output to BUFFER."
1319 (run-hooks 'nntp-prepare-server-hook)
1320 (let* ((pbuffer (nntp-make-process-buffer buffer))
6748645f
LMI
1321 (timer
1322 (and nntp-connection-timeout
01c52d31 1323 (run-at-time
6748645f
LMI
1324 nntp-connection-timeout nil
1325 `(lambda ()
16409b0b 1326 (nntp-kill-buffer ,pbuffer)))))
eec82323 1327 (process
ed797193 1328 (condition-case err
ccaab511 1329 (let ((coding-system-for-read nntp-coding-system-for-read)
ed797193 1330 (coding-system-for-write nntp-coding-system-for-write)
e742e117
CY
1331 (map '((nntp-open-network-stream network)
1332 (network-only plain) ; compat
1333 (nntp-open-plain-stream plain)
ed797193
G
1334 (nntp-open-ssl-stream tls)
1335 (nntp-open-tls-stream tls))))
1336 (if (assoc nntp-open-connection-function map)
f2eefd24
CY
1337 (open-protocol-stream
1338 "nntpd" pbuffer nntp-address nntp-port-number
e742e117 1339 :type (cadr (assoc nntp-open-connection-function map))
f2eefd24
CY
1340 :end-of-command "^\\([2345]\\|[.]\\).*\n"
1341 :capability-command "CAPABILITIES\r\n"
1342 :success "^3"
1343 :starttls-function
1344 (lambda (capabilities)
1345 (if (not (string-match "STARTTLS" capabilities))
1346 nil
1347 "STARTTLS\r\n")))
ed797193
G
1348 (funcall nntp-open-connection-function pbuffer)))
1349 (error
f2eefd24 1350 (nnheader-report 'nntp ">>> %s" err))
2eebe218 1351 (quit
01c52d31 1352 (message "Quit opening connection to %s" nntp-address)
2eebe218
DL
1353 (nntp-kill-buffer pbuffer)
1354 (signal 'quit nil)
1355 nil))))
6748645f
LMI
1356 (when timer
1357 (nnheader-cancel-timer timer))
f2eefd24
CY
1358 (when (and process
1359 (not (memq (process-status process) '(open run))))
1360 (setq process nil))
23f87bed
MB
1361 (unless process
1362 (nntp-kill-buffer pbuffer))
6748645f
LMI
1363 (when (and (buffer-name pbuffer)
1364 process)
7887e229
KY
1365 (when (and (fboundp 'set-network-process-option) ;; Unavailable in XEmacs.
1366 (fboundp 'process-type) ;; Emacs 22 doesn't provide it.
68b5d5ee
SM
1367 (eq (process-type process) 'network))
1368 ;; Use TCP-keepalive so that connections that pass through a NAT router
1369 ;; don't hang when left idle.
1370 (set-network-process-option process :keepalive t))
4a43ee9b 1371 (gnus-set-process-query-on-exit-flag process nil)
23f87bed
MB
1372 (if (and (nntp-wait-for process "^2.*\n" buffer nil t)
1373 (memq (process-status process) '(open run)))
eec82323
LMI
1374 (prog1
1375 (caar (push (list process buffer nil) nntp-connection-alist))
1376 (push process nntp-connection-list)
ed075cb4 1377 (with-current-buffer pbuffer
eec82323
LMI
1378 (nntp-read-server-type)
1379 (erase-buffer)
1380 (set-buffer nntp-server-buffer)
1381 (let ((nnheader-callback-function nil))
6748645f
LMI
1382 (run-hooks 'nntp-server-opened-hook)
1383 (nntp-send-authinfo t))))
16409b0b 1384 (nntp-kill-buffer (process-buffer process))
eec82323
LMI
1385 nil))))
1386
eec82323
LMI
1387(defun nntp-read-server-type ()
1388 "Find out what the name of the server we have connected to is."
1389 ;; Wait for the status string to arrive.
1390 (setq nntp-server-type (buffer-string))
01c52d31 1391 (let ((case-fold-search t))
eec82323 1392 ;; Run server-specific commands.
01c52d31 1393 (dolist (entry nntp-server-action-alist)
eec82323
LMI
1394 (when (string-match (car entry) nntp-server-type)
1395 (if (and (listp (cadr entry))
1396 (not (eq 'lambda (caadr entry))))
1397 (eval (cadr entry))
1398 (funcall (cadr entry)))))))
1399
16409b0b 1400(defun nntp-async-wait (process wait-for buffer decode callback)
ed075cb4 1401 (with-current-buffer (process-buffer process)
16409b0b
GM
1402 (unless nntp-inside-change-function
1403 (erase-buffer))
1404 (setq nntp-process-wait-for wait-for
1405 nntp-process-to-buffer buffer
1406 nntp-process-decode decode
1407 nntp-process-callback callback
1408 nntp-process-start-point (point-max))
6b8382e4 1409 (setq after-change-functions '(nntp-after-change-function))))
16409b0b
GM
1410
1411(defun nntp-async-timer-handler ()
1412 (mapcar
1413 (lambda (proc)
1414 (if (memq (process-status proc) '(open run))
1415 (nntp-async-trigger proc)
1416 (nntp-async-stop proc)))
1417 nntp-async-process-list))
1418
1419(defun nntp-async-stop (proc)
1420 (setq nntp-async-process-list (delq proc nntp-async-process-list))
1421 (when (and nntp-async-timer (not nntp-async-process-list))
1422 (nnheader-cancel-timer nntp-async-timer)
1423 (setq nntp-async-timer nil)))
1424
1425(defun nntp-after-change-function (beg end len)
1426 (unwind-protect
1427 ;; we only care about insertions at eob
1428 (when (and (eq 0 len) (eq (point-max) end))
1429 (save-match-data
1430 (let ((proc (get-buffer-process (current-buffer))))
1431 (when proc
1432 (nntp-async-trigger proc)))))
1433 ;; any throw from after-change-functions will leave it
1434 ;; set to nil. so we reset it here, if necessary.
1435 (when quit-flag
1436 (setq after-change-functions '(nntp-after-change-function)))))
1437
1438(defun nntp-async-trigger (process)
ed075cb4 1439 (with-current-buffer (process-buffer process)
16409b0b
GM
1440 (when nntp-process-callback
1441 ;; do we have an error message?
1442 (goto-char nntp-process-start-point)
1443 (if (memq (following-char) '(?4 ?5))
1444 ;; wants credentials?
1445 (if (looking-at "480")
2eebe218 1446 (nntp-handle-authinfo process)
16409b0b
GM
1447 ;; report error message.
1448 (nntp-snarf-error-message)
1449 (nntp-do-callback nil))
1450
1451 ;; got what we expect?
1452 (goto-char (point-max))
1453 (when (re-search-backward
1454 nntp-process-wait-for nntp-process-start-point t)
23f87bed
MB
1455 (let ((response (match-string 0)))
1456 (with-current-buffer nntp-server-buffer
1457 (setq nntp-process-response response)))
16409b0b
GM
1458 (nntp-async-stop process)
1459 ;; convert it.
6748645f 1460 (when (gnus-buffer-exists-p nntp-process-to-buffer)
16409b0b
GM
1461 (let ((buf (current-buffer))
1462 (start nntp-process-start-point)
1463 (decode nntp-process-decode))
ed075cb4 1464 (with-current-buffer nntp-process-to-buffer
eec82323 1465 (goto-char (point-max))
16409b0b
GM
1466 (save-restriction
1467 (narrow-to-region (point) (point))
9f5e78f7 1468 (nnheader-insert-buffer-substring buf start)
16409b0b
GM
1469 (when decode
1470 (nntp-decode-text))))))
1471 ;; report it.
1472 (goto-char (point-max))
1473 (nntp-do-callback
1474 (buffer-name (get-buffer nntp-process-to-buffer))))))))
1475
1476(defun nntp-do-callback (arg)
1477 (let ((callback nntp-process-callback)
1478 (nntp-inside-change-function t))
1479 (setq nntp-process-callback nil)
1480 (funcall callback arg)))
eec82323
LMI
1481
1482(defun nntp-snarf-error-message ()
1483 "Save the error message in the current buffer."
1484 (let ((message (buffer-string)))
1485 (while (string-match "[\r\n]+" message)
1486 (setq message (replace-match " " t t message)))
04db63bc 1487 (nnheader-report 'nntp "%s" message)
eec82323
LMI
1488 message))
1489
23f87bed 1490(defun nntp-accept-process-output (process)
eec82323 1491 "Wait for output from PROCESS and message some dots."
01c52d31
MB
1492 (with-current-buffer (or (nntp-find-connection-buffer nntp-server-buffer)
1493 nntp-server-buffer)
c7279817 1494 (let ((len (/ (buffer-size) 1024))
eec82323
LMI
1495 message-log-max)
1496 (unless (< len 10)
1497 (setq nntp-have-messaged t)
1498 (nnheader-message 7 "nntp read: %dk" len)))
01c52d31
MB
1499 (prog1
1500 (nnheader-accept-process-output process)
1501 ;; accept-process-output may update status of process to indicate
1502 ;; that the server has closed the connection. This MUST be
1503 ;; handled here as the buffer restored by the save-excursion may
1504 ;; be the process's former output buffer (i.e. now killed)
1505 (or (and process
1506 (memq (process-status process) '(open run)))
1507 (nntp-report "Server closed connection")))))
eec82323
LMI
1508
1509(defun nntp-accept-response ()
1510 "Wait for output from the process that outputs to BUFFER."
1511 (nntp-accept-process-output (nntp-find-connection nntp-server-buffer)))
1512
1513(defun nntp-possibly-change-group (group server &optional connectionless)
1514 (let ((nnheader-callback-function nil))
1515 (when server
1516 (or (nntp-server-opened server)
1517 (nntp-open-server server nil connectionless)))
1518
1519 (unless connectionless
1520 (or (nntp-find-connection nntp-server-buffer)
1521 (nntp-open-connection nntp-server-buffer))))
1522
1523 (when group
1524 (let ((entry (nntp-find-connection-entry nntp-server-buffer)))
23f87bed
MB
1525 (cond ((not entry)
1526 (nntp-report "Server closed connection"))
1527 ((not (equal group (caddr entry)))
ed075cb4 1528 (with-current-buffer (process-buffer (car entry))
23f87bed
MB
1529 (erase-buffer)
1530 (nntp-send-command "^[245].*\n" "GROUP" group)
1531 (setcar (cddr entry) group)
1532 (erase-buffer)
01c52d31 1533 (nntp-erase-buffer nntp-server-buffer)))))))
eec82323
LMI
1534
1535(defun nntp-decode-text (&optional cr-only)
1536 "Decode the text in the current buffer."
1537 (goto-char (point-min))
1538 (while (search-forward "\r" nil t)
1539 (delete-char -1))
1540 (unless cr-only
1541 ;; Remove trailing ".\n" end-of-transfer marker.
1542 (goto-char (point-max))
1543 (forward-line -1)
1544 (when (looking-at ".\n")
1545 (delete-char 2))
1546 ;; Delete status line.
1547 (goto-char (point-min))
2eebe218
DL
1548 (while (looking-at "[1-5][0-9][0-9] .*\n")
1549 ;; For some unknown reason, there is more than one status line.
1550 (delete-region (point) (progn (forward-line 1) (point))))
eec82323
LMI
1551 ;; Remove "." -> ".." encoding.
1552 (while (search-forward "\n.." nil t)
1553 (delete-char -1))))
1554
1555(defun nntp-encode-text ()
1556 "Encode the text in the current buffer."
1557 (save-excursion
1558 ;; Replace "." at beginning of line with "..".
1559 (goto-char (point-min))
1560 (while (re-search-forward "^\\." nil t)
1561 (insert "."))
1562 (goto-char (point-max))
1563 ;; Insert newline at the end of the buffer.
1564 (unless (bolp)
1565 (insert "\n"))
1566 ;; Insert `.' at end of buffer (end of text mark).
1567 (goto-char (point-max))
45926d06
RS
1568 (insert ".\n")
1569 (goto-char (point-min))
1570 (while (not (eobp))
1571 (end-of-line)
1572 (delete-char 1)
1573 (insert nntp-end-of-line))))
eec82323
LMI
1574
1575(defun nntp-retrieve-headers-with-xover (articles &optional fetch-old)
1576 (set-buffer nntp-server-buffer)
1577 (erase-buffer)
1578 (cond
1579
1580 ;; This server does not talk NOV.
1581 ((not nntp-server-xover)
1582 nil)
1583
1584 ;; We don't care about gaps.
1585 ((or (not nntp-nov-gap)
1586 fetch-old)
1587 (nntp-send-xover-command
1588 (if fetch-old
1589 (if (numberp fetch-old)
1590 (max 1 (- (car articles) fetch-old))
1591 1)
1592 (car articles))
1593 (car (last articles)) 'wait)
1594
1595 (goto-char (point-min))
16409b0b 1596 (when (looking-at "[1-5][0-9][0-9] .*\n")
eec82323
LMI
1597 (delete-region (point) (progn (forward-line 1) (point))))
1598 (while (search-forward "\r" nil t)
1599 (replace-match "" t t))
1600 (goto-char (point-max))
1601 (forward-line -1)
1602 (when (looking-at "\\.")
1603 (delete-region (point) (progn (forward-line 1) (point)))))
1604
1605 ;; We do it the hard way. For each gap, an XOVER command is sent
1606 ;; to the server. We do not wait for a reply from the server, we
1607 ;; just send them off as fast as we can. That means that we have
1608 ;; to count the number of responses we get back to find out when we
1609 ;; have gotten all we asked for.
1610 ((numberp nntp-nov-gap)
1611 (let ((count 0)
1612 (received 0)
16409b0b
GM
1613 last-point
1614 in-process-buffer-p
eec82323 1615 (buf nntp-server-buffer)
16409b0b 1616 (process-buffer (nntp-find-connection-buffer nntp-server-buffer))
23f87bed 1617 first last status)
eec82323
LMI
1618 ;; We have to check `nntp-server-xover'. If it gets set to nil,
1619 ;; that means that the server does not understand XOVER, but we
1620 ;; won't know that until we try.
1621 (while (and nntp-server-xover articles)
1622 (setq first (car articles))
1623 ;; Search forward until we find a gap, or until we run out of
1624 ;; articles.
1625 (while (and (cdr articles)
1626 (< (- (nth 1 articles) (car articles)) nntp-nov-gap))
1627 (setq articles (cdr articles)))
1628
16409b0b 1629 (setq in-process-buffer-p (stringp nntp-server-xover))
23f87bed
MB
1630 (nntp-send-xover-command first (setq last (car articles)))
1631 (setq articles (cdr articles))
a1506d29 1632
16409b0b
GM
1633 (when (and nntp-server-xover in-process-buffer-p)
1634 ;; Don't count tried request.
1635 (setq count (1+ count))
a1506d29 1636
eec82323
LMI
1637 ;; Every 400 requests we have to read the stream in
1638 ;; order to avoid deadlocks.
1639 (when (or (null articles) ;All requests have been sent.
23f87bed 1640 (= 1 (% count nntp-maximum-request)))
16409b0b
GM
1641
1642 (nntp-accept-response)
1643 ;; On some Emacs versions the preceding function has a
1644 ;; tendency to change the buffer. Perhaps. It's quite
1645 ;; difficult to reproduce, because it only seems to happen
1646 ;; once in a blue moon.
1647 (set-buffer process-buffer)
eec82323 1648 (while (progn
16409b0b 1649 (goto-char (or last-point (point-min)))
eec82323 1650 ;; Count replies.
23f87bed
MB
1651 (while (re-search-forward "^\\([0-9][0-9][0-9]\\) .*\n"
1652 nil t)
1653 (incf received)
1654 (setq status (match-string 1))
1655 (if (string-match "^[45]" status)
1656 (setq status 'error)
1657 (setq status 'ok)))
eec82323 1658 (setq last-point (point))
23f87bed
MB
1659 (or (< received count)
1660 (if (eq status 'error)
1661 nil
1662 ;; I haven't started reading the final response
1663 (progn
1664 (goto-char (point-max))
1665 (forward-line -1)
1666 (not (looking-at "^\\.\r?\n"))))))
1667 ;; I haven't read the end of the final response
16409b0b 1668 (nntp-accept-response)
23f87bed
MB
1669 (set-buffer process-buffer))))
1670
1671 ;; Some nntp servers seem to have an extension to the XOVER
1672 ;; extension. On these servers, requesting an article range
97610156 1673 ;; preceding the active range does not return an error as
23f87bed
MB
1674 ;; specified in the RFC. What we instead get is the NOV entry
1675 ;; for the first available article. Obviously, a client can
1676 ;; use that entry to avoid making unnecessary requests. The
1677 ;; only problem is for a client that assumes that the response
1678 ;; will always be within the requested ranage. For such a
1679 ;; client, we can get N copies of the same entry (one for each
1680 ;; XOVER command sent to the server).
1681
1682 (when (<= count 1)
1683 (goto-char (point-min))
1684 (when (re-search-forward "^[0-9][0-9][0-9] .*\n\\([0-9]+\\)" nil t)
e9bd5782 1685 (let ((low-limit (string-to-number
e84b4b86 1686 (buffer-substring (match-beginning 1)
23f87bed
MB
1687 (match-end 1)))))
1688 (while (and articles (<= (car articles) low-limit))
1689 (setq articles (cdr articles))))))
1690 (set-buffer buf))
eec82323
LMI
1691
1692 (when nntp-server-xover
16409b0b 1693 (when in-process-buffer-p
16409b0b
GM
1694 (set-buffer buf)
1695 (goto-char (point-max))
9f5e78f7 1696 (nnheader-insert-buffer-substring process-buffer)
16409b0b
GM
1697 (set-buffer process-buffer)
1698 (erase-buffer)
1699 (set-buffer buf))
eec82323
LMI
1700
1701 ;; We remove any "." lines and status lines.
1702 (goto-char (point-min))
1703 (while (search-forward "\r" nil t)
1704 (delete-char -1))
1705 (goto-char (point-min))
1706 (delete-matching-lines "^\\.$\\|^[1-5][0-9][0-9] ")
eec82323
LMI
1707 t))))
1708
1709 nntp-server-xover)
1710
1711(defun nntp-send-xover-command (beg end &optional wait-for-reply)
1712 "Send the XOVER command to the server."
1713 (let ((range (format "%d-%d" beg end))
1714 (nntp-inhibit-erase t))
1715 (if (stringp nntp-server-xover)
1716 ;; If `nntp-server-xover' is a string, then we just send this
1717 ;; command.
1718 (if wait-for-reply
1719 (nntp-send-command-nodelete
1720 "\r?\n\\.\r?\n" nntp-server-xover range)
1721 ;; We do not wait for the reply.
16409b0b 1722 (nntp-send-command-nodelete nil nntp-server-xover range))
eec82323
LMI
1723 (let ((commands nntp-xover-commands))
1724 ;; `nntp-xover-commands' is a list of possible XOVER commands.
1725 ;; We try them all until we get at positive response.
1726 (while (and commands (eq nntp-server-xover 'try))
1727 (nntp-send-command-nodelete "\r?\n\\.\r?\n" (car commands) range)
ed075cb4 1728 (with-current-buffer nntp-server-buffer
eec82323
LMI
1729 (goto-char (point-min))
1730 (and (looking-at "[23]") ; No error message.
1731 ;; We also have to look at the lines. Some buggy
1732 ;; servers give back simple lines with just the
1733 ;; article number. How... helpful.
1734 (progn
1735 (forward-line 1)
5cedca8d
MB
1736 ;; More text after number, or a dot.
1737 (looking-at "[0-9]+\t...\\|\\.\r?\n"))
eec82323
LMI
1738 (setq nntp-server-xover (car commands))))
1739 (setq commands (cdr commands)))
1740 ;; If none of the commands worked, we disable XOVER.
1741 (when (eq nntp-server-xover 'try)
01c52d31
MB
1742 (nntp-erase-buffer nntp-server-buffer)
1743 (setq nntp-server-xover nil))
23f87bed 1744 nntp-server-xover))))
eec82323 1745
23f87bed
MB
1746(defun nntp-find-group-and-number (&optional group)
1747 (save-excursion
1748 (save-restriction
ed075cb4 1749 ;; FIXME: This is REALLY FISHY: set-buffer after save-restriction?!?
23f87bed
MB
1750 (set-buffer nntp-server-buffer)
1751 (narrow-to-region (goto-char (point-min))
1752 (or (search-forward "\n\n" nil t) (point-max)))
1753 (goto-char (point-min))
1754 ;; We first find the number by looking at the status line.
1755 (let ((number (and (looking-at "2[0-9][0-9] +\\([0-9]+\\) ")
e9bd5782 1756 (string-to-number
23f87bed
MB
1757 (buffer-substring (match-beginning 1)
1758 (match-end 1)))))
1759 newsgroups xref)
1760 (and number (zerop number) (setq number nil))
1761 (if number
1762 ;; Then we find the group name.
1763 (setq group
1764 (cond
1765 ;; If there is only one group in the Newsgroups
1766 ;; header, then it seems quite likely that this
1767 ;; article comes from that group, I'd say.
1768 ((and (setq newsgroups
1769 (mail-fetch-field "newsgroups"))
1770 (not (string-match "," newsgroups)))
1771 newsgroups)
1772 ;; If there is more than one group in the
1773 ;; Newsgroups header, then the Xref header should
1774 ;; be filled out. We hazard a guess that the group
1775 ;; that has this article number in the Xref header
1776 ;; is the one we are looking for. This might very
1777 ;; well be wrong if this article happens to have
1778 ;; the same number in several groups, but that's
1779 ;; life.
1780 ((and (setq xref (mail-fetch-field "xref"))
1781 number
1782 (string-match
1783 (format "\\([^ :]+\\):%d" number) xref))
1784 (match-string 1 xref))
1785 (t "")))
1786 (cond
37cc095b
MB
1787 ((and (not nntp-xref-number-is-evil)
1788 (setq xref (mail-fetch-field "xref"))
23f87bed
MB
1789 (string-match
1790 (if group
1791 (concat "\\(" (regexp-quote group) "\\):\\([0-9]+\\)")
1792 "\\([^ :]+\\):\\([0-9]+\\)")
1793 xref))
1794 (setq group (match-string 1 xref)
e9bd5782 1795 number (string-to-number (match-string 2 xref))))
23f87bed
MB
1796 ((and (setq newsgroups
1797 (mail-fetch-field "newsgroups"))
1798 (not (string-match "," newsgroups)))
1799 (setq group newsgroups))
1800 (group)
1801 (t (setq group ""))))
1802 (when (string-match "\r" group)
1803 (setq group (substring group 0 (match-beginning 0))))
1804 (cons group number)))))
eec82323
LMI
1805
1806(defun nntp-wait-for-string (regexp)
1807 "Wait until string arrives in the buffer."
23f87bed
MB
1808 (let ((buf (current-buffer))
1809 proc)
eec82323 1810 (goto-char (point-min))
23f87bed
MB
1811 (while (and (setq proc (get-buffer-process buf))
1812 (memq (process-status proc) '(open run))
1813 (not (re-search-forward regexp nil t)))
d832b437 1814 (accept-process-output proc 0.1)
eec82323
LMI
1815 (set-buffer buf)
1816 (goto-char (point-min)))))
1817
23f87bed
MB
1818
1819;; ==========================================================================
1820;; Obsolete nntp-open-* connection methods -- drv
1821;; ==========================================================================
1822
1823(defvoo nntp-open-telnet-envuser nil
1824 "*If non-nil, telnet session (client and server both) will support the ENVIRON option and not prompt for login name.")
1825
1826(defvoo nntp-telnet-shell-prompt "bash\\|\$ *\r?$\\|> *\r?"
1827 "*Regular expression to match the shell prompt on the remote machine.")
1828
1829(defvoo nntp-rlogin-program "rsh"
1830 "*Program used to log in on remote machines.
1831The default is \"rsh\", but \"ssh\" is a popular alternative.")
1832
1833(defvoo nntp-rlogin-parameters '("telnet" "-8" "${NNTPSERVER:=news}" "nntp")
1834 "*Parameters to `nntp-open-rlogin'.
1835That function may be used as `nntp-open-connection-function'. In that
1836case, this list will be used as the parameter list given to rsh.")
1837
1838(defvoo nntp-rlogin-user-name nil
1839 "*User name on remote system when using the rlogin connect method.")
1840
1841(defvoo nntp-telnet-parameters
1842 '("exec" "telnet" "-8" "${NNTPSERVER:=news}" "nntp")
1843 "*Parameters to `nntp-open-telnet'.
1844That function may be used as `nntp-open-connection-function'. In that
1845case, this list will be executed as a command after logging in
1846via telnet.")
1847
1848(defvoo nntp-telnet-user-name nil
1849 "User name to log in via telnet with.")
1850
1851(defvoo nntp-telnet-passwd nil
1852 "Password to use to log in via telnet with.")
1853
990e2c2f
SM
1854(defun nntp-service-to-port (svc)
1855 (cond
1856 ((integerp svc) (number-to-string svc))
49b196a5 1857 ((string-match "\\`[0-9]+\\'" svc) svc)
990e2c2f
SM
1858 (t
1859 (with-temp-buffer
1860 (ignore-errors (insert-file-contents "/etc/services"))
1861 (goto-char (point-min))
1862 (if (re-search-forward (concat "^" (regexp-quote svc)
49b196a5 1863 "[ \t]+\\([0-9]+\\)/tcp"))
990e2c2f
SM
1864 (match-string 1)
1865 svc)))))
1866
eec82323 1867(defun nntp-open-telnet (buffer)
990e2c2f 1868 (with-current-buffer buffer
eec82323 1869 (erase-buffer)
a8151ef7
LMI
1870 (let ((proc (apply
1871 'start-process
1872 "nntpd" buffer nntp-telnet-command nntp-telnet-switches))
eec82323
LMI
1873 (case-fold-search t))
1874 (when (memq (process-status proc) '(open run))
2eebe218 1875 (nntp-wait-for-string "^r?telnet")
eec82323 1876 (process-send-string proc "set escape \^X\n")
6748645f
LMI
1877 (cond
1878 ((and nntp-open-telnet-envuser nntp-telnet-user-name)
1879 (process-send-string proc (concat "open " "-l" nntp-telnet-user-name
1880 nntp-address "\n")))
1881 (t
1882 (process-send-string proc (concat "open " nntp-address "\n"))))
1883 (cond
1884 ((not nntp-open-telnet-envuser)
1885 (nntp-wait-for-string "^\r*.?login:")
1886 (process-send-string
1887 proc (concat
1888 (or nntp-telnet-user-name
1889 (setq nntp-telnet-user-name (read-string "login: ")))
1890 "\n"))))
eec82323
LMI
1891 (nntp-wait-for-string "^\r*.?password:")
1892 (process-send-string
1893 proc (concat
1894 (or nntp-telnet-passwd
1895 (setq nntp-telnet-passwd
23f87bed 1896 (read-passwd "Password: ")))
eec82323 1897 "\n"))
6748645f 1898 (nntp-wait-for-string nntp-telnet-shell-prompt)
eec82323
LMI
1899 (process-send-string
1900 proc (concat (mapconcat 'identity nntp-telnet-parameters " ") "\n"))
6748645f 1901 (nntp-wait-for-string "^\r*20[01]")
eec82323
LMI
1902 (beginning-of-line)
1903 (delete-region (point-min) (point))
1904 (process-send-string proc "\^]")
2eebe218 1905 (nntp-wait-for-string "^r?telnet")
eec82323
LMI
1906 (process-send-string proc "mode character\n")
1907 (accept-process-output proc 1)
1908 (sit-for 1)
1909 (goto-char (point-min))
1910 (forward-line 1)
1911 (delete-region (point) (point-max)))
1912 proc)))
1913
1914(defun nntp-open-rlogin (buffer)
1915 "Open a connection to SERVER using rsh."
1916 (let ((proc (if nntp-rlogin-user-name
6748645f
LMI
1917 (apply 'start-process
1918 "nntpd" buffer nntp-rlogin-program
1919 nntp-address "-l" nntp-rlogin-user-name
1920 nntp-rlogin-parameters)
1921 (apply 'start-process
1922 "nntpd" buffer nntp-rlogin-program nntp-address
1923 nntp-rlogin-parameters))))
990e2c2f 1924 (with-current-buffer buffer
6748645f
LMI
1925 (nntp-wait-for-string "^\r*20[01]")
1926 (beginning-of-line)
1927 (delete-region (point-min) (point))
1928 proc)))
eec82323 1929
23f87bed
MB
1930
1931;; ==========================================================================
1932;; Replacements for the nntp-open-* functions -- drv
1933;; ==========================================================================
1934
1935(defun nntp-open-telnet-stream (buffer)
1936 "Open a nntp connection by telnet'ing the news server.
990e2c2f 1937`nntp-open-netcat-stream' is recommended in place of this function
ed075cb4 1938because it is more reliable.
23f87bed
MB
1939
1940Please refer to the following variables to customize the connection:
1941- `nntp-pre-command',
1942- `nntp-telnet-command',
1943- `nntp-telnet-switches',
1944- `nntp-address',
1945- `nntp-port-number',
1946- `nntp-end-of-line'."
1947 (let ((command `(,nntp-telnet-command
1948 ,@nntp-telnet-switches
9b3ebcb6 1949 ,nntp-address
990e2c2f 1950 ,(nntp-service-to-port nntp-port-number)))
23f87bed
MB
1951 proc)
1952 (and nntp-pre-command
1953 (push nntp-pre-command command))
1954 (setq proc (apply 'start-process "nntpd" buffer command))
ed075cb4 1955 (with-current-buffer buffer
23f87bed
MB
1956 (nntp-wait-for-string "^\r*20[01]")
1957 (beginning-of-line)
1958 (delete-region (point-min) (point))
1959 proc)))
1960
1961(defun nntp-open-via-rlogin-and-telnet (buffer)
1962 "Open a connection to an nntp server through an intermediate host.
1963First rlogin to the remote host, and then telnet the real news server
1964from there.
ed075cb4
SM
1965`nntp-open-via-rlogin-and-netcat' is recommended in place of this function
1966because it is more reliable.
23f87bed
MB
1967
1968Please refer to the following variables to customize the connection:
1969- `nntp-pre-command',
1970- `nntp-via-rlogin-command',
1971- `nntp-via-rlogin-command-switches',
1972- `nntp-via-user-name',
1973- `nntp-via-address',
1974- `nntp-telnet-command',
1975- `nntp-telnet-switches',
1976- `nntp-address',
1977- `nntp-port-number',
1978- `nntp-end-of-line'."
1979 (let ((command `(,nntp-via-address
1980 ,nntp-telnet-command
1981 ,@nntp-telnet-switches))
1982 proc)
1983 (when nntp-via-user-name
1984 (setq command `("-l" ,nntp-via-user-name ,@command)))
1985 (when nntp-via-rlogin-command-switches
1986 (setq command (append nntp-via-rlogin-command-switches command)))
1987 (push nntp-via-rlogin-command command)
1988 (and nntp-pre-command
1989 (push nntp-pre-command command))
1990 (setq proc (apply 'start-process "nntpd" buffer command))
ed075cb4 1991 (with-current-buffer buffer
23f87bed 1992 (nntp-wait-for-string "^r?telnet")
9b3ebcb6 1993 (process-send-string proc (concat "open " nntp-address " "
990e2c2f 1994 (nntp-service-to-port nntp-port-number)
9b3ebcb6 1995 "\n"))
23f87bed
MB
1996 (nntp-wait-for-string "^\r*20[01]")
1997 (beginning-of-line)
1998 (delete-region (point-min) (point))
1999 (process-send-string proc "\^]")
2000 (nntp-wait-for-string "^r?telnet")
2001 (process-send-string proc "mode character\n")
2002 (accept-process-output proc 1)
2003 (sit-for 1)
eec82323 2004 (goto-char (point-min))
23f87bed
MB
2005 (forward-line 1)
2006 (delete-region (point) (point-max)))
2007 proc))
2008
01c52d31
MB
2009(defun nntp-open-via-rlogin-and-netcat (buffer)
2010 "Open a connection to an nntp server through an intermediate host.
2011First rlogin to the remote host, and then connect to the real news
2012server from there using the netcat command.
2013
2014Please refer to the following variables to customize the connection:
2015- `nntp-pre-command',
2016- `nntp-via-rlogin-command',
2017- `nntp-via-rlogin-command-switches',
2018- `nntp-via-user-name',
2019- `nntp-via-address',
990e2c2f
SM
2020- `nntp-netcat-command',
2021- `nntp-netcat-switches',
01c52d31 2022- `nntp-address',
990e2c2f 2023- `nntp-port-number'."
01c52d31
MB
2024 (let ((command `(,@(when nntp-pre-command
2025 (list nntp-pre-command))
2026 ,nntp-via-rlogin-command
990e2c2f 2027 ,@nntp-via-rlogin-command-switches
01c52d31
MB
2028 ,@(when nntp-via-user-name
2029 (list "-l" nntp-via-user-name))
2030 ,nntp-via-address
990e2c2f
SM
2031 ,nntp-netcat-command
2032 ,@nntp-netcat-switches
01c52d31 2033 ,nntp-address
990e2c2f
SM
2034 ,(nntp-service-to-port nntp-port-number))))
2035 ;; A non-nil connection type results in mightily odd behavior where
2036 ;; (process-send-string proc "\^M") ends up sending a "\n" to the
2037 ;; ssh process. --Stef
2038 ;; Also a nil connection allow ssh-askpass to work under X11.
2039 (let ((process-connection-type nil))
2040 (apply 'start-process "nntpd" buffer command))))
2041
2042(defun nntp-open-netcat-stream (buffer)
2043 "Open a connection to an nntp server through netcat.
2044I.e. use the `nc' command rather than Emacs's builtin networking code.
2045
2046Please refer to the following variables to customize the connection:
2047- `nntp-pre-command',
2048- `nntp-netcat-command',
2049- `nntp-netcat-switches',
2050- `nntp-address',
2051- `nntp-port-number'."
2052 (let ((command `(,nntp-netcat-command
2053 ,@nntp-netcat-switches
2054 ,nntp-address
2055 ,(nntp-service-to-port nntp-port-number))))
2056 (and nntp-pre-command (push nntp-pre-command command))
2057 (let ((process-connection-type nil)) ;See `nntp-open-via-rlogin-and-netcat'.
2058 (apply 'start-process "nntpd" buffer command))))
c9fc72fa 2059
01c52d31 2060
23f87bed
MB
2061(defun nntp-open-via-telnet-and-telnet (buffer)
2062 "Open a connection to an nntp server through an intermediate host.
2063First telnet the remote host, and then telnet the real news server
2064from there.
2065
2066Please refer to the following variables to customize the connection:
2067- `nntp-pre-command',
2068- `nntp-via-telnet-command',
2069- `nntp-via-telnet-switches',
2070- `nntp-via-address',
2071- `nntp-via-envuser',
2072- `nntp-via-user-name',
2073- `nntp-via-user-password',
2074- `nntp-via-shell-prompt',
2075- `nntp-telnet-command',
2076- `nntp-telnet-switches',
2077- `nntp-address',
2078- `nntp-port-number',
2079- `nntp-end-of-line'."
ed075cb4 2080 (with-current-buffer buffer
23f87bed
MB
2081 (erase-buffer)
2082 (let ((command `(,nntp-via-telnet-command ,@nntp-via-telnet-switches))
2083 (case-fold-search t)
2084 proc)
2085 (and nntp-pre-command (push nntp-pre-command command))
2086 (setq proc (apply 'start-process "nntpd" buffer command))
2087 (when (memq (process-status proc) '(open run))
2088 (nntp-wait-for-string "^r?telnet")
2089 (process-send-string proc "set escape \^X\n")
2090 (cond
2091 ((and nntp-via-envuser nntp-via-user-name)
2092 (process-send-string proc (concat "open " "-l" nntp-via-user-name
2093 nntp-via-address "\n")))
2094 (t
2095 (process-send-string proc (concat "open " nntp-via-address
2096 "\n"))))
2097 (when (not nntp-via-envuser)
2098 (nntp-wait-for-string "^\r*.?login:")
2099 (process-send-string proc
2100 (concat
2101 (or nntp-via-user-name
2102 (setq nntp-via-user-name
2103 (read-string "login: ")))
2104 "\n")))
2105 (nntp-wait-for-string "^\r*.?password:")
2106 (process-send-string proc
2107 (concat
2108 (or nntp-via-user-password
2109 (setq nntp-via-user-password
2110 (read-passwd "Password: ")))
2111 "\n"))
2112 (nntp-wait-for-string nntp-via-shell-prompt)
2113 (let ((real-telnet-command `("exec"
2114 ,nntp-telnet-command
2115 ,@nntp-telnet-switches
2116 ,nntp-address
990e2c2f 2117 ,(nntp-service-to-port nntp-port-number))))
23f87bed
MB
2118 (process-send-string proc
2119 (concat (mapconcat 'identity
2120 real-telnet-command " ")
2121 "\n")))
2122 (nntp-wait-for-string "^\r*20[01]")
2123 (beginning-of-line)
2124 (delete-region (point-min) (point))
2125 (process-send-string proc "\^]")
2126 (nntp-wait-for-string "^r?telnet")
2127 (process-send-string proc "mode character\n")
2128 (accept-process-output proc 1)
2129 (sit-for 1)
2130 (goto-char (point-min))
2131 (forward-line 1)
2132 (delete-region (point) (point-max)))
2133 proc)))
eec82323 2134
01c52d31
MB
2135;; Marks handling
2136
2137(defun nntp-marks-directory (server)
2138 (expand-file-name server nntp-marks-directory))
2139
2140(defvar nntp-server-to-method-cache nil
2141 "Alist of servers and select methods.")
2142
2143(defun nntp-group-pathname (server group &optional file)
2144 "Return an absolute file name of FILE for GROUP on SERVER."
2145 (let ((method (cdr (assoc server nntp-server-to-method-cache))))
2146 (unless method
2147 (push (cons server (setq method (or (gnus-server-to-method server)
2148 (gnus-find-method-for-group group))))
2149 nntp-server-to-method-cache))
2150 (nnmail-group-pathname
2151 (mm-decode-coding-string group
2152 (inline (gnus-group-name-charset method group)))
2153 (nntp-marks-directory server)
2154 file)))
2155
2156(defun nntp-possibly-create-directory (group server)
2157 (let ((dir (nntp-group-pathname server group))
2158 (file-name-coding-system nnmail-pathname-coding-system))
2159 (unless (file-exists-p dir)
2160 (make-directory (directory-file-name dir) t)
2161 (nnheader-message 5 "Creating nntp marks directory %s" dir))))
2162
8abf1b22 2163(autoload 'time-less-p "time-date")
01c52d31
MB
2164
2165(defun nntp-marks-changed-p (group server)
2166 (let ((file (nntp-group-pathname server group nntp-marks-file-name))
2167 (file-name-coding-system nnmail-pathname-coding-system))
2168 (if (null (gnus-gethash file nntp-marks-modtime))
2169 t ;; never looked at marks file, assume it has changed
2170 (time-less-p (gnus-gethash file nntp-marks-modtime)
2171 (nth 5 (file-attributes file))))))
2172
2173(defun nntp-save-marks (group server)
2174 (let ((file-name-coding-system nnmail-pathname-coding-system)
2175 (file (nntp-group-pathname server group nntp-marks-file-name)))
2176 (condition-case err
2177 (progn
2178 (nntp-possibly-create-directory group server)
2179 (with-temp-file file
2180 (erase-buffer)
2181 (gnus-prin1 nntp-marks)
2182 (insert "\n"))
2183 (gnus-sethash file
2184 (nth 5 (file-attributes file))
2185 nntp-marks-modtime))
2186 (error (or (gnus-yes-or-no-p
2187 (format "Could not write to %s (%s). Continue? " file err))
2188 (error "Cannot write to %s (%s)" file err))))))
2189
2190(defun nntp-open-marks (group server)
2191 (let ((file (nntp-group-pathname server group nntp-marks-file-name))
2192 (file-name-coding-system nnmail-pathname-coding-system))
2193 (if (file-exists-p file)
2194 (condition-case err
2195 (with-temp-buffer
2196 (gnus-sethash file (nth 5 (file-attributes file))
2197 nntp-marks-modtime)
2198 (nnheader-insert-file-contents file)
2199 (setq nntp-marks (read (current-buffer)))
2200 (dolist (el gnus-article-unpropagated-mark-lists)
2201 (setq nntp-marks (gnus-remassoc el nntp-marks))))
2202 (error (or (gnus-yes-or-no-p
2203 (format "Error reading nntp marks file %s (%s). Continuing will use marks from .newsrc.eld. Continue? " file err))
2204 (error "Cannot read nntp marks file %s (%s)" file err))))
2205 ;; User didn't have a .marks file. Probably first time
2206 ;; user of the .marks stuff. Bootstrap it from .newsrc.eld.
2207 (let ((info (gnus-get-info
2208 (gnus-group-prefixed-name
2209 group
2210 (gnus-server-to-method (format "nntp:%s" server)))))
2211 (decoded-name (mm-decode-coding-string
2212 group
2213 (gnus-group-name-charset
2214 (gnus-server-to-method server) group))))
2215 (nnheader-message 7 "Bootstrapping marks for %s..." decoded-name)
2216 (setq nntp-marks (gnus-info-marks info))
2217 (push (cons 'read (gnus-info-read info)) nntp-marks)
2218 (dolist (el gnus-article-unpropagated-mark-lists)
2219 (setq nntp-marks (gnus-remassoc el nntp-marks)))
2220 (nntp-save-marks group server)
2221 (nnheader-message 7 "Bootstrapping marks for %s...done"
2222 decoded-name)))))
2223
eec82323
LMI
2224(provide 'nntp)
2225
2226;;; nntp.el ends here