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