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