]> code.delx.au - gnu-emacs/blob - lisp/gnus/nntp.el
*** empty log message ***
[gnu-emacs] / lisp / gnus / nntp.el
1 ;;; nntp.el --- nntp access for Gnus
2
3 ;; Copyright (C) 1987, 1988, 1989, 1990, 1992, 1993,
4 ;; 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002,
5 ;; 2003, 2004, 2005 Free Software Foundation, Inc.
6
7 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
8 ;; Keywords: news
9
10 ;; This file is part of GNU Emacs.
11
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published
14 ;; by the Free Software Foundation; either version 2, or (at your
15 ;; option) any later version.
16
17 ;; GNU Emacs is distributed in the hope that it will be useful, but
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ;; General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
25 ;; MA 02110-1301, USA.
26
27 ;;; Commentary:
28
29 ;;; Code:
30
31 (require 'nnheader)
32 (require 'nnoo)
33 (require 'gnus-util)
34
35 (nnoo-declare nntp)
36
37 (eval-when-compile (require 'cl))
38
39 (defgroup nntp nil
40 "NNTP access for Gnus."
41 :group 'gnus)
42
43 (defvoo nntp-address nil
44 "Address of the physical nntp server.")
45
46 (defvoo nntp-port-number "nntp"
47 "Port number on the physical nntp server.")
48
49 (defvoo nntp-server-opened-hook '(nntp-send-mode-reader)
50 "*Hook used for sending commands to the server at startup.
51 The default value is `nntp-send-mode-reader', which makes an innd
52 server spawn an nnrpd server.")
53
54 (defvoo nntp-authinfo-function 'nntp-send-authinfo
55 "Function used to send AUTHINFO to the server.
56 It is called with no parameters.")
57
58 (defvoo nntp-server-action-alist
59 '(("nntpd 1\\.5\\.11t"
60 (remove-hook 'nntp-server-opened-hook 'nntp-send-mode-reader))
61 ("NNRP server Netscape"
62 (setq nntp-server-list-active-group nil)))
63 "Alist of regexps to match on server types and actions to be taken.
64 For instance, if you want Gnus to beep every time you connect
65 to innd, you could say something like:
66
67 \(setq nntp-server-action-alist
68 '((\"innd\" (ding))))
69
70 You probably don't want to do that, though.")
71
72 (defvoo nntp-open-connection-function 'nntp-open-network-stream
73 "*Function used for connecting to a remote system.
74 It will be called with the buffer to output in as argument.
75
76 Currently, five such functions are provided (please refer to their
77 respective doc string for more information), three of them establishing
78 direct connections to the nntp server, and two of them using an indirect
79 host.
80
81 Direct connections:
82 - `nntp-open-network-stream' (the default),
83 - `nntp-open-ssl-stream',
84 - `nntp-open-tls-stream',
85 - `nntp-open-telnet-stream'.
86
87 Indirect connections:
88 - `nntp-open-via-rlogin-and-telnet',
89 - `nntp-open-via-telnet-and-telnet'.")
90
91 (defvoo nntp-pre-command nil
92 "*Pre-command to use with the various nntp-open-via-* methods.
93 This is where you would put \"runsocks\" or stuff like that.")
94
95 (defvoo nntp-telnet-command "telnet"
96 "*Telnet command used to connect to the nntp server.
97 This command is used by the various nntp-open-via-* methods.")
98
99 (defvoo nntp-telnet-switches '("-8")
100 "*Switches given to the telnet command `nntp-telnet-command'.")
101
102 (defvoo nntp-end-of-line "\r\n"
103 "*String to use on the end of lines when talking to the NNTP server.
104 This is \"\\r\\n\" by default, but should be \"\\n\" when
105 using and indirect connection method (nntp-open-via-*).")
106
107 (defvoo nntp-via-rlogin-command "rsh"
108 "*Rlogin command used to connect to an intermediate host.
109 This command is used by the `nntp-open-via-rlogin-and-telnet' method.
110 The default is \"rsh\", but \"ssh\" is a popular alternative.")
111
112 (defvoo nntp-via-rlogin-command-switches nil
113 "*Switches given to the rlogin command `nntp-via-rlogin-command'.
114 If you use \"ssh\" for `nntp-via-rlogin-command', you may set this to
115 \(\"-C\") in order to compress all data connections, otherwise set this
116 to \(\"-t\" \"-e\" \"none\") or (\"-C\" \"-t\" \"-e\" \"none\") if the telnet
117 command requires a pseudo-tty allocation on an intermediate host.")
118
119 (defvoo nntp-via-telnet-command "telnet"
120 "*Telnet command used to connect to an intermediate host.
121 This command is used by the `nntp-open-via-telnet-and-telnet' method.")
122
123 (defvoo nntp-via-telnet-switches '("-8")
124 "*Switches given to the telnet command `nntp-via-telnet-command'.")
125
126 (defvoo nntp-via-user-name nil
127 "*User name to log in on an intermediate host with.
128 This variable is used by the `nntp-open-via-telnet-and-telnet' method.")
129
130 (defvoo nntp-via-user-password nil
131 "*Password to use to log in on an intermediate host with.
132 This variable is used by the `nntp-open-via-telnet-and-telnet' method.")
133
134 (defvoo nntp-via-address nil
135 "*Address of an intermediate host to connect to.
136 This variable is used by the `nntp-open-via-rlogin-and-telnet' and
137 `nntp-open-via-telnet-and-telnet' methods.")
138
139 (defvoo nntp-via-envuser nil
140 "*Whether both telnet client and server support the ENVIRON option.
141 If non-nil, there will be no prompt for a login name.")
142
143 (defvoo nntp-via-shell-prompt "bash\\|\$ *\r?$\\|> *\r?"
144 "*Regular expression to match the shell prompt on an intermediate host.
145 This variable is used by the `nntp-open-via-telnet-and-telnet' method.")
146
147 (defvoo nntp-large-newsgroup 50
148 "*The number of articles which indicates a large newsgroup.
149 If the number of articles is greater than the value, verbose
150 messages will be shown to indicate the current status.")
151
152 (defvoo nntp-maximum-request 400
153 "*The maximum number of the requests sent to the NNTP server at one time.
154 If Emacs hangs up while retrieving headers, set the variable to a
155 lower value.")
156
157 (defvoo nntp-nov-is-evil nil
158 "*If non-nil, nntp will never attempt to use XOVER when talking to the server.")
159
160 (defvoo nntp-xover-commands '("XOVER" "XOVERVIEW")
161 "*List of strings that are used as commands to fetch NOV lines from a server.
162 The strings are tried in turn until a positive response is gotten. If
163 none of the commands are successful, nntp will just grab headers one
164 by one.")
165
166 (defvoo nntp-nov-gap 5
167 "*Maximum allowed gap between two articles.
168 If the gap between two consecutive articles is bigger than this
169 variable, split the XOVER request into two requests.")
170
171 (defvoo nntp-prepare-server-hook nil
172 "*Hook run before a server is opened.
173 If can be used to set up a server remotely, for instance. Say you
174 have an account at the machine \"other.machine\". This machine has
175 access to an NNTP server that you can't access locally. You could
176 then use this hook to rsh to the remote machine and start a proxy NNTP
177 server there that you can connect to. See also
178 `nntp-open-connection-function'")
179
180 (defvoo nntp-coding-system-for-read 'binary
181 "*Coding system to read from NNTP.")
182
183 (defvoo nntp-coding-system-for-write 'binary
184 "*Coding system to write to NNTP.")
185
186 (defcustom nntp-authinfo-file "~/.authinfo"
187 ".netrc-like file that holds nntp authinfo passwords."
188 :group 'nntp
189 :type
190 '(choice file
191 (repeat :tag "Entries"
192 :menu-tag "Inline"
193 (list :format "%v"
194 :value ("" ("login" . "") ("password" . ""))
195 (string :tag "Host")
196 (checklist :inline t
197 (cons :format "%v"
198 (const :format "" "login")
199 (string :format "Login: %v"))
200 (cons :format "%v"
201 (const :format "" "password")
202 (string :format "Password: %v")))))))
203
204 \f
205
206 (defvoo nntp-connection-timeout nil
207 "*Number of seconds to wait before an nntp connection times out.
208 If this variable is nil, which is the default, no timers are set.
209 NOTE: This variable is never seen to work in Emacs 20 and XEmacs 21.")
210
211 (defvoo nntp-prepare-post-hook nil
212 "*Hook run just before posting an article. It is supposed to be used
213 to insert Cancel-Lock headers.")
214
215 ;;; Internal variables.
216
217 (defvar nntp-record-commands nil
218 "*If non-nil, nntp will record all commands in the \"*nntp-log*\" buffer.")
219
220 (defvar nntp-have-messaged nil)
221
222 (defvar nntp-process-wait-for nil)
223 (defvar nntp-process-to-buffer nil)
224 (defvar nntp-process-callback nil)
225 (defvar nntp-process-decode nil)
226 (defvar nntp-process-start-point nil)
227 (defvar nntp-inside-change-function nil)
228 (defvoo nntp-last-command-time nil)
229 (defvoo nntp-last-command nil)
230 (defvoo nntp-authinfo-password nil)
231 (defvoo nntp-authinfo-user nil)
232
233 (defvar nntp-connection-list nil)
234
235 (defvoo nntp-server-type nil)
236 (defvoo nntp-connection-alist nil)
237 (defvoo nntp-status-string "")
238 (defconst nntp-version "nntp 5.0")
239 (defvoo nntp-inhibit-erase nil)
240 (defvoo nntp-inhibit-output nil)
241
242 (defvoo nntp-server-xover 'try)
243 (defvoo nntp-server-list-active-group 'try)
244
245 (defvar nntp-async-needs-kluge
246 (string-match "^GNU Emacs 20\\.3\\." (emacs-version))
247 "*When non-nil, nntp will poll asynchronous connections
248 once a second. By default, this is turned on only for Emacs
249 20.3, which has a bug that breaks nntp's normal method of
250 noticing asynchronous data.")
251
252 (defvar nntp-async-timer nil)
253 (defvar nntp-async-process-list nil)
254
255 (defvar nntp-ssl-program
256 "openssl s_client -quiet -ssl3 -connect %s:%p"
257 "A string containing commands for SSL connections.
258 Within a string, %s is replaced with the server address and %p with
259 port number on server. The program should accept IMAP commands on
260 stdin and return responses to stdout.")
261
262 \f
263
264 ;;; Internal functions.
265
266 (defsubst nntp-send-string (process string)
267 "Send STRING to PROCESS."
268 ;; We need to store the time to provide timeouts, and
269 ;; to store the command so the we can replay the command
270 ;; if the server gives us an AUTHINFO challenge.
271 (setq nntp-last-command-time (current-time)
272 nntp-last-command string)
273 (when nntp-record-commands
274 (nntp-record-command string))
275 (process-send-string process (concat string nntp-end-of-line))
276 (or (memq (process-status process) '(open run))
277 (nntp-report "Server closed connection")))
278
279 (defun nntp-record-command (string)
280 "Record the command STRING."
281 (save-excursion
282 (set-buffer (get-buffer-create "*nntp-log*"))
283 (goto-char (point-max))
284 (let ((time (current-time)))
285 (insert (format-time-string "%Y%m%dT%H%M%S" time)
286 "." (format "%03d" (/ (nth 2 time) 1000))
287 " " nntp-address " " string "\n"))))
288
289 (defun nntp-report (&rest args)
290 "Report an error from the nntp backend. The first string in ARGS
291 can be a format string. For some commands, the failed command may be
292 retried once before actually displaying the error report."
293
294 (when nntp-record-commands
295 (nntp-record-command "*** CALLED nntp-report ***"))
296
297 (nnheader-report 'nntp args)
298
299 (apply 'error args))
300
301 (defun nntp-report-1 (&rest args)
302 "Throws out to nntp-with-open-group-error so that the connection may
303 be restored and the command retried."
304
305 (when nntp-record-commands
306 (nntp-record-command "*** CONNECTION LOST ***"))
307
308 (throw 'nntp-with-open-group-error t))
309
310 (defsubst nntp-wait-for (process wait-for buffer &optional decode discard)
311 "Wait for WAIT-FOR to arrive from PROCESS."
312 (save-excursion
313 (set-buffer (process-buffer process))
314 (goto-char (point-min))
315 (while (and (or (not (memq (char-after (point)) '(?2 ?3 ?4 ?5)))
316 (looking-at "480"))
317 (memq (process-status process) '(open run)))
318 (when (looking-at "480")
319 (nntp-handle-authinfo process))
320 (when (looking-at "^.*\n")
321 (delete-region (point) (progn (forward-line 1) (point))))
322 (nntp-accept-process-output process)
323 (goto-char (point-min)))
324 (prog1
325 (cond
326 ((looking-at "[45]")
327 (progn
328 (nntp-snarf-error-message)
329 nil))
330 ((not (memq (process-status process) '(open run)))
331 (nntp-report "Server closed connection"))
332 (t
333 (goto-char (point-max))
334 (let ((limit (point-min))
335 response)
336 (while (not (re-search-backward wait-for limit t))
337 (nntp-accept-process-output process)
338 ;; We assume that whatever we wait for is less than 1000
339 ;; characters long.
340 (setq limit (max (- (point-max) 1000) (point-min)))
341 (goto-char (point-max)))
342 (setq response (match-string 0))
343 (with-current-buffer nntp-server-buffer
344 (setq nntp-process-response response)))
345 (nntp-decode-text (not decode))
346 (unless discard
347 (save-excursion
348 (set-buffer buffer)
349 (goto-char (point-max))
350 (insert-buffer-substring (process-buffer process))
351 ;; Nix out "nntp reading...." message.
352 (when nntp-have-messaged
353 (setq nntp-have-messaged nil)
354 (nnheader-message 5 ""))))
355 t))
356 (unless discard
357 (erase-buffer)))))
358
359 (defun nntp-kill-buffer (buffer)
360 (when (buffer-name buffer)
361 (kill-buffer buffer)
362 (nnheader-init-server-buffer)))
363
364 (defsubst nntp-find-connection (buffer)
365 "Find the connection delivering to BUFFER."
366 (let ((alist nntp-connection-alist)
367 (buffer (if (stringp buffer) (get-buffer buffer) buffer))
368 process entry)
369 (while (and alist (setq entry (pop alist)))
370 (when (eq buffer (cadr entry))
371 (setq process (car entry)
372 alist nil)))
373 (when process
374 (if (memq (process-status process) '(open run))
375 process
376 (nntp-kill-buffer (process-buffer process))
377 (setq nntp-connection-alist (delq entry nntp-connection-alist))
378 nil))))
379
380 (defsubst nntp-find-connection-entry (buffer)
381 "Return the entry for the connection to BUFFER."
382 (assq (nntp-find-connection buffer) nntp-connection-alist))
383
384 (defun nntp-find-connection-buffer (buffer)
385 "Return the process connection buffer tied to BUFFER."
386 (let ((process (nntp-find-connection buffer)))
387 (when process
388 (process-buffer process))))
389
390 (defsubst nntp-retrieve-data (command address port buffer
391 &optional wait-for callback decode)
392 "Use COMMAND to retrieve data into BUFFER from PORT on ADDRESS."
393 (let ((process (or (nntp-find-connection buffer)
394 (nntp-open-connection buffer))))
395 (if process
396 (progn
397 (unless (or nntp-inhibit-erase nnheader-callback-function)
398 (save-excursion
399 (set-buffer (process-buffer process))
400 (erase-buffer)))
401 (condition-case err
402 (progn
403 (when command
404 (nntp-send-string process command))
405 (cond
406 ((eq callback 'ignore)
407 t)
408 ((and callback wait-for)
409 (nntp-async-wait process wait-for buffer decode callback)
410 t)
411 (wait-for
412 (nntp-wait-for process wait-for buffer decode))
413 (t t)))
414 (error
415 (nnheader-report 'nntp "Couldn't open connection to %s: %s"
416 address err))
417 (quit
418 (message "Quit retrieving data from nntp")
419 (signal 'quit nil)
420 nil)))
421 (nnheader-report 'nntp "Couldn't open connection to %s" address))))
422
423 (defsubst nntp-send-command (wait-for &rest strings)
424 "Send STRINGS to server and wait until WAIT-FOR returns."
425 (when (and (not nnheader-callback-function)
426 (not nntp-inhibit-output))
427 (save-excursion
428 (set-buffer nntp-server-buffer)
429 (erase-buffer)))
430 (let* ((command (mapconcat 'identity strings " "))
431 (process (nntp-find-connection nntp-server-buffer))
432 (buffer (and process (process-buffer process)))
433 (pos (and buffer (with-current-buffer buffer (point)))))
434 (if process
435 (prog1
436 (nntp-retrieve-data command
437 nntp-address nntp-port-number
438 nntp-server-buffer
439 wait-for nnheader-callback-function)
440 ;; If nothing to wait for, still remove possibly echo'ed commands.
441 ;; We don't have echos if nntp-open-connection-function
442 ;; is `nntp-open-network-stream', so we skip this in that case.
443 (unless (or wait-for
444 (equal nntp-open-connection-function
445 'nntp-open-network-stream))
446 (nntp-accept-response)
447 (save-excursion
448 (set-buffer buffer)
449 (goto-char pos)
450 (if (looking-at (regexp-quote command))
451 (delete-region pos (progn (forward-line 1)
452 (gnus-point-at-bol))))
453 )))
454 (nnheader-report 'nntp "Couldn't open connection to %s."
455 nntp-address))))
456
457 (defun nntp-send-command-nodelete (wait-for &rest strings)
458 "Send STRINGS to server and wait until WAIT-FOR returns."
459 (let* ((command (mapconcat 'identity strings " "))
460 (process (nntp-find-connection nntp-server-buffer))
461 (buffer (and process (process-buffer process)))
462 (pos (and buffer (with-current-buffer buffer (point)))))
463 (if process
464 (prog1
465 (nntp-retrieve-data command
466 nntp-address nntp-port-number
467 nntp-server-buffer
468 wait-for nnheader-callback-function)
469 ;; If nothing to wait for, still remove possibly echo'ed commands
470 (unless wait-for
471 (nntp-accept-response)
472 (save-excursion
473 (set-buffer buffer)
474 (goto-char pos)
475 (if (looking-at (regexp-quote command))
476 (delete-region pos (progn (forward-line 1)
477 (gnus-point-at-bol)))))))
478 (nnheader-report 'nntp "Couldn't open connection to %s."
479 nntp-address))))
480
481 (defun nntp-send-command-and-decode (wait-for &rest strings)
482 "Send STRINGS to server and wait until WAIT-FOR returns."
483 (when (and (not nnheader-callback-function)
484 (not nntp-inhibit-output))
485 (save-excursion
486 (set-buffer nntp-server-buffer)
487 (erase-buffer)))
488 (let* ((command (mapconcat 'identity strings " "))
489 (process (nntp-find-connection nntp-server-buffer))
490 (buffer (and process (process-buffer process)))
491 (pos (and buffer (with-current-buffer buffer (point)))))
492 (if process
493 (prog1
494 (nntp-retrieve-data command
495 nntp-address nntp-port-number
496 nntp-server-buffer
497 wait-for nnheader-callback-function t)
498 ;; If nothing to wait for, still remove possibly echo'ed commands
499 (unless wait-for
500 (nntp-accept-response)
501 (save-excursion
502 (set-buffer buffer)
503 (goto-char pos)
504 (if (looking-at (regexp-quote command))
505 (delete-region pos (progn (forward-line 1) (gnus-point-at-bol))))
506 )))
507 (nnheader-report 'nntp "Couldn't open connection to %s."
508 nntp-address))))
509
510
511 (defun nntp-send-buffer (wait-for)
512 "Send the current buffer to server and wait until WAIT-FOR returns."
513 (when (and (not nnheader-callback-function)
514 (not nntp-inhibit-output))
515 (save-excursion
516 (set-buffer (nntp-find-connection-buffer nntp-server-buffer))
517 (erase-buffer)))
518 (nntp-encode-text)
519 (mm-with-unibyte-current-buffer
520 ;; Some encoded unicode text contains character 0x80-0x9f e.g. Euro.
521 (process-send-region (nntp-find-connection nntp-server-buffer)
522 (point-min) (point-max)))
523 (nntp-retrieve-data
524 nil nntp-address nntp-port-number nntp-server-buffer
525 wait-for nnheader-callback-function))
526
527 \f
528
529 ;;; Interface functions.
530
531 (nnoo-define-basics nntp)
532
533 (defsubst nntp-next-result-arrived-p ()
534 (cond
535 ;; A result that starts with a 2xx code is terminated by
536 ;; a line with only a "." on it.
537 ((eq (char-after) ?2)
538 (if (re-search-forward "\n\\.\r?\n" nil t)
539 t
540 nil))
541 ;; A result that starts with a 3xx or 4xx code is terminated
542 ;; by a newline.
543 ((looking-at "[34]")
544 (if (search-forward "\n" nil t)
545 t
546 nil))
547 ;; No result here.
548 (t
549 nil)))
550
551 (eval-when-compile
552 (defvar nntp-with-open-group-internal nil)
553 (defvar nntp-report-n nil))
554
555 (defmacro nntp-with-open-group (group server &optional connectionless &rest forms)
556 "Protect against servers that don't like clients that keep idle connections opens.
557 The problem being that these servers may either close a connection or
558 simply ignore any further requests on a connection. Closed
559 connections are not detected until accept-process-output has updated
560 the process-status. Dropped connections are not detected until the
561 connection timeouts (which may be several minutes) or
562 nntp-connection-timeout has expired. When these occur
563 nntp-with-open-group, opens a new connection then re-issues the NNTP
564 command whose response triggered the error."
565 (when (and (listp connectionless)
566 (not (eq connectionless nil)))
567 (setq forms (cons connectionless forms)
568 connectionless nil))
569 `(letf ((nntp-report-n (symbol-function 'nntp-report))
570 ((symbol-function 'nntp-report) (symbol-function 'nntp-report-1))
571 (nntp-with-open-group-internal nil))
572 (while (catch 'nntp-with-open-group-error
573 ;; Open the connection to the server
574 ;; NOTE: Existing connections are NOT tested.
575 (nntp-possibly-change-group ,group ,server ,connectionless)
576
577 (let ((timer
578 (and nntp-connection-timeout
579 (nnheader-run-at-time
580 nntp-connection-timeout nil
581 '(lambda ()
582 (let ((process (nntp-find-connection
583 nntp-server-buffer))
584 (buffer (and process
585 (process-buffer process))))
586 ;; When I an able to identify the
587 ;; connection to the server AND I've
588 ;; received NO reponse for
589 ;; nntp-connection-timeout seconds.
590 (when (and buffer (eq 0 (buffer-size buffer)))
591 ;; Close the connection. Take no
592 ;; other action as the accept input
593 ;; code will handle the closed
594 ;; connection.
595 (nntp-kill-buffer buffer))))))))
596 (unwind-protect
597 (setq nntp-with-open-group-internal
598 (condition-case nil
599 (progn ,@forms)
600 (quit
601 (nntp-close-server)
602 (signal 'quit nil))))
603 (when timer
604 (nnheader-cancel-timer timer)))
605 nil))
606 (setf (symbol-function 'nntp-report) nntp-report-n))
607 nntp-with-open-group-internal))
608
609 (deffoo nntp-retrieve-headers (articles &optional group server fetch-old)
610 "Retrieve the headers of ARTICLES."
611 (nntp-with-open-group
612 group server
613 (save-excursion
614 (set-buffer (nntp-find-connection-buffer nntp-server-buffer))
615 (erase-buffer)
616 (if (and (not gnus-nov-is-evil)
617 (not nntp-nov-is-evil)
618 (nntp-retrieve-headers-with-xover articles fetch-old))
619 ;; We successfully retrieved the headers via XOVER.
620 'nov
621 ;; XOVER didn't work, so we do it the hard, slow and inefficient
622 ;; way.
623 (let ((number (length articles))
624 (articles articles)
625 (count 0)
626 (received 0)
627 (last-point (point-min))
628 (buf (nntp-find-connection-buffer nntp-server-buffer))
629 (nntp-inhibit-erase t)
630 article)
631 ;; Send HEAD commands.
632 (while (setq article (pop articles))
633 (nntp-send-command
634 nil
635 "HEAD" (if (numberp article)
636 (int-to-string article)
637 ;; `articles' is either a list of article numbers
638 ;; or a list of article IDs.
639 article))
640 (incf count)
641 ;; Every 400 requests we have to read the stream in
642 ;; order to avoid deadlocks.
643 (when (or (null articles) ;All requests have been sent.
644 (zerop (% count nntp-maximum-request)))
645 (nntp-accept-response)
646 (while (progn
647 (set-buffer buf)
648 (goto-char last-point)
649 ;; Count replies.
650 (while (nntp-next-result-arrived-p)
651 (setq last-point (point))
652 (incf received))
653 (< received count))
654 ;; If number of headers is greater than 100, give
655 ;; informative messages.
656 (and (numberp nntp-large-newsgroup)
657 (> number nntp-large-newsgroup)
658 (zerop (% received 20))
659 (nnheader-message 6 "NNTP: Receiving headers... %d%%"
660 (/ (* received 100) number)))
661 (nntp-accept-response))))
662 (and (numberp nntp-large-newsgroup)
663 (> number nntp-large-newsgroup)
664 (nnheader-message 6 "NNTP: Receiving headers...done"))
665
666 ;; Now all of replies are received. Fold continuation lines.
667 (nnheader-fold-continuation-lines)
668 ;; Remove all "\r"'s.
669 (nnheader-strip-cr)
670 (copy-to-buffer nntp-server-buffer (point-min) (point-max))
671 'headers)))))
672
673 (deffoo nntp-retrieve-groups (groups &optional server)
674 "Retrieve group info on GROUPS."
675 (nntp-with-open-group
676 nil server
677 (when (nntp-find-connection-buffer nntp-server-buffer)
678 (catch 'done
679 (save-excursion
680 ;; Erase nntp-server-buffer before nntp-inhibit-erase.
681 (set-buffer nntp-server-buffer)
682 (erase-buffer)
683 (set-buffer (nntp-find-connection-buffer nntp-server-buffer))
684 ;; The first time this is run, this variable is `try'. So we
685 ;; try.
686 (when (eq nntp-server-list-active-group 'try)
687 (nntp-try-list-active (car groups)))
688 (erase-buffer)
689 (let ((count 0)
690 (groups groups)
691 (received 0)
692 (last-point (point-min))
693 (nntp-inhibit-erase t)
694 (buf (nntp-find-connection-buffer nntp-server-buffer))
695 (command (if nntp-server-list-active-group
696 "LIST ACTIVE" "GROUP")))
697 (while groups
698 ;; Timeout may have killed the buffer.
699 (unless (gnus-buffer-live-p buf)
700 (nnheader-report 'nntp "Connection to %s is closed." server)
701 (throw 'done nil))
702 ;; Send the command to the server.
703 (nntp-send-command nil command (pop groups))
704 (incf count)
705 ;; Every 400 requests we have to read the stream in
706 ;; order to avoid deadlocks.
707 (when (or (null groups) ;All requests have been sent.
708 (zerop (% count nntp-maximum-request)))
709 (nntp-accept-response)
710 (while (and (gnus-buffer-live-p buf)
711 (progn
712 ;; Search `blue moon' in this file for the
713 ;; reason why set-buffer here.
714 (set-buffer buf)
715 (goto-char last-point)
716 ;; Count replies.
717 (while (re-search-forward "^[0-9]" nil t)
718 (incf received))
719 (setq last-point (point))
720 (< received count)))
721 (nntp-accept-response))))
722
723 ;; Wait for the reply from the final command.
724 (unless (gnus-buffer-live-p buf)
725 (nnheader-report 'nntp "Connection to %s is closed." server)
726 (throw 'done nil))
727 (set-buffer buf)
728 (goto-char (point-max))
729 (re-search-backward "^[0-9]" nil t)
730 (when (looking-at "^[23]")
731 (while (and (gnus-buffer-live-p buf)
732 (progn
733 (set-buffer buf)
734 (goto-char (point-max))
735 (if (not nntp-server-list-active-group)
736 (not (re-search-backward "\r?\n"
737 (- (point) 3) t))
738 (not (re-search-backward "^\\.\r?\n"
739 (- (point) 4) t)))))
740 (nntp-accept-response)))
741
742 ;; Now all replies are received. We remove CRs.
743 (unless (gnus-buffer-live-p buf)
744 (nnheader-report 'nntp "Connection to %s is closed." server)
745 (throw 'done nil))
746 (set-buffer buf)
747 (goto-char (point-min))
748 (while (search-forward "\r" nil t)
749 (replace-match "" t t))
750
751 (if (not nntp-server-list-active-group)
752 (progn
753 (copy-to-buffer nntp-server-buffer (point-min) (point-max))
754 'group)
755 ;; We have read active entries, so we just delete the
756 ;; superfluous gunk.
757 (goto-char (point-min))
758 (while (re-search-forward "^[.2-5]" nil t)
759 (delete-region (match-beginning 0)
760 (progn (forward-line 1) (point))))
761 (copy-to-buffer nntp-server-buffer (point-min) (point-max))
762 'active)))))))
763
764 (deffoo nntp-retrieve-articles (articles &optional group server)
765 (nntp-with-open-group
766 group server
767 (save-excursion
768 (let ((number (length articles))
769 (articles articles)
770 (count 0)
771 (received 0)
772 (last-point (point-min))
773 (buf (nntp-find-connection-buffer nntp-server-buffer))
774 (nntp-inhibit-erase t)
775 (map (apply 'vector articles))
776 (point 1)
777 article)
778 (set-buffer buf)
779 (erase-buffer)
780 ;; Send ARTICLE command.
781 (while (setq article (pop articles))
782 (nntp-send-command
783 nil
784 "ARTICLE" (if (numberp article)
785 (int-to-string article)
786 ;; `articles' is either a list of article numbers
787 ;; or a list of article IDs.
788 article))
789 (incf count)
790 ;; Every 400 requests we have to read the stream in
791 ;; order to avoid deadlocks.
792 (when (or (null articles) ;All requests have been sent.
793 (zerop (% count nntp-maximum-request)))
794 (nntp-accept-response)
795 (while (progn
796 (set-buffer buf)
797 (goto-char last-point)
798 ;; Count replies.
799 (while (nntp-next-result-arrived-p)
800 (aset map received (cons (aref map received) (point)))
801 (setq last-point (point))
802 (incf received))
803 (< received count))
804 ;; If number of headers is greater than 100, give
805 ;; informative messages.
806 (and (numberp nntp-large-newsgroup)
807 (> number nntp-large-newsgroup)
808 (zerop (% received 20))
809 (nnheader-message 6 "NNTP: Receiving articles... %d%%"
810 (/ (* received 100) number)))
811 (nntp-accept-response))))
812 (and (numberp nntp-large-newsgroup)
813 (> number nntp-large-newsgroup)
814 (nnheader-message 6 "NNTP: Receiving articles...done"))
815
816 ;; Now we have all the responses. We go through the results,
817 ;; wash it and copy it over to the server buffer.
818 (set-buffer nntp-server-buffer)
819 (erase-buffer)
820 (setq last-point (point-min))
821 (mapcar
822 (lambda (entry)
823 (narrow-to-region
824 (setq point (goto-char (point-max)))
825 (progn
826 (insert-buffer-substring buf last-point (cdr entry))
827 (point-max)))
828 (setq last-point (cdr entry))
829 (nntp-decode-text)
830 (widen)
831 (cons (car entry) point))
832 map)))))
833
834 (defun nntp-try-list-active (group)
835 (nntp-list-active-group group)
836 (save-excursion
837 (set-buffer nntp-server-buffer)
838 (goto-char (point-min))
839 (cond ((or (eobp)
840 (looking-at "5[0-9]+"))
841 (setq nntp-server-list-active-group nil))
842 (t
843 (setq nntp-server-list-active-group t)))))
844
845 (deffoo nntp-list-active-group (group &optional server)
846 "Return the active info on GROUP (which can be a regexp)."
847 (nntp-with-open-group
848 nil server
849 (nntp-send-command "^\\.*\r?\n" "LIST ACTIVE" group)))
850
851 (deffoo nntp-request-group-articles (group &optional server)
852 "Return the list of existing articles in GROUP."
853 (nntp-with-open-group
854 nil server
855 (nntp-send-command "^\\.*\r?\n" "LISTGROUP" group)))
856
857 (deffoo nntp-request-article (article &optional group server buffer command)
858 (nntp-with-open-group
859 group server
860 (when (nntp-send-command-and-decode
861 "\r?\n\\.\r?\n" "ARTICLE"
862 (if (numberp article) (int-to-string article) article))
863 (if (and buffer
864 (not (equal buffer nntp-server-buffer)))
865 (save-excursion
866 (set-buffer nntp-server-buffer)
867 (copy-to-buffer buffer (point-min) (point-max))
868 (nntp-find-group-and-number group))
869 (nntp-find-group-and-number group)))))
870
871 (deffoo nntp-request-head (article &optional group server)
872 (nntp-with-open-group
873 group server
874 (when (nntp-send-command
875 "\r?\n\\.\r?\n" "HEAD"
876 (if (numberp article) (int-to-string article) article))
877 (prog1
878 (nntp-find-group-and-number group)
879 (nntp-decode-text)))))
880
881 (deffoo nntp-request-body (article &optional group server)
882 (nntp-with-open-group
883 group server
884 (nntp-send-command-and-decode
885 "\r?\n\\.\r?\n" "BODY"
886 (if (numberp article) (int-to-string article) article))))
887
888 (deffoo nntp-request-group (group &optional server dont-check)
889 (nntp-with-open-group
890 nil server
891 (when (nntp-send-command "^[245].*\n" "GROUP" group)
892 (let ((entry (nntp-find-connection-entry nntp-server-buffer)))
893 (setcar (cddr entry) group)))))
894
895 (deffoo nntp-close-group (group &optional server)
896 t)
897
898 (deffoo nntp-server-opened (&optional server)
899 "Say whether a connection to SERVER has been opened."
900 (and (nnoo-current-server-p 'nntp server)
901 nntp-server-buffer
902 (gnus-buffer-live-p nntp-server-buffer)
903 (nntp-find-connection nntp-server-buffer)))
904
905 (deffoo nntp-open-server (server &optional defs connectionless)
906 (nnheader-init-server-buffer)
907 (if (nntp-server-opened server)
908 t
909 (when (or (stringp (car defs))
910 (numberp (car defs)))
911 (setq defs (cons (list 'nntp-port-number (car defs)) (cdr defs))))
912 (unless (assq 'nntp-address defs)
913 (setq defs (append defs (list (list 'nntp-address server)))))
914 (nnoo-change-server 'nntp server defs)
915 (unless connectionless
916 (or (nntp-find-connection nntp-server-buffer)
917 (nntp-open-connection nntp-server-buffer)))))
918
919 (deffoo nntp-close-server (&optional server)
920 (nntp-possibly-change-group nil server t)
921 (let ((process (nntp-find-connection nntp-server-buffer)))
922 (while process
923 (when (memq (process-status process) '(open run))
924 (ignore-errors
925 (nntp-send-string process "QUIT")
926 (unless (eq nntp-open-connection-function 'nntp-open-network-stream)
927 ;; Ok, this is evil, but when using telnet and stuff
928 ;; as the connection method, it's important that the
929 ;; QUIT command actually is sent out before we kill
930 ;; the process.
931 (sleep-for 1))))
932 (nntp-kill-buffer (process-buffer process))
933 (setq process (car (pop nntp-connection-alist))))
934 (nnoo-close-server 'nntp)))
935
936 (deffoo nntp-request-close ()
937 (let (process)
938 (while (setq process (pop nntp-connection-list))
939 (when (memq (process-status process) '(open run))
940 (ignore-errors
941 (nntp-send-string process "QUIT")
942 (unless (eq nntp-open-connection-function 'nntp-open-network-stream)
943 ;; Ok, this is evil, but when using telnet and stuff
944 ;; as the connection method, it's important that the
945 ;; QUIT command actually is sent out before we kill
946 ;; the process.
947 (sleep-for 1))))
948 (nntp-kill-buffer (process-buffer process)))))
949
950 (deffoo nntp-request-list (&optional server)
951 (nntp-with-open-group
952 nil server
953 (nntp-send-command-and-decode "\r?\n\\.\r?\n" "LIST")))
954
955 (deffoo nntp-request-list-newsgroups (&optional server)
956 (nntp-with-open-group
957 nil server
958 (nntp-send-command "\r?\n\\.\r?\n" "LIST NEWSGROUPS")))
959
960 (deffoo nntp-request-newgroups (date &optional server)
961 (nntp-with-open-group
962 nil server
963 (save-excursion
964 (set-buffer nntp-server-buffer)
965 (let* ((time (date-to-time date))
966 (ls (- (cadr time) (nth 8 (decode-time time)))))
967 (cond ((< ls 0)
968 (setcar time (1- (car time)))
969 (setcar (cdr time) (+ ls 65536)))
970 ((>= ls 65536)
971 (setcar time (1+ (car time)))
972 (setcar (cdr time) (- ls 65536)))
973 (t
974 (setcar (cdr time) ls)))
975 (prog1
976 (nntp-send-command
977 "^\\.\r?\n" "NEWGROUPS"
978 (format-time-string "%y%m%d %H%M%S" time)
979 "GMT")
980 (nntp-decode-text))))))
981
982 (deffoo nntp-request-post (&optional server)
983 (nntp-with-open-group
984 nil server
985 (when (nntp-send-command "^[23].*\r?\n" "POST")
986 (let ((response (with-current-buffer nntp-server-buffer
987 nntp-process-response))
988 server-id)
989 (when (and response
990 (string-match "^[23].*\\(<[^\t\n @<>]+@[^\t\n @<>]+>\\)"
991 response))
992 (setq server-id (match-string 1 response))
993 (narrow-to-region (goto-char (point-min))
994 (if (search-forward "\n\n" nil t)
995 (1- (point))
996 (point-max)))
997 (unless (mail-fetch-field "Message-ID")
998 (goto-char (point-min))
999 (insert "Message-ID: " server-id "\n"))
1000 (widen))
1001 (run-hooks 'nntp-prepare-post-hook)
1002 (nntp-send-buffer "^[23].*\n")))))
1003
1004 (deffoo nntp-request-type (group article)
1005 'news)
1006
1007 (deffoo nntp-asynchronous-p ()
1008 t)
1009
1010 ;;; Hooky functions.
1011
1012 (defun nntp-send-mode-reader ()
1013 "Send the MODE READER command to the nntp server.
1014 This function is supposed to be called from `nntp-server-opened-hook'.
1015 It will make innd servers spawn an nnrpd process to allow actual article
1016 reading."
1017 (nntp-send-command "^.*\n" "MODE READER"))
1018
1019 (defun nntp-send-authinfo (&optional send-if-force)
1020 "Send the AUTHINFO to the nntp server.
1021 It will look in the \"~/.authinfo\" file for matching entries. If
1022 nothing suitable is found there, it will prompt for a user name
1023 and a password.
1024
1025 If SEND-IF-FORCE, only send authinfo to the server if the
1026 .authinfo file has the FORCE token."
1027 (let* ((list (gnus-parse-netrc nntp-authinfo-file))
1028 (alist (gnus-netrc-machine list nntp-address "nntp"))
1029 (force (gnus-netrc-get alist "force"))
1030 (user (or (gnus-netrc-get alist "login") nntp-authinfo-user))
1031 (passwd (gnus-netrc-get alist "password")))
1032 (when (or (not send-if-force)
1033 force)
1034 (unless user
1035 (setq user (read-string (format "NNTP (%s) user name: " nntp-address))
1036 nntp-authinfo-user user))
1037 (unless (member user '(nil ""))
1038 (nntp-send-command "^3.*\r?\n" "AUTHINFO USER" user)
1039 (when t ;???Should check if AUTHINFO succeeded
1040 (nntp-send-command
1041 "^2.*\r?\n" "AUTHINFO PASS"
1042 (or passwd
1043 nntp-authinfo-password
1044 (setq nntp-authinfo-password
1045 (read-passwd (format "NNTP (%s@%s) password: "
1046 user nntp-address))))))))))
1047
1048 (defun nntp-send-nosy-authinfo ()
1049 "Send the AUTHINFO to the nntp server."
1050 (let ((user (read-string (format "NNTP (%s) user name: " nntp-address))))
1051 (unless (member user '(nil ""))
1052 (nntp-send-command "^3.*\r?\n" "AUTHINFO USER" user)
1053 (when t ;???Should check if AUTHINFO succeeded
1054 (nntp-send-command "^2.*\r?\n" "AUTHINFO PASS"
1055 (read-passwd (format "NNTP (%s@%s) password: "
1056 user nntp-address)))))))
1057
1058 (defun nntp-send-authinfo-from-file ()
1059 "Send the AUTHINFO to the nntp server.
1060
1061 The authinfo login name is taken from the user's login name and the
1062 password contained in '~/.nntp-authinfo'."
1063 (when (file-exists-p "~/.nntp-authinfo")
1064 (with-temp-buffer
1065 (insert-file-contents "~/.nntp-authinfo")
1066 (goto-char (point-min))
1067 (nntp-send-command "^3.*\r?\n" "AUTHINFO USER" (user-login-name))
1068 (nntp-send-command
1069 "^2.*\r?\n" "AUTHINFO PASS"
1070 (buffer-substring (point) (gnus-point-at-eol))))))
1071
1072 ;;; Internal functions.
1073
1074 (defun nntp-handle-authinfo (process)
1075 "Take care of an authinfo response from the server."
1076 (let ((last nntp-last-command))
1077 (funcall nntp-authinfo-function)
1078 ;; We have to re-send the function that was interrupted by
1079 ;; the authinfo request.
1080 (save-excursion
1081 (set-buffer nntp-server-buffer)
1082 (erase-buffer))
1083 (nntp-send-string process last)))
1084
1085 (defun nntp-make-process-buffer (buffer)
1086 "Create a new, fresh buffer usable for nntp process connections."
1087 (save-excursion
1088 (set-buffer
1089 (generate-new-buffer
1090 (format " *server %s %s %s*"
1091 nntp-address nntp-port-number
1092 (gnus-buffer-exists-p buffer))))
1093 (mm-enable-multibyte)
1094 (set (make-local-variable 'after-change-functions) nil)
1095 (set (make-local-variable 'nntp-process-wait-for) nil)
1096 (set (make-local-variable 'nntp-process-callback) nil)
1097 (set (make-local-variable 'nntp-process-to-buffer) nil)
1098 (set (make-local-variable 'nntp-process-start-point) nil)
1099 (set (make-local-variable 'nntp-process-decode) nil)
1100 (current-buffer)))
1101
1102 (defun nntp-open-connection (buffer)
1103 "Open a connection to PORT on ADDRESS delivering output to BUFFER."
1104 (run-hooks 'nntp-prepare-server-hook)
1105 (let* ((pbuffer (nntp-make-process-buffer buffer))
1106 (timer
1107 (and nntp-connection-timeout
1108 (nnheader-run-at-time
1109 nntp-connection-timeout nil
1110 `(lambda ()
1111 (nntp-kill-buffer ,pbuffer)))))
1112 (process
1113 (condition-case ()
1114 (let ((coding-system-for-read nntp-coding-system-for-read)
1115 (coding-system-for-write nntp-coding-system-for-write))
1116 (funcall nntp-open-connection-function pbuffer))
1117 (error nil)
1118 (quit
1119 (message "Quit opening connection")
1120 (nntp-kill-buffer pbuffer)
1121 (signal 'quit nil)
1122 nil))))
1123 (when timer
1124 (nnheader-cancel-timer timer))
1125 (unless process
1126 (nntp-kill-buffer pbuffer))
1127 (when (and (buffer-name pbuffer)
1128 process)
1129 (gnus-set-process-query-on-exit-flag process nil)
1130 (if (and (nntp-wait-for process "^2.*\n" buffer nil t)
1131 (memq (process-status process) '(open run)))
1132 (prog1
1133 (caar (push (list process buffer nil) nntp-connection-alist))
1134 (push process nntp-connection-list)
1135 (save-excursion
1136 (set-buffer pbuffer)
1137 (nntp-read-server-type)
1138 (erase-buffer)
1139 (set-buffer nntp-server-buffer)
1140 (let ((nnheader-callback-function nil))
1141 (run-hooks 'nntp-server-opened-hook)
1142 (nntp-send-authinfo t))))
1143 (nntp-kill-buffer (process-buffer process))
1144 nil))))
1145
1146 (defun nntp-open-network-stream (buffer)
1147 (open-network-stream "nntpd" buffer nntp-address nntp-port-number))
1148
1149 (eval-and-compile
1150 (autoload 'format-spec "format-spec")
1151 (autoload 'format-spec-make "format-spec")
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 (gnus-set-process-query-on-exit-flag proc nil)
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 (gnus-set-process-query-on-exit-flag proc nil)
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-number
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-number
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-number (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