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