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