Mercurial > emacs
annotate lisp/gnus/nntp.el @ 23193:c12a3c0be4ee
(Fload): Handle case where openp finds a magic file
but it has no `load' handler or that handler calls `load'.
If FOUND != FILE, find FOUND's handler even if inhibited for FILE.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Sun, 06 Sep 1998 13:57:32 +0000 |
parents | 196f32d1873f |
children | 629892842585 |
rev | line source |
---|---|
17493 | 1 ;;; nntp.el --- nntp access for Gnus |
2 ;;; Copyright (C) 1987,88,89,90,92,93,94,95,96,97 Free Software Foundation, Inc. | |
3 | |
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no> | |
5 ;; Keywords: news | |
6 | |
7 ;; This file is part of GNU Emacs. | |
8 | |
9 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
10 ;; it under the terms of the GNU General Public License as published by | |
11 ;; the Free Software Foundation; either version 2, or (at your option) | |
12 ;; any later version. | |
13 | |
14 ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 | |
19 ;; You should have received a copy of the GNU General Public License | |
20 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
21 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
22 | |
23 ;;; Commentary: | |
24 | |
25 ;;; Code: | |
26 | |
27 (require 'nnheader) | |
28 (require 'nnoo) | |
29 (require 'gnus-util) | |
30 | |
31 (nnoo-declare nntp) | |
32 | |
33 (eval-and-compile | |
34 (unless (fboundp 'open-network-stream) | |
35 (require 'tcp))) | |
36 | |
37 (eval-when-compile (require 'cl)) | |
38 | |
39 (defvoo nntp-address nil | |
40 "Address of the physical nntp server.") | |
41 | |
42 (defvoo nntp-port-number "nntp" | |
43 "Port number on the physical nntp server.") | |
44 | |
45 (defvoo nntp-server-opened-hook '(nntp-send-mode-reader) | |
46 "*Hook used for sending commands to the server at startup. | |
47 The default value is `nntp-send-mode-reader', which makes an innd | |
48 server spawn an nnrpd server. Another useful function to put in this | |
49 hook might be `nntp-send-authinfo', which will prompt for a password | |
50 to allow posting from the server. Note that this is only necessary to | |
51 do on servers that use strict access control.") | |
52 | |
53 (defvoo nntp-authinfo-function 'nntp-send-authinfo | |
54 "Function used to send AUTHINFO to the server.") | |
55 | |
56 (defvoo nntp-server-action-alist | |
57 '(("nntpd 1\\.5\\.11t" | |
58 (remove-hook 'nntp-server-opened-hook 'nntp-send-mode-reader)) | |
59 ("NNRP server Netscape" | |
60 (setq nntp-server-list-active-group nil))) | |
61 "Alist of regexps to match on server types and actions to be taken. | |
62 For instance, if you want Gnus to beep every time you connect | |
63 to innd, you could say something like: | |
64 | |
65 \(setq nntp-server-action-alist | |
66 '((\"innd\" (ding)))) | |
67 | |
68 You probably don't want to do that, though.") | |
69 | |
70 (defvoo nntp-open-connection-function 'nntp-open-network-stream | |
71 "*Function used for connecting to a remote system. | |
72 It will be called with the buffer to output in. | |
73 | |
74 Two pre-made functions are `nntp-open-network-stream', which is the | |
75 default, and simply connects to some port or other on the remote | |
19969
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19598
diff
changeset
|
76 system (see nntp-port-number). The other are `nntp-open-rlogin', |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19598
diff
changeset
|
77 which does an rlogin on the remote system, and then does a telnet to |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19598
diff
changeset
|
78 the NNTP server available there (see nntp-rlogin-parameters) and |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19598
diff
changeset
|
79 `nntp-open-telnet' which telnets to a remote system, logs in and does |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19598
diff
changeset
|
80 the same.") |
17493 | 81 |
82 (defvoo nntp-rlogin-parameters '("telnet" "-8" "${NNTPSERVER:=news}" "nntp") | |
83 "*Parameters to `nntp-open-login'. | |
84 That function may be used as `nntp-open-connection-function'. In that | |
85 case, this list will be used as the parameter list given to rsh.") | |
86 | |
87 (defvoo nntp-rlogin-user-name nil | |
88 "*User name on remote system when using the rlogin connect method.") | |
89 | |
90 (defvoo nntp-telnet-parameters '("exec" "telnet" "-8" "${NNTPSERVER:=news}" "nntp") | |
91 "*Parameters to `nntp-open-telnet'. | |
92 That function may be used as `nntp-open-connection-function'. In that | |
93 case, this list will be executed as a command after logging in | |
94 via telnet.") | |
95 | |
96 (defvoo nntp-telnet-user-name nil | |
97 "User name to log in via telnet with.") | |
98 | |
99 (defvoo nntp-telnet-passwd nil | |
100 "Password to use to log in via telnet with.") | |
101 | |
19969
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19598
diff
changeset
|
102 (defvoo nntp-telnet-command "telnet" |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19598
diff
changeset
|
103 "Command used to start telnet.") |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19598
diff
changeset
|
104 |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19598
diff
changeset
|
105 (defvoo nntp-telnet-switches '("-8") |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19598
diff
changeset
|
106 "Switches given to the telnet command.") |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19598
diff
changeset
|
107 |
17493 | 108 (defvoo nntp-end-of-line "\r\n" |
109 "String to use on the end of lines when talking to the NNTP server. | |
110 This is \"\\r\\n\" by default, but should be \"\\n\" when | |
111 using rlogin or telnet to communicate with the server.") | |
112 | |
113 (defvoo nntp-large-newsgroup 50 | |
114 "*The number of the articles which indicates a large newsgroup. | |
115 If the number of the articles is greater than the value, verbose | |
116 messages will be shown to indicate the current status.") | |
117 | |
118 (defvoo nntp-maximum-request 400 | |
119 "*The maximum number of the requests sent to the NNTP server at one time. | |
120 If Emacs hangs up while retrieving headers, set the variable to a | |
121 lower value.") | |
122 | |
123 (defvoo nntp-nov-is-evil nil | |
124 "*If non-nil, nntp will never attempt to use XOVER when talking to the server.") | |
125 | |
126 (defvoo nntp-xover-commands '("XOVER" "XOVERVIEW") | |
127 "*List of strings that are used as commands to fetch NOV lines from a server. | |
128 The strings are tried in turn until a positive response is gotten. If | |
129 none of the commands are successful, nntp will just grab headers one | |
130 by one.") | |
131 | |
19969
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19598
diff
changeset
|
132 (defvoo nntp-nov-gap 5 |
17493 | 133 "*Maximum allowed gap between two articles. |
134 If the gap between two consecutive articles is bigger than this | |
135 variable, split the XOVER request into two requests.") | |
136 | |
137 (defvoo nntp-connection-timeout nil | |
138 "*Number of seconds to wait before an nntp connection times out. | |
139 If this variable is nil, which is the default, no timers are set.") | |
140 | |
141 (defvoo nntp-prepare-server-hook nil | |
142 "*Hook run before a server is opened. | |
143 If can be used to set up a server remotely, for instance. Say you | |
144 have an account at the machine \"other.machine\". This machine has | |
145 access to an NNTP server that you can't access locally. You could | |
146 then use this hook to rsh to the remote machine and start a proxy NNTP | |
147 server there that you can connect to. See also `nntp-open-connection-function'") | |
148 | |
149 (defvoo nntp-warn-about-losing-connection t | |
150 "*If non-nil, beep when a server closes connection.") | |
151 | |
19598
611e0de24d43
(nntp-coding-system-for-read): New variable.
Kenichi Handa <handa@m17n.org>
parents:
17493
diff
changeset
|
152 ;; 1997/5/4 by MORIOKA Tomohiko <morioka@jaist.ac.jp> |
20236
fe71a35628c9
(nntp-coding-system-for-read): Set default value to
Kenichi Handa <handa@m17n.org>
parents:
19992
diff
changeset
|
153 (defvoo nntp-coding-system-for-read 'binary |
19992
36e81448237d
(nntp-coding-system-for-write): New variable.
Kenichi Handa <handa@m17n.org>
parents:
19969
diff
changeset
|
154 "*Coding system to read from NNTP.") |
36e81448237d
(nntp-coding-system-for-write): New variable.
Kenichi Handa <handa@m17n.org>
parents:
19969
diff
changeset
|
155 |
20236
fe71a35628c9
(nntp-coding-system-for-read): Set default value to
Kenichi Handa <handa@m17n.org>
parents:
19992
diff
changeset
|
156 (defvoo nntp-coding-system-for-write 'binary |
19992
36e81448237d
(nntp-coding-system-for-write): New variable.
Kenichi Handa <handa@m17n.org>
parents:
19969
diff
changeset
|
157 "*Coding system to write to NNTP.") |
19598
611e0de24d43
(nntp-coding-system-for-read): New variable.
Kenichi Handa <handa@m17n.org>
parents:
17493
diff
changeset
|
158 |
17493 | 159 |
160 | |
161 ;;; Internal variables. | |
162 | |
163 (defvar nntp-have-messaged nil) | |
164 | |
165 (defvar nntp-process-wait-for nil) | |
166 (defvar nntp-process-to-buffer nil) | |
167 (defvar nntp-process-callback nil) | |
168 (defvar nntp-process-decode nil) | |
169 (defvar nntp-process-start-point nil) | |
170 (defvar nntp-inside-change-function nil) | |
171 | |
172 (defvar nntp-connection-list nil) | |
173 | |
174 (defvoo nntp-server-type nil) | |
175 (defvoo nntp-connection-alist nil) | |
176 (defvoo nntp-status-string "") | |
177 (defconst nntp-version "nntp 5.0") | |
178 (defvoo nntp-inhibit-erase nil) | |
179 (defvoo nntp-inhibit-output nil) | |
180 | |
181 (defvoo nntp-server-xover 'try) | |
182 (defvoo nntp-server-list-active-group 'try) | |
183 | |
184 (eval-and-compile | |
185 (autoload 'nnmail-read-passwd "nnmail")) | |
186 | |
187 | |
188 | |
189 ;;; Internal functions. | |
190 | |
191 (defsubst nntp-send-string (process string) | |
192 "Send STRING to PROCESS." | |
193 (process-send-string process (concat string nntp-end-of-line))) | |
194 | |
195 (defsubst nntp-wait-for (process wait-for buffer &optional decode discard) | |
196 "Wait for WAIT-FOR to arrive from PROCESS." | |
197 (save-excursion | |
198 (set-buffer (process-buffer process)) | |
199 (goto-char (point-min)) | |
19969
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19598
diff
changeset
|
200 (while (or (not (memq (char-after (point)) '(?2 ?3 ?4 ?5))) |
17493 | 201 (looking-at "480")) |
202 (when (looking-at "480") | |
203 (erase-buffer) | |
204 (funcall nntp-authinfo-function)) | |
205 (nntp-accept-process-output process) | |
206 (goto-char (point-min))) | |
207 (prog1 | |
208 (if (looking-at "[45]") | |
209 (progn | |
210 (nntp-snarf-error-message) | |
211 nil) | |
212 (goto-char (point-max)) | |
213 (let ((limit (point-min))) | |
214 (while (not (re-search-backward wait-for limit t)) | |
215 ;; We assume that whatever we wait for is less than 1000 | |
216 ;; characters long. | |
217 (setq limit (max (- (point-max) 1000) (point-min))) | |
218 (nntp-accept-process-output process) | |
219 (goto-char (point-max)))) | |
220 (nntp-decode-text (not decode)) | |
221 (unless discard | |
222 (save-excursion | |
223 (set-buffer buffer) | |
224 (goto-char (point-max)) | |
225 (insert-buffer-substring (process-buffer process)) | |
226 ;; Nix out "nntp reading...." message. | |
227 (when nntp-have-messaged | |
228 (setq nntp-have-messaged nil) | |
229 (message "")) | |
230 t))) | |
231 (unless discard | |
232 (erase-buffer))))) | |
233 | |
234 (defsubst nntp-find-connection (buffer) | |
235 "Find the connection delivering to BUFFER." | |
236 (let ((alist nntp-connection-alist) | |
237 (buffer (if (stringp buffer) (get-buffer buffer) buffer)) | |
238 process entry) | |
239 (while (setq entry (pop alist)) | |
240 (when (eq buffer (cadr entry)) | |
241 (setq process (car entry) | |
242 alist nil))) | |
243 (when process | |
244 (if (memq (process-status process) '(open run)) | |
245 process | |
246 (when (buffer-name (process-buffer process)) | |
247 (kill-buffer (process-buffer process))) | |
248 (setq nntp-connection-alist (delq entry nntp-connection-alist)) | |
249 nil)))) | |
250 | |
251 (defsubst nntp-find-connection-entry (buffer) | |
252 "Return the entry for the connection to BUFFER." | |
253 (assq (nntp-find-connection buffer) nntp-connection-alist)) | |
254 | |
255 (defun nntp-find-connection-buffer (buffer) | |
256 "Return the process connection buffer tied to BUFFER." | |
257 (let ((process (nntp-find-connection buffer))) | |
258 (when process | |
259 (process-buffer process)))) | |
260 | |
261 (defsubst nntp-retrieve-data (command address port buffer | |
262 &optional wait-for callback decode) | |
263 "Use COMMAND to retrieve data into BUFFER from PORT on ADDRESS." | |
264 (let ((process (or (nntp-find-connection buffer) | |
265 (nntp-open-connection buffer)))) | |
266 (if (not process) | |
267 (nnheader-report 'nntp "Couldn't open connection to %s" address) | |
268 (unless (or nntp-inhibit-erase nnheader-callback-function) | |
269 (save-excursion | |
270 (set-buffer (process-buffer process)) | |
271 (erase-buffer))) | |
272 (when command | |
273 (nntp-send-string process command)) | |
274 (cond | |
275 ((eq callback 'ignore) | |
276 t) | |
277 ((and callback wait-for) | |
278 (save-excursion | |
279 (set-buffer (process-buffer process)) | |
280 (unless nntp-inside-change-function | |
281 (erase-buffer)) | |
282 (setq nntp-process-decode decode | |
283 nntp-process-to-buffer buffer | |
284 nntp-process-wait-for wait-for | |
285 nntp-process-callback callback | |
286 nntp-process-start-point (point-max) | |
287 after-change-functions | |
288 (list 'nntp-after-change-function-callback))) | |
289 t) | |
290 (wait-for | |
291 (nntp-wait-for process wait-for buffer decode)) | |
292 (t t))))) | |
293 | |
294 (defsubst nntp-send-command (wait-for &rest strings) | |
295 "Send STRINGS to server and wait until WAIT-FOR returns." | |
296 (when (and (not nnheader-callback-function) | |
297 (not nntp-inhibit-output)) | |
298 (save-excursion | |
299 (set-buffer nntp-server-buffer) | |
300 (erase-buffer))) | |
301 (nntp-retrieve-data | |
302 (mapconcat 'identity strings " ") | |
303 nntp-address nntp-port-number nntp-server-buffer | |
304 wait-for nnheader-callback-function)) | |
305 | |
306 (defun nntp-send-command-nodelete (wait-for &rest strings) | |
307 "Send STRINGS to server and wait until WAIT-FOR returns." | |
308 (nntp-retrieve-data | |
309 (mapconcat 'identity strings " ") | |
310 nntp-address nntp-port-number nntp-server-buffer | |
311 wait-for nnheader-callback-function)) | |
312 | |
313 (defun nntp-send-command-and-decode (wait-for &rest strings) | |
314 "Send STRINGS to server and wait until WAIT-FOR returns." | |
315 (when (and (not nnheader-callback-function) | |
316 (not nntp-inhibit-output)) | |
317 (save-excursion | |
318 (set-buffer nntp-server-buffer) | |
319 (erase-buffer))) | |
320 (nntp-retrieve-data | |
321 (mapconcat 'identity strings " ") | |
322 nntp-address nntp-port-number nntp-server-buffer | |
323 wait-for nnheader-callback-function t)) | |
324 | |
325 (defun nntp-send-buffer (wait-for) | |
326 "Send the current buffer to server and wait until WAIT-FOR returns." | |
327 (when (and (not nnheader-callback-function) | |
328 (not nntp-inhibit-output)) | |
329 (save-excursion | |
330 (set-buffer (nntp-find-connection-buffer nntp-server-buffer)) | |
331 (erase-buffer))) | |
332 (nntp-encode-text) | |
333 (process-send-region (nntp-find-connection nntp-server-buffer) | |
334 (point-min) (point-max)) | |
335 (nntp-retrieve-data | |
336 nil nntp-address nntp-port-number nntp-server-buffer | |
337 wait-for nnheader-callback-function)) | |
338 | |
339 | |
340 | |
341 ;;; Interface functions. | |
342 | |
343 (nnoo-define-basics nntp) | |
344 | |
345 (deffoo nntp-retrieve-headers (articles &optional group server fetch-old) | |
346 "Retrieve the headers of ARTICLES." | |
347 (nntp-possibly-change-group group server) | |
348 (save-excursion | |
349 (set-buffer (nntp-find-connection-buffer nntp-server-buffer)) | |
350 (erase-buffer) | |
351 (if (and (not gnus-nov-is-evil) | |
352 (not nntp-nov-is-evil) | |
353 (nntp-retrieve-headers-with-xover articles fetch-old)) | |
354 ;; We successfully retrieved the headers via XOVER. | |
355 'nov | |
356 ;; XOVER didn't work, so we do it the hard, slow and inefficient | |
357 ;; way. | |
358 (let ((number (length articles)) | |
359 (count 0) | |
360 (received 0) | |
361 (last-point (point-min)) | |
362 (buf (nntp-find-connection-buffer nntp-server-buffer)) | |
363 (nntp-inhibit-erase t)) | |
364 ;; Send HEAD command. | |
365 (while articles | |
366 (nntp-send-command | |
367 nil | |
368 "HEAD" (if (numberp (car articles)) | |
369 (int-to-string (car articles)) | |
370 ;; `articles' is either a list of article numbers | |
371 ;; or a list of article IDs. | |
372 (car articles))) | |
373 (setq articles (cdr articles) | |
374 count (1+ count)) | |
375 ;; Every 400 header requests we have to read the stream in | |
376 ;; order to avoid deadlocks. | |
377 (when (or (null articles) ;All requests have been sent. | |
378 (zerop (% count nntp-maximum-request))) | |
379 (nntp-accept-response) | |
380 (while (progn | |
381 (progn | |
382 (set-buffer buf) | |
383 (goto-char last-point)) | |
384 ;; Count replies. | |
385 (while (re-search-forward "^[0-9]" nil t) | |
386 (incf received)) | |
387 (setq last-point (point)) | |
388 (< received count)) | |
389 ;; If number of headers is greater than 100, give | |
390 ;; informative messages. | |
391 (and (numberp nntp-large-newsgroup) | |
392 (> number nntp-large-newsgroup) | |
393 (zerop (% received 20)) | |
394 (nnheader-message 6 "NNTP: Receiving headers... %d%%" | |
395 (/ (* received 100) number))) | |
396 (nntp-accept-response)))) | |
397 ;; Wait for text of last command. | |
398 (goto-char (point-max)) | |
399 (re-search-backward "^[0-9]" nil t) | |
400 (when (looking-at "^[23]") | |
401 (while (progn | |
402 (goto-char (point-max)) | |
403 (forward-line -1) | |
404 (not (looking-at "^\\.\r?\n"))) | |
405 (nntp-accept-response))) | |
406 (and (numberp nntp-large-newsgroup) | |
407 (> number nntp-large-newsgroup) | |
408 (nnheader-message 6 "NNTP: Receiving headers...done")) | |
409 | |
410 ;; Now all of replies are received. Fold continuation lines. | |
411 (nnheader-fold-continuation-lines) | |
412 ;; Remove all "\r"'s. | |
413 (nnheader-strip-cr) | |
414 (copy-to-buffer nntp-server-buffer (point-min) (point-max)) | |
415 'headers)))) | |
416 | |
417 (deffoo nntp-retrieve-groups (groups &optional server) | |
418 "Retrieve group info on GROUPS." | |
419 (nntp-possibly-change-group nil server) | |
420 (save-excursion | |
421 (set-buffer (nntp-find-connection-buffer nntp-server-buffer)) | |
422 ;; The first time this is run, this variable is `try'. So we | |
423 ;; try. | |
424 (when (eq nntp-server-list-active-group 'try) | |
425 (nntp-try-list-active (car groups))) | |
426 (erase-buffer) | |
427 (let ((count 0) | |
428 (received 0) | |
429 (last-point (point-min)) | |
430 (nntp-inhibit-erase t) | |
431 (command (if nntp-server-list-active-group "LIST ACTIVE" "GROUP"))) | |
432 (while groups | |
433 ;; Send the command to the server. | |
434 (nntp-send-command nil command (pop groups)) | |
435 (incf count) | |
436 ;; Every 400 requests we have to read the stream in | |
437 ;; order to avoid deadlocks. | |
438 (when (or (null groups) ;All requests have been sent. | |
439 (zerop (% count nntp-maximum-request))) | |
440 (nntp-accept-response) | |
441 (while (progn | |
442 (goto-char last-point) | |
443 ;; Count replies. | |
444 (while (re-search-forward "^[0-9]" nil t) | |
445 (incf received)) | |
446 (setq last-point (point)) | |
447 (< received count)) | |
448 (nntp-accept-response)))) | |
449 | |
450 ;; Wait for the reply from the final command. | |
451 (goto-char (point-max)) | |
452 (re-search-backward "^[0-9]" nil t) | |
453 (when (looking-at "^[23]") | |
454 (while (progn | |
455 (goto-char (point-max)) | |
456 (if (not nntp-server-list-active-group) | |
457 (not (re-search-backward "\r?\n" (- (point) 3) t)) | |
458 (not (re-search-backward "^\\.\r?\n" (- (point) 4) t)))) | |
459 (nntp-accept-response))) | |
460 | |
461 ;; Now all replies are received. We remove CRs. | |
462 (goto-char (point-min)) | |
463 (while (search-forward "\r" nil t) | |
464 (replace-match "" t t)) | |
465 | |
466 (if (not nntp-server-list-active-group) | |
467 (progn | |
468 (copy-to-buffer nntp-server-buffer (point-min) (point-max)) | |
469 'group) | |
470 ;; We have read active entries, so we just delete the | |
471 ;; superfluous gunk. | |
472 (goto-char (point-min)) | |
473 (while (re-search-forward "^[.2-5]" nil t) | |
474 (delete-region (match-beginning 0) | |
475 (progn (forward-line 1) (point)))) | |
476 (copy-to-buffer nntp-server-buffer (point-min) (point-max)) | |
477 'active)))) | |
478 | |
479 (deffoo nntp-retrieve-articles (articles &optional group server) | |
480 (nntp-possibly-change-group group server) | |
481 (save-excursion | |
482 (let ((number (length articles)) | |
483 (count 0) | |
484 (received 0) | |
485 (last-point (point-min)) | |
486 (buf (nntp-find-connection-buffer nntp-server-buffer)) | |
487 (nntp-inhibit-erase t) | |
488 (map (apply 'vector articles)) | |
489 (point 1) | |
490 article alist) | |
491 (set-buffer buf) | |
492 (erase-buffer) | |
493 ;; Send HEAD command. | |
494 (while (setq article (pop articles)) | |
495 (nntp-send-command | |
496 nil | |
497 "ARTICLE" (if (numberp article) | |
498 (int-to-string article) | |
499 ;; `articles' is either a list of article numbers | |
500 ;; or a list of article IDs. | |
501 article)) | |
502 (incf count) | |
503 ;; Every 400 requests we have to read the stream in | |
504 ;; order to avoid deadlocks. | |
505 (when (or (null articles) ;All requests have been sent. | |
506 (zerop (% count nntp-maximum-request))) | |
507 (nntp-accept-response) | |
508 (while (progn | |
509 (progn | |
510 (set-buffer buf) | |
511 (goto-char last-point)) | |
512 ;; Count replies. | |
513 (while (nntp-next-result-arrived-p) | |
514 (aset map received (cons (aref map received) (point))) | |
515 (incf received)) | |
516 (setq last-point (point)) | |
517 (< received count)) | |
518 ;; If number of headers is greater than 100, give | |
519 ;; informative messages. | |
520 (and (numberp nntp-large-newsgroup) | |
521 (> number nntp-large-newsgroup) | |
522 (zerop (% received 20)) | |
523 (nnheader-message 6 "NNTP: Receiving articles... %d%%" | |
524 (/ (* received 100) number))) | |
525 (nntp-accept-response)))) | |
526 (and (numberp nntp-large-newsgroup) | |
527 (> number nntp-large-newsgroup) | |
528 (nnheader-message 6 "NNTP: Receiving headers...done")) | |
529 | |
530 ;; Now we have all the responses. We go through the results, | |
531 ;; washes it and copies it over to the server buffer. | |
532 (set-buffer nntp-server-buffer) | |
533 (erase-buffer) | |
534 (mapcar | |
535 (lambda (entry) | |
536 (narrow-to-region | |
537 (setq point (goto-char (point-max))) | |
538 (progn | |
539 (insert-buffer-substring buf last-point (cdr entry)) | |
540 (point-max))) | |
541 (nntp-decode-text) | |
542 (widen) | |
543 (cons (car entry) point)) | |
544 map)))) | |
545 | |
546 (defun nntp-next-result-arrived-p () | |
547 (let ((point (point))) | |
548 (cond | |
549 ((looking-at "2") | |
550 (if (re-search-forward "\n.\r?\n" nil t) | |
551 t | |
552 (goto-char point) | |
553 nil)) | |
554 ((looking-at "[34]") | |
555 (forward-line 1) | |
556 t) | |
557 (t | |
558 nil)))) | |
559 | |
560 (defun nntp-try-list-active (group) | |
561 (nntp-list-active-group group) | |
562 (save-excursion | |
563 (set-buffer nntp-server-buffer) | |
564 (goto-char (point-min)) | |
565 (cond ((or (eobp) | |
566 (looking-at "5[0-9]+")) | |
567 (setq nntp-server-list-active-group nil)) | |
568 (t | |
569 (setq nntp-server-list-active-group t))))) | |
570 | |
571 (deffoo nntp-list-active-group (group &optional server) | |
572 "Return the active info on GROUP (which can be a regexp." | |
573 (nntp-possibly-change-group nil server) | |
574 (nntp-send-command "^.*\r?\n" "LIST ACTIVE" group)) | |
575 | |
576 (deffoo nntp-request-article (article &optional group server buffer command) | |
577 (nntp-possibly-change-group group server) | |
578 (when (nntp-send-command-and-decode | |
579 "\r?\n\\.\r?\n" "ARTICLE" | |
580 (if (numberp article) (int-to-string article) article)) | |
19969
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19598
diff
changeset
|
581 (if (and buffer |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19598
diff
changeset
|
582 (not (equal buffer nntp-server-buffer))) |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19598
diff
changeset
|
583 (save-excursion |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19598
diff
changeset
|
584 (set-buffer nntp-server-buffer) |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19598
diff
changeset
|
585 (copy-to-buffer buffer (point-min) (point-max)) |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19598
diff
changeset
|
586 (nntp-find-group-and-number)) |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19598
diff
changeset
|
587 (nntp-find-group-and-number)))) |
17493 | 588 |
589 (deffoo nntp-request-head (article &optional group server) | |
590 (nntp-possibly-change-group group server) | |
19969
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19598
diff
changeset
|
591 (when (nntp-send-command |
17493 | 592 "\r?\n\\.\r?\n" "HEAD" |
593 (if (numberp article) (int-to-string article) article)) | |
19969
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19598
diff
changeset
|
594 (prog1 |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19598
diff
changeset
|
595 (nntp-find-group-and-number) |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19598
diff
changeset
|
596 (nntp-decode-text)))) |
17493 | 597 |
598 (deffoo nntp-request-body (article &optional group server) | |
599 (nntp-possibly-change-group group server) | |
600 (nntp-send-command-and-decode | |
601 "\r?\n\\.\r?\n" "BODY" | |
602 (if (numberp article) (int-to-string article) article))) | |
603 | |
604 (deffoo nntp-request-group (group &optional server dont-check) | |
605 (nntp-possibly-change-group nil server) | |
606 (when (nntp-send-command "^2.*\n" "GROUP" group) | |
607 (let ((entry (nntp-find-connection-entry nntp-server-buffer))) | |
608 (setcar (cddr entry) group)))) | |
609 | |
610 (deffoo nntp-close-group (group &optional server) | |
611 t) | |
612 | |
613 (deffoo nntp-server-opened (&optional server) | |
614 "Say whether a connection to SERVER has been opened." | |
615 (and (nnoo-current-server-p 'nntp server) | |
616 nntp-server-buffer | |
617 (gnus-buffer-live-p nntp-server-buffer) | |
618 (nntp-find-connection nntp-server-buffer))) | |
619 | |
620 (deffoo nntp-open-server (server &optional defs connectionless) | |
621 (nnheader-init-server-buffer) | |
622 (if (nntp-server-opened server) | |
623 t | |
624 (when (or (stringp (car defs)) | |
625 (numberp (car defs))) | |
626 (setq defs (cons (list 'nntp-port-number (car defs)) (cdr defs)))) | |
627 (unless (assq 'nntp-address defs) | |
628 (setq defs (append defs (list (list 'nntp-address server))))) | |
629 (nnoo-change-server 'nntp server defs) | |
630 (unless connectionless | |
631 (or (nntp-find-connection nntp-server-buffer) | |
632 (nntp-open-connection nntp-server-buffer))))) | |
633 | |
634 (deffoo nntp-close-server (&optional server) | |
635 (nntp-possibly-change-group nil server t) | |
636 (let (process) | |
637 (while (setq process (car (pop nntp-connection-alist))) | |
638 (when (memq (process-status process) '(open run)) | |
639 (set-process-sentinel process nil) | |
640 (nntp-send-string process "QUIT")) | |
641 (when (buffer-name (process-buffer process)) | |
642 (kill-buffer (process-buffer process)))) | |
643 (nnoo-close-server 'nntp))) | |
644 | |
645 (deffoo nntp-request-close () | |
646 (let (process) | |
647 (while (setq process (pop nntp-connection-list)) | |
648 (when (memq (process-status process) '(open run)) | |
649 (set-process-sentinel process nil) | |
650 (ignore-errors | |
651 (nntp-send-string process "QUIT"))) | |
652 (when (buffer-name (process-buffer process)) | |
653 (kill-buffer (process-buffer process)))))) | |
654 | |
655 (deffoo nntp-request-list (&optional server) | |
656 (nntp-possibly-change-group nil server) | |
657 (nntp-send-command-and-decode "\r?\n\\.\r?\n" "LIST")) | |
658 | |
659 (deffoo nntp-request-list-newsgroups (&optional server) | |
660 (nntp-possibly-change-group nil server) | |
661 (nntp-send-command "\r?\n\\.\r?\n" "LIST NEWSGROUPS")) | |
662 | |
663 (deffoo nntp-request-newgroups (date &optional server) | |
664 (nntp-possibly-change-group nil server) | |
665 (save-excursion | |
666 (set-buffer nntp-server-buffer) | |
667 (let* ((date (timezone-parse-date date)) | |
668 (time-string | |
669 (format "%s%02d%02d %s%s%s" | |
670 (substring (aref date 0) 2) (string-to-int (aref date 1)) | |
671 (string-to-int (aref date 2)) (substring (aref date 3) 0 2) | |
672 (substring | |
673 (aref date 3) 3 5) (substring (aref date 3) 6 8)))) | |
674 (prog1 | |
675 (nntp-send-command "^\\.\r?\n" "NEWGROUPS" time-string) | |
676 (nntp-decode-text))))) | |
677 | |
678 (deffoo nntp-request-post (&optional server) | |
679 (nntp-possibly-change-group nil server) | |
680 (when (nntp-send-command "^[23].*\r?\n" "POST") | |
681 (nntp-send-buffer "^[23].*\n"))) | |
682 | |
683 (deffoo nntp-request-type (group article) | |
684 'news) | |
685 | |
686 (deffoo nntp-asynchronous-p () | |
687 t) | |
688 | |
689 ;;; Hooky functions. | |
690 | |
691 (defun nntp-send-mode-reader () | |
692 "Send the MODE READER command to the nntp server. | |
693 This function is supposed to be called from `nntp-server-opened-hook'. | |
694 It will make innd servers spawn an nnrpd process to allow actual article | |
695 reading." | |
696 (nntp-send-command "^.*\r?\n" "MODE READER")) | |
697 | |
698 (defun nntp-send-nosy-authinfo () | |
699 "Send the AUTHINFO to the nntp server. | |
700 This function is supposed to be called from `nntp-server-opened-hook'. | |
701 It will prompt for a password." | |
702 (nntp-send-command | |
703 "^.*\r?\n" "AUTHINFO USER" | |
704 (read-string (format "NNTP (%s) user name: " nntp-address))) | |
705 (nntp-send-command | |
706 "^.*\r?\n" "AUTHINFO PASS" | |
707 (nnmail-read-passwd "NNTP (%s) password: " nntp-address))) | |
708 | |
709 (defun nntp-send-authinfo () | |
710 "Send the AUTHINFO to the nntp server. | |
711 This function is supposed to be called from `nntp-server-opened-hook'. | |
712 It will prompt for a password." | |
713 (nntp-send-command "^.*\r?\n" "AUTHINFO USER" (user-login-name)) | |
714 (nntp-send-command | |
715 "^.*\r?\n" "AUTHINFO PASS" | |
716 (nnmail-read-passwd (format "NNTP (%s) password: " nntp-address)))) | |
717 | |
718 (defun nntp-send-authinfo-from-file () | |
719 "Send the AUTHINFO to the nntp server. | |
720 This function is supposed to be called from `nntp-server-opened-hook'." | |
721 (when (file-exists-p "~/.nntp-authinfo") | |
722 (nnheader-temp-write nil | |
723 (insert-file-contents "~/.nntp-authinfo") | |
724 (goto-char (point-min)) | |
725 (nntp-send-command "^.*\r?\n" "AUTHINFO USER" (user-login-name)) | |
726 (nntp-send-command | |
727 "^.*\r?\n" "AUTHINFO PASS" | |
728 (buffer-substring (point) (progn (end-of-line) (point))))))) | |
729 | |
730 ;;; Internal functions. | |
731 | |
732 (defun nntp-make-process-buffer (buffer) | |
733 "Create a new, fresh buffer usable for nntp process connections." | |
734 (save-excursion | |
735 (set-buffer | |
736 (generate-new-buffer | |
737 (format " *server %s %s %s*" | |
738 nntp-address nntp-port-number | |
739 (buffer-name (get-buffer buffer))))) | |
740 (buffer-disable-undo (current-buffer)) | |
741 (set (make-local-variable 'after-change-functions) nil) | |
742 (set (make-local-variable 'nntp-process-wait-for) nil) | |
743 (set (make-local-variable 'nntp-process-callback) nil) | |
744 (set (make-local-variable 'nntp-process-to-buffer) nil) | |
745 (set (make-local-variable 'nntp-process-start-point) nil) | |
746 (set (make-local-variable 'nntp-process-decode) nil) | |
747 (current-buffer))) | |
748 | |
749 (defun nntp-open-connection (buffer) | |
750 "Open a connection to PORT on ADDRESS delivering output to BUFFER." | |
751 (run-hooks 'nntp-prepare-server-hook) | |
752 (let* ((pbuffer (nntp-make-process-buffer buffer)) | |
753 (process | |
754 (condition-case () | |
19598
611e0de24d43
(nntp-coding-system-for-read): New variable.
Kenichi Handa <handa@m17n.org>
parents:
17493
diff
changeset
|
755 ;; 1997/5/4 by MORIOKA Tomohiko <morioka@jaist.ac.jp> |
19992
36e81448237d
(nntp-coding-system-for-write): New variable.
Kenichi Handa <handa@m17n.org>
parents:
19969
diff
changeset
|
756 (let ((coding-system-for-read nntp-coding-system-for-read) |
36e81448237d
(nntp-coding-system-for-write): New variable.
Kenichi Handa <handa@m17n.org>
parents:
19969
diff
changeset
|
757 (coding-system-for-write nntp-coding-system-for-write)) |
19598
611e0de24d43
(nntp-coding-system-for-read): New variable.
Kenichi Handa <handa@m17n.org>
parents:
17493
diff
changeset
|
758 (funcall nntp-open-connection-function pbuffer)) |
17493 | 759 (error nil) |
760 (quit nil)))) | |
761 (when process | |
762 (process-kill-without-query process) | |
763 (nntp-wait-for process "^.*\n" buffer nil t) | |
764 (if (memq (process-status process) '(open run)) | |
765 (prog1 | |
766 (caar (push (list process buffer nil) nntp-connection-alist)) | |
767 (push process nntp-connection-list) | |
768 (save-excursion | |
769 (set-buffer pbuffer) | |
770 (nntp-read-server-type) | |
771 (erase-buffer) | |
772 (set-buffer nntp-server-buffer) | |
773 (let ((nnheader-callback-function nil)) | |
774 (run-hooks 'nntp-server-opened-hook)))) | |
775 (when (buffer-name (process-buffer process)) | |
776 (kill-buffer (process-buffer process))) | |
777 nil)))) | |
778 | |
779 (defun nntp-open-network-stream (buffer) | |
780 (open-network-stream "nntpd" buffer nntp-address nntp-port-number)) | |
781 | |
782 (defun nntp-read-server-type () | |
783 "Find out what the name of the server we have connected to is." | |
784 ;; Wait for the status string to arrive. | |
785 (setq nntp-server-type (buffer-string)) | |
786 (let ((alist nntp-server-action-alist) | |
787 (case-fold-search t) | |
788 entry) | |
789 ;; Run server-specific commands. | |
790 (while alist | |
791 (setq entry (pop alist)) | |
792 (when (string-match (car entry) nntp-server-type) | |
793 (if (and (listp (cadr entry)) | |
794 (not (eq 'lambda (caadr entry)))) | |
795 (eval (cadr entry)) | |
796 (funcall (cadr entry))))))) | |
797 | |
798 (defun nntp-after-change-function-callback (beg end len) | |
799 (when nntp-process-callback | |
800 (save-match-data | |
801 (if (and (= beg (point-min)) | |
802 (memq (char-after beg) '(?4 ?5))) | |
803 ;; Report back error messages. | |
804 (save-excursion | |
805 (goto-char beg) | |
806 (if (looking-at "480") | |
807 (funcall nntp-authinfo-function) | |
808 (nntp-snarf-error-message) | |
809 (funcall nntp-process-callback nil))) | |
810 (goto-char end) | |
811 (when (and (> (point) nntp-process-start-point) | |
812 (re-search-backward nntp-process-wait-for | |
813 nntp-process-start-point t)) | |
814 (when (buffer-name (get-buffer nntp-process-to-buffer)) | |
815 (let ((cur (current-buffer)) | |
816 (start nntp-process-start-point)) | |
817 (save-excursion | |
818 (set-buffer (get-buffer nntp-process-to-buffer)) | |
819 (goto-char (point-max)) | |
820 (let ((b (point))) | |
821 (insert-buffer-substring cur start) | |
822 (narrow-to-region b (point-max)) | |
823 (nntp-decode-text) | |
824 (widen))))) | |
825 (goto-char end) | |
826 (let ((callback nntp-process-callback) | |
827 (nntp-inside-change-function t)) | |
828 (setq nntp-process-callback nil) | |
829 (save-excursion | |
830 (funcall callback (buffer-name | |
831 (get-buffer nntp-process-to-buffer)))))))))) | |
832 | |
833 (defun nntp-snarf-error-message () | |
834 "Save the error message in the current buffer." | |
835 (let ((message (buffer-string))) | |
836 (while (string-match "[\r\n]+" message) | |
837 (setq message (replace-match " " t t message))) | |
838 (nnheader-report 'nntp message) | |
839 message)) | |
840 | |
841 (defun nntp-accept-process-output (process) | |
842 "Wait for output from PROCESS and message some dots." | |
843 (save-excursion | |
844 (set-buffer (or (nntp-find-connection-buffer nntp-server-buffer) | |
845 nntp-server-buffer)) | |
846 (let ((len (/ (point-max) 1024)) | |
847 message-log-max) | |
848 (unless (< len 10) | |
849 (setq nntp-have-messaged t) | |
850 (nnheader-message 7 "nntp read: %dk" len))) | |
851 (accept-process-output process 1))) | |
852 | |
853 (defun nntp-accept-response () | |
854 "Wait for output from the process that outputs to BUFFER." | |
855 (nntp-accept-process-output (nntp-find-connection nntp-server-buffer))) | |
856 | |
857 (defun nntp-possibly-change-group (group server &optional connectionless) | |
858 (let ((nnheader-callback-function nil)) | |
859 (when server | |
860 (or (nntp-server-opened server) | |
861 (nntp-open-server server nil connectionless))) | |
862 | |
863 (unless connectionless | |
864 (or (nntp-find-connection nntp-server-buffer) | |
865 (nntp-open-connection nntp-server-buffer)))) | |
866 | |
867 (when group | |
868 (let ((entry (nntp-find-connection-entry nntp-server-buffer))) | |
869 (when (not (equal group (caddr entry))) | |
870 (save-excursion | |
871 (set-buffer (process-buffer (car entry))) | |
872 (erase-buffer) | |
873 (nntp-send-string (car entry) (concat "GROUP " group)) | |
874 (nntp-wait-for-string "^2.*\n") | |
875 (setcar (cddr entry) group) | |
876 (erase-buffer)))))) | |
877 | |
878 (defun nntp-decode-text (&optional cr-only) | |
879 "Decode the text in the current buffer." | |
880 (goto-char (point-min)) | |
881 (while (search-forward "\r" nil t) | |
882 (delete-char -1)) | |
883 (unless cr-only | |
884 ;; Remove trailing ".\n" end-of-transfer marker. | |
885 (goto-char (point-max)) | |
886 (forward-line -1) | |
887 (when (looking-at ".\n") | |
888 (delete-char 2)) | |
889 ;; Delete status line. | |
890 (goto-char (point-min)) | |
891 (delete-region (point) (progn (forward-line 1) (point))) | |
892 ;; Remove "." -> ".." encoding. | |
893 (while (search-forward "\n.." nil t) | |
894 (delete-char -1)))) | |
895 | |
896 (defun nntp-encode-text () | |
897 "Encode the text in the current buffer." | |
898 (save-excursion | |
899 ;; Replace "." at beginning of line with "..". | |
900 (goto-char (point-min)) | |
901 (while (re-search-forward "^\\." nil t) | |
902 (insert ".")) | |
903 (goto-char (point-max)) | |
904 ;; Insert newline at the end of the buffer. | |
905 (unless (bolp) | |
906 (insert "\n")) | |
907 ;; Insert `.' at end of buffer (end of text mark). | |
908 (goto-char (point-max)) | |
23010
196f32d1873f
(nntp-encode-text): Properly encode outgoing text by
Richard M. Stallman <rms@gnu.org>
parents:
20236
diff
changeset
|
909 (insert ".\n") |
196f32d1873f
(nntp-encode-text): Properly encode outgoing text by
Richard M. Stallman <rms@gnu.org>
parents:
20236
diff
changeset
|
910 (goto-char (point-min)) |
196f32d1873f
(nntp-encode-text): Properly encode outgoing text by
Richard M. Stallman <rms@gnu.org>
parents:
20236
diff
changeset
|
911 (while (not (eobp)) |
196f32d1873f
(nntp-encode-text): Properly encode outgoing text by
Richard M. Stallman <rms@gnu.org>
parents:
20236
diff
changeset
|
912 (end-of-line) |
196f32d1873f
(nntp-encode-text): Properly encode outgoing text by
Richard M. Stallman <rms@gnu.org>
parents:
20236
diff
changeset
|
913 (delete-char 1) |
196f32d1873f
(nntp-encode-text): Properly encode outgoing text by
Richard M. Stallman <rms@gnu.org>
parents:
20236
diff
changeset
|
914 (insert nntp-end-of-line)))) |
17493 | 915 |
916 (defun nntp-retrieve-headers-with-xover (articles &optional fetch-old) | |
917 (set-buffer nntp-server-buffer) | |
918 (erase-buffer) | |
919 (cond | |
920 | |
921 ;; This server does not talk NOV. | |
922 ((not nntp-server-xover) | |
923 nil) | |
924 | |
925 ;; We don't care about gaps. | |
926 ((or (not nntp-nov-gap) | |
927 fetch-old) | |
928 (nntp-send-xover-command | |
929 (if fetch-old | |
930 (if (numberp fetch-old) | |
931 (max 1 (- (car articles) fetch-old)) | |
932 1) | |
933 (car articles)) | |
934 (car (last articles)) 'wait) | |
935 | |
936 (goto-char (point-min)) | |
937 (when (looking-at "[1-5][0-9][0-9] ") | |
938 (delete-region (point) (progn (forward-line 1) (point)))) | |
939 (while (search-forward "\r" nil t) | |
940 (replace-match "" t t)) | |
941 (goto-char (point-max)) | |
942 (forward-line -1) | |
943 (when (looking-at "\\.") | |
944 (delete-region (point) (progn (forward-line 1) (point))))) | |
945 | |
946 ;; We do it the hard way. For each gap, an XOVER command is sent | |
947 ;; to the server. We do not wait for a reply from the server, we | |
948 ;; just send them off as fast as we can. That means that we have | |
949 ;; to count the number of responses we get back to find out when we | |
950 ;; have gotten all we asked for. | |
951 ((numberp nntp-nov-gap) | |
952 (let ((count 0) | |
953 (received 0) | |
954 (last-point (point-min)) | |
955 (buf nntp-server-buffer) | |
956 ;;(process-buffer (nntp-find-connection (current-buffer)))) | |
957 first) | |
958 ;; We have to check `nntp-server-xover'. If it gets set to nil, | |
959 ;; that means that the server does not understand XOVER, but we | |
960 ;; won't know that until we try. | |
961 (while (and nntp-server-xover articles) | |
962 (setq first (car articles)) | |
963 ;; Search forward until we find a gap, or until we run out of | |
964 ;; articles. | |
965 (while (and (cdr articles) | |
966 (< (- (nth 1 articles) (car articles)) nntp-nov-gap)) | |
967 (setq articles (cdr articles))) | |
968 | |
969 (when (nntp-send-xover-command first (car articles)) | |
970 (setq articles (cdr articles) | |
971 count (1+ count)) | |
972 | |
973 ;; Every 400 requests we have to read the stream in | |
974 ;; order to avoid deadlocks. | |
975 (when (or (null articles) ;All requests have been sent. | |
976 (zerop (% count nntp-maximum-request))) | |
977 (accept-process-output) | |
978 ;; On some Emacs versions the preceding function has | |
979 ;; a tendency to change the buffer. Perhaps. It's | |
980 ;; quite difficult to reproduce, because it only | |
981 ;; seems to happen once in a blue moon. | |
982 (set-buffer buf) | |
983 (while (progn | |
984 (goto-char last-point) | |
985 ;; Count replies. | |
986 (while (re-search-forward "^[0-9][0-9][0-9] " nil t) | |
987 (setq received (1+ received))) | |
988 (setq last-point (point)) | |
989 (< received count)) | |
990 (accept-process-output) | |
991 (set-buffer buf))))) | |
992 | |
993 (when nntp-server-xover | |
994 ;; Wait for the reply from the final command. | |
995 (goto-char (point-max)) | |
996 (re-search-backward "^[0-9][0-9][0-9] " nil t) | |
997 (when (looking-at "^[23]") | |
998 (while (progn | |
999 (goto-char (point-max)) | |
1000 (forward-line -1) | |
1001 (not (looking-at "^\\.\r?\n"))) | |
1002 (nntp-accept-response))) | |
1003 | |
1004 ;; We remove any "." lines and status lines. | |
1005 (goto-char (point-min)) | |
1006 (while (search-forward "\r" nil t) | |
1007 (delete-char -1)) | |
1008 (goto-char (point-min)) | |
1009 (delete-matching-lines "^\\.$\\|^[1-5][0-9][0-9] ") | |
1010 ;;(copy-to-buffer nntp-server-buffer (point-min) (point-max)) | |
1011 t)))) | |
1012 | |
1013 nntp-server-xover) | |
1014 | |
1015 (defun nntp-send-xover-command (beg end &optional wait-for-reply) | |
1016 "Send the XOVER command to the server." | |
1017 (let ((range (format "%d-%d" beg end)) | |
1018 (nntp-inhibit-erase t)) | |
1019 (if (stringp nntp-server-xover) | |
1020 ;; If `nntp-server-xover' is a string, then we just send this | |
1021 ;; command. | |
1022 (if wait-for-reply | |
1023 (nntp-send-command-nodelete | |
1024 "\r?\n\\.\r?\n" nntp-server-xover range) | |
1025 ;; We do not wait for the reply. | |
1026 (nntp-send-command-nodelete "\r?\n\\.\r?\n" nntp-server-xover range)) | |
1027 (let ((commands nntp-xover-commands)) | |
1028 ;; `nntp-xover-commands' is a list of possible XOVER commands. | |
1029 ;; We try them all until we get at positive response. | |
1030 (while (and commands (eq nntp-server-xover 'try)) | |
1031 (nntp-send-command-nodelete "\r?\n\\.\r?\n" (car commands) range) | |
1032 (save-excursion | |
1033 (set-buffer nntp-server-buffer) | |
1034 (goto-char (point-min)) | |
1035 (and (looking-at "[23]") ; No error message. | |
1036 ;; We also have to look at the lines. Some buggy | |
1037 ;; servers give back simple lines with just the | |
1038 ;; article number. How... helpful. | |
1039 (progn | |
1040 (forward-line 1) | |
1041 (looking-at "[0-9]+\t...")) ; More text after number. | |
1042 (setq nntp-server-xover (car commands)))) | |
1043 (setq commands (cdr commands))) | |
1044 ;; If none of the commands worked, we disable XOVER. | |
1045 (when (eq nntp-server-xover 'try) | |
1046 (save-excursion | |
1047 (set-buffer nntp-server-buffer) | |
1048 (erase-buffer) | |
1049 (setq nntp-server-xover nil))) | |
1050 nntp-server-xover)))) | |
1051 | |
1052 ;;; Alternative connection methods. | |
1053 | |
1054 (defun nntp-wait-for-string (regexp) | |
1055 "Wait until string arrives in the buffer." | |
1056 (let ((buf (current-buffer))) | |
1057 (goto-char (point-min)) | |
1058 (while (not (re-search-forward regexp nil t)) | |
1059 (accept-process-output (nntp-find-connection nntp-server-buffer)) | |
1060 (set-buffer buf) | |
1061 (goto-char (point-min))))) | |
1062 | |
1063 (defun nntp-open-telnet (buffer) | |
1064 (save-excursion | |
1065 (set-buffer buffer) | |
1066 (erase-buffer) | |
19969
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19598
diff
changeset
|
1067 (let ((proc (apply |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19598
diff
changeset
|
1068 'start-process |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19598
diff
changeset
|
1069 "nntpd" buffer nntp-telnet-command nntp-telnet-switches)) |
17493 | 1070 (case-fold-search t)) |
1071 (when (memq (process-status proc) '(open run)) | |
1072 (process-send-string proc "set escape \^X\n") | |
1073 (process-send-string proc (concat "open " nntp-address "\n")) | |
1074 (nntp-wait-for-string "^\r*.?login:") | |
1075 (process-send-string | |
1076 proc (concat | |
1077 (or nntp-telnet-user-name | |
1078 (setq nntp-telnet-user-name (read-string "login: "))) | |
1079 "\n")) | |
1080 (nntp-wait-for-string "^\r*.?password:") | |
1081 (process-send-string | |
1082 proc (concat | |
1083 (or nntp-telnet-passwd | |
1084 (setq nntp-telnet-passwd | |
1085 (nnmail-read-passwd "Password: "))) | |
1086 "\n")) | |
1087 (erase-buffer) | |
1088 (nntp-wait-for-string "bash\\|\$ *\r?$\\|> *\r?") | |
1089 (process-send-string | |
1090 proc (concat (mapconcat 'identity nntp-telnet-parameters " ") "\n")) | |
1091 (nntp-wait-for-string "^\r*200") | |
1092 (beginning-of-line) | |
1093 (delete-region (point-min) (point)) | |
1094 (process-send-string proc "\^]") | |
1095 (nntp-wait-for-string "^telnet") | |
1096 (process-send-string proc "mode character\n") | |
1097 (accept-process-output proc 1) | |
1098 (sit-for 1) | |
1099 (goto-char (point-min)) | |
1100 (forward-line 1) | |
1101 (delete-region (point) (point-max))) | |
1102 proc))) | |
1103 | |
1104 (defun nntp-open-rlogin (buffer) | |
1105 "Open a connection to SERVER using rsh." | |
1106 (let ((proc (if nntp-rlogin-user-name | |
1107 (start-process | |
1108 "nntpd" buffer "rsh" | |
1109 nntp-address "-l" nntp-rlogin-user-name | |
1110 (mapconcat 'identity | |
1111 nntp-rlogin-parameters " ")) | |
1112 (start-process | |
1113 "nntpd" buffer "rsh" nntp-address | |
1114 (mapconcat 'identity | |
1115 nntp-rlogin-parameters " "))))) | |
1116 (set-buffer buffer) | |
1117 (nntp-wait-for-string "^\r*200") | |
1118 (beginning-of-line) | |
1119 (delete-region (point-min) (point)) | |
1120 proc)) | |
1121 | |
1122 (defun nntp-find-group-and-number () | |
1123 (save-excursion | |
1124 (save-restriction | |
1125 (set-buffer nntp-server-buffer) | |
1126 (narrow-to-region (goto-char (point-min)) | |
1127 (or (search-forward "\n\n" nil t) (point-max))) | |
1128 (goto-char (point-min)) | |
1129 ;; We first find the number by looking at the status line. | |
1130 (let ((number (and (looking-at "2[0-9][0-9] +\\([0-9]+\\) ") | |
1131 (string-to-int | |
1132 (buffer-substring (match-beginning 1) | |
1133 (match-end 1))))) | |
1134 group newsgroups xref) | |
1135 (and number (zerop number) (setq number nil)) | |
1136 ;; Then we find the group name. | |
1137 (setq group | |
1138 (cond | |
1139 ;; If there is only one group in the Newsgroups header, | |
1140 ;; then it seems quite likely that this article comes | |
1141 ;; from that group, I'd say. | |
1142 ((and (setq newsgroups (mail-fetch-field "newsgroups")) | |
1143 (not (string-match "," newsgroups))) | |
1144 newsgroups) | |
1145 ;; If there is more than one group in the Newsgroups | |
1146 ;; header, then the Xref header should be filled out. | |
1147 ;; We hazard a guess that the group that has this | |
1148 ;; article number in the Xref header is the one we are | |
1149 ;; looking for. This might very well be wrong if this | |
1150 ;; article happens to have the same number in several | |
1151 ;; groups, but that's life. | |
1152 ((and (setq xref (mail-fetch-field "xref")) | |
1153 number | |
1154 (string-match (format "\\([^ :]+\\):%d" number) xref)) | |
1155 (substring xref (match-beginning 1) (match-end 1))) | |
1156 (t ""))) | |
1157 (when (string-match "\r" group) | |
1158 (setq group (substring group 0 (match-beginning 0)))) | |
1159 (cons group number))))) | |
1160 | |
1161 (provide 'nntp) | |
1162 | |
1163 ;;; nntp.el ends here |