Mercurial > emacs
annotate lisp/=nntp.el @ 741:587f7a98341d
*** empty log message ***
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 05 Jul 1992 20:52:00 +0000 |
parents | 505130d1ddf8 |
children | 47ec7c4c42bc |
rev | line source |
---|---|
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
1 ;;; nntp.el --- NNTP (RFC977) Interface for GNU Emacs |
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
2 |
87 | 3 ;; Copyright (C) 1987, 1988, 1989 Fujitsu Laboratories LTD. |
4 ;; Copyright (C) 1987, 1988, 1989, 1990 Masanobu UMEDA | |
5 ;; $Header: nntp.el,v 3.10 90/03/23 13:25:27 umerin Locked $ | |
6 | |
7 ;; This file is part of GNU Emacs. | |
8 | |
9 ;; GNU Emacs is distributed in the hope that it will be useful, | |
10 ;; but WITHOUT ANY WARRANTY. No author or distributor | |
11 ;; accepts responsibility to anyone for the consequences of using it | |
12 ;; or for whether it serves any particular purpose or works at all, | |
13 ;; unless he says so in writing. Refer to the GNU Emacs General Public | |
14 ;; License for full details. | |
15 | |
16 ;; Everyone is granted permission to copy, modify and redistribute | |
17 ;; GNU Emacs, but only under the conditions described in the | |
18 ;; GNU Emacs General Public License. A copy of this license is | |
19 ;; supposed to have been given to you along with GNU Emacs so you | |
20 ;; can know your rights and responsibilities. It should be in a | |
21 ;; file named COPYING. Among other things, the copyright notice | |
22 ;; and this notice must be preserved on all copies. | |
23 | |
24 ;; This implementation is tested on both 1.2a and 1.5 version of the | |
25 ;; NNTP package. | |
26 | |
27 ;; Troubleshooting of NNTP | |
28 ;; | |
29 ;; (1) Select routine may signal an error or fall into infinite loop | |
30 ;; while waiting for the server response. In this case, you'd better | |
31 ;; not use byte-compiled codes but original source. If you still have | |
32 ;; a problems with it, set the variable `nntp-buggy-select' to T. | |
33 ;; | |
34 ;; (2) Emacs may hang up while retrieving headers since too many | |
35 ;; requests have been sent to the NNTP server without reading their | |
36 ;; replies. In this case, reduce the number of the requests sent to | |
37 ;; the server at one time by setting the variable | |
38 ;; `nntp-maximum-request' to a lower value. | |
39 ;; | |
40 ;; (3) If the TCP/IP stream (open-network-stream) is not supported by | |
41 ;; emacs, compile and install `tcp.el' and `tcp.c' which is an | |
42 ;; emulation program of the stream. If you modified `tcp.c' for your | |
43 ;; system, please send me the diffs. I'll include some of them in the | |
44 ;; future releases. | |
45 | |
46 (defvar nntp-server-hook nil | |
47 "*Hooks for the NNTP server. | |
48 If the kanji code of the NNTP server is different from the local kanji | |
49 code, the correct kanji code of the buffer associated with the NNTP | |
50 server must be specified as follows: | |
51 | |
52 (setq nntp-server-hook | |
53 '(lambda () | |
54 ;; Server's Kanji code is EUC (NEmacs hack). | |
55 (make-local-variable 'kanji-fileio-code) | |
56 (setq kanji-fileio-code 0))) | |
57 | |
58 If you'd like to change something depending on the server in this | |
59 hook, use the variable `nntp-server-name'.") | |
60 | |
61 (defvar nntp-buggy-select (memq system-type '(usg-unix-v fujitsu-uts)) | |
62 "*T if your select routine is buggy. | |
63 If the select routine signals error or fall into infinite loop while | |
64 waiting for the server response, the variable must be set to t. In | |
65 case of Fujitsu UTS, it is set to T since `accept-process-output' | |
66 doesn't work properly.") | |
67 | |
68 (defvar nntp-maximum-request 400 | |
69 "*The maximum number of the requests sent to the NNTP server at one time. | |
70 If Emacs hangs up while retrieving headers, set the variable to a | |
71 lower value.") | |
72 | |
73 (defvar nntp-large-newsgroup 50 | |
74 "*The number of the articles which indicates a large newsgroup. | |
75 If the number of the articles is greater than the value, verbose | |
76 messages will be shown to indicate the current status.") | |
77 | |
78 | |
79 (defconst nntp-version "NNTP 3.10" | |
80 "Version numbers of this version of NNTP.") | |
81 | |
82 (defvar nntp-server-name nil | |
83 "The name of the host running NNTP server.") | |
84 | |
85 (defvar nntp-server-buffer nil | |
86 "Buffer associated with NNTP server process.") | |
87 | |
88 (defvar nntp-server-process nil | |
89 "The NNTP server process. | |
90 You'd better not use this variable in NNTP front-end program but | |
91 instead use `nntp-server-buffer'.") | |
92 | |
93 (defvar nntp-status-message-string nil | |
94 "Save the server response message. | |
95 You'd better not use this variable in NNTP front-end program but | |
96 instead call function `nntp-status-message' to get status message.") | |
97 | |
98 ;;; | |
99 ;;; Extended Command for retrieving many headers. | |
100 ;;; | |
101 ;; Retrieving lots of headers by sending command asynchronously. | |
102 ;; Access functions to headers are defined as macro. | |
103 | |
104 (defmacro nntp-header-number (header) | |
105 "Return article number in HEADER." | |
106 (` (aref (, header) 0))) | |
107 | |
108 (defmacro nntp-set-header-number (header number) | |
109 "Set article number of HEADER to NUMBER." | |
110 (` (aset (, header) 0 (, number)))) | |
111 | |
112 (defmacro nntp-header-subject (header) | |
113 "Return subject string in HEADER." | |
114 (` (aref (, header) 1))) | |
115 | |
116 (defmacro nntp-set-header-subject (header subject) | |
117 "Set article subject of HEADER to SUBJECT." | |
118 (` (aset (, header) 1 (, subject)))) | |
119 | |
120 (defmacro nntp-header-from (header) | |
121 "Return author string in HEADER." | |
122 (` (aref (, header) 2))) | |
123 | |
124 (defmacro nntp-set-header-from (header from) | |
125 "Set article author of HEADER to FROM." | |
126 (` (aset (, header) 2 (, from)))) | |
127 | |
128 (defmacro nntp-header-xref (header) | |
129 "Return xref string in HEADER." | |
130 (` (aref (, header) 3))) | |
131 | |
132 (defmacro nntp-set-header-xref (header xref) | |
133 "Set article xref of HEADER to xref." | |
134 (` (aset (, header) 3 (, xref)))) | |
135 | |
136 (defmacro nntp-header-lines (header) | |
137 "Return lines in HEADER." | |
138 (` (aref (, header) 4))) | |
139 | |
140 (defmacro nntp-set-header-lines (header lines) | |
141 "Set article lines of HEADER to LINES." | |
142 (` (aset (, header) 4 (, lines)))) | |
143 | |
144 (defmacro nntp-header-date (header) | |
145 "Return date in HEADER." | |
146 (` (aref (, header) 5))) | |
147 | |
148 (defmacro nntp-set-header-date (header date) | |
149 "Set article date of HEADER to DATE." | |
150 (` (aset (, header) 5 (, date)))) | |
151 | |
152 (defmacro nntp-header-id (header) | |
153 "Return Id in HEADER." | |
154 (` (aref (, header) 6))) | |
155 | |
156 (defmacro nntp-set-header-id (header id) | |
157 "Set article Id of HEADER to ID." | |
158 (` (aset (, header) 6 (, id)))) | |
159 | |
160 (defmacro nntp-header-references (header) | |
161 "Return references in HEADER." | |
162 (` (aref (, header) 7))) | |
163 | |
164 (defmacro nntp-set-header-references (header ref) | |
165 "Set article references of HEADER to REF." | |
166 (` (aset (, header) 7 (, ref)))) | |
167 | |
168 (defun nntp-retrieve-headers (sequence) | |
169 "Return list of article headers specified by SEQUENCE of article id. | |
170 The format of list is | |
171 `([NUMBER SUBJECT FROM XREF LINES DATE MESSAGE-ID REFERENCES] ...)'. | |
172 Reader macros for the vector are defined as `nntp-header-FIELD'. | |
173 Writer macros for the vector are defined as `nntp-set-header-FIELD'. | |
174 News group must be selected before calling me." | |
175 (save-excursion | |
176 (set-buffer nntp-server-buffer) | |
177 (erase-buffer) | |
178 (let ((number (length sequence)) | |
179 (last-point (point-min)) | |
180 (received 0) | |
181 (count 0) | |
182 (headers nil) ;Result list. | |
183 (article 0) | |
184 (subject nil) | |
185 (message-id) | |
186 (from nil) | |
187 (xref nil) | |
188 (lines 0) | |
189 (date nil) | |
190 (references nil)) | |
191 ;; Send HEAD command. | |
192 (while sequence | |
193 (nntp-send-strings-to-server "HEAD" (car sequence)) | |
194 (setq sequence (cdr sequence)) | |
195 (setq count (1+ count)) | |
196 ;; Every 400 header requests we have to read stream in order | |
197 ;; to avoid deadlock. | |
198 (if (or (null sequence) ;All requests have been sent. | |
199 (zerop (% count nntp-maximum-request))) | |
200 (progn | |
201 (accept-process-output) | |
202 (while (progn | |
203 (goto-char last-point) | |
204 ;; Count replies. | |
205 (while (re-search-forward "^[0-9]" nil t) | |
206 (setq received (1+ received))) | |
207 (setq last-point (point)) | |
208 (< received count)) | |
209 ;; If number of headers is greater than 100, give | |
210 ;; informative messages. | |
211 (and (numberp nntp-large-newsgroup) | |
212 (> number nntp-large-newsgroup) | |
213 (zerop (% received 20)) | |
214 (message "NNTP: %d%% of headers received." | |
215 (/ (* received 100) number))) | |
216 (nntp-accept-response)) | |
217 )) | |
218 ) | |
219 ;; Wait for text of last command. | |
220 (goto-char (point-max)) | |
221 (re-search-backward "^[0-9]" nil t) | |
222 (if (looking-at "^[23]") | |
223 (while (progn | |
224 (goto-char (- (point-max) 3)) | |
225 (not (looking-at "^\\.\r$"))) | |
226 (nntp-accept-response))) | |
227 (and (numberp nntp-large-newsgroup) | |
228 (> number nntp-large-newsgroup) | |
229 (message "NNTP: 100%% of headers received.")) | |
230 ;; Now all of replies are received. | |
231 (setq received number) | |
232 ;; First, fold continuation lines. | |
233 (goto-char (point-min)) | |
234 (while (re-search-forward "\\(\r?\n[ \t]+\\)+" nil t) | |
235 (replace-match " " t t)) | |
236 ;;(delete-non-matching-lines | |
237 ;; "^Subject:\\|^Xref:\\|^From:\\|^Lines:\\|^Date:\\|^References:\\|^[23]") | |
238 (and (numberp nntp-large-newsgroup) | |
239 (> number nntp-large-newsgroup) | |
240 (message "NNTP: Parsing headers...")) | |
241 ;; Then examines replies. | |
242 (goto-char (point-min)) | |
243 (while (not (eobp)) | |
244 (cond ((looking-at "^[23][0-9][0-9][ \t]+\\([0-9]+\\)[ \t]+\\(<[^>]+>\\)") | |
245 (setq article | |
246 (string-to-int | |
247 (buffer-substring (match-beginning 1) (match-end 1)))) | |
248 (setq message-id | |
249 (buffer-substring (match-beginning 2) (match-end 2))) | |
250 (forward-line 1) | |
251 ;; Set default value. | |
252 (setq subject nil) | |
253 (setq xref nil) | |
254 (setq from nil) | |
255 (setq lines 0) | |
256 (setq date nil) | |
257 (setq references nil) | |
258 ;; Thanks go to mly@AI.MIT.EDU (Richard Mlynarik) | |
259 (while (and (not (eobp)) | |
260 (not (memq (following-char) '(?2 ?3)))) | |
261 (if (looking-at "\\(From\\|Subject\\|Date\\|Lines\\|Xref\\|References\\):[ \t]+\\([^ \t\n]+.*\\)\r$") | |
262 (let ((s (buffer-substring | |
263 (match-beginning 2) (match-end 2))) | |
264 (c (char-after (match-beginning 0)))) | |
265 ;; We don't have to worry about letter case. | |
266 (cond ((char-equal c ?F) ;From: | |
267 (setq from s)) | |
268 ((char-equal c ?S) ;Subject: | |
269 (setq subject s)) | |
270 ((char-equal c ?D) ;Date: | |
271 (setq date s)) | |
272 ((char-equal c ?L) ;Lines: | |
273 (setq lines (string-to-int s))) | |
274 ((char-equal c ?X) ;Xref: | |
275 (setq xref s)) | |
276 ((char-equal c ?R) ;References: | |
277 (setq references s)) | |
278 ))) | |
279 (forward-line 1)) | |
280 ;; Finished to parse one header. | |
281 (if (null subject) | |
282 (setq subject "(None)")) | |
283 (if (null from) | |
284 (setq from "(Unknown User)")) | |
285 (setq headers | |
286 (cons (vector article subject from | |
287 xref lines date | |
288 message-id references) headers)) | |
289 ) | |
290 (t (forward-line 1)) | |
291 ) | |
292 (setq received (1- received)) | |
293 (and (numberp nntp-large-newsgroup) | |
294 (> number nntp-large-newsgroup) | |
295 (zerop (% received 20)) | |
296 (message "NNTP: Parsing headers... %d%%" | |
297 (/ (* received 100) number))) | |
298 ) | |
299 (and (numberp nntp-large-newsgroup) | |
300 (> number nntp-large-newsgroup) | |
301 (message "NNTP: Parsing headers... done")) | |
302 (nreverse headers) | |
303 ))) | |
304 | |
305 | |
306 ;;; | |
307 ;;; Raw Interface to Network News Transfer Protocol (RFC977). | |
308 ;;; | |
309 | |
310 (defun nntp-open-server (host &optional service) | |
311 "Open news server on HOST. | |
312 If HOST is nil, use value of environment variable `NNTPSERVER'. | |
313 If optional argument SERVICE is non-nil, open by the service name." | |
314 (let ((host (or host (getenv "NNTPSERVER"))) | |
315 (status nil)) | |
316 (setq nntp-status-message-string "") | |
317 (cond ((and host (nntp-open-server-internal host service)) | |
318 (setq status (nntp-wait-for-response "^[23].*\r$")) | |
319 ;; Do check unexpected close of connection. | |
320 ;; Suggested by feldmark@hanako.stars.flab.fujitsu.junet. | |
321 (if status | |
322 (set-process-sentinel nntp-server-process | |
323 'nntp-default-sentinel) | |
324 ;; We have to close connection here, since function | |
325 ;; `nntp-server-opened' may return incorrect status. | |
326 (nntp-close-server-internal) | |
327 )) | |
328 ((null host) | |
329 (setq nntp-status-message-string "NNTP server is not specified.")) | |
330 ) | |
331 status | |
332 )) | |
333 | |
334 (defun nntp-close-server () | |
335 "Close news server." | |
336 (unwind-protect | |
337 (progn | |
338 ;; Un-set default sentinel function before closing connection. | |
339 (and nntp-server-process | |
340 (eq 'nntp-default-sentinel | |
341 (process-sentinel nntp-server-process)) | |
342 (set-process-sentinel nntp-server-process nil)) | |
343 ;; We cannot send QUIT command unless the process is running. | |
344 (if (nntp-server-opened) | |
345 (nntp-send-command nil "QUIT")) | |
346 ) | |
347 (nntp-close-server-internal) | |
348 )) | |
349 | |
350 (fset 'nntp-request-quit (symbol-function 'nntp-close-server)) | |
351 | |
352 (defun nntp-server-opened () | |
353 "Return server process status, T or NIL. | |
354 If the stream is opened, return T, otherwise return NIL." | |
355 (and nntp-server-process | |
356 (memq (process-status nntp-server-process) '(open run)))) | |
357 | |
358 (defun nntp-status-message () | |
359 "Return server status response as string." | |
360 (if (and nntp-status-message-string | |
361 ;; NNN MESSAGE | |
362 (string-match "[0-9][0-9][0-9][ \t]+\\([^\r]*\\).*$" | |
363 nntp-status-message-string)) | |
364 (substring nntp-status-message-string (match-beginning 1) (match-end 1)) | |
365 ;; Empty message if nothing. | |
366 "" | |
367 )) | |
368 | |
369 (defun nntp-request-article (id) | |
370 "Select article by message ID (or number)." | |
371 (prog1 | |
372 ;; If NEmacs, end of message may look like: "\256\215" (".^M") | |
373 (nntp-send-command "^\\.\r$" "ARTICLE" id) | |
374 (nntp-decode-text) | |
375 )) | |
376 | |
377 (defun nntp-request-body (id) | |
378 "Select article body by message ID (or number)." | |
379 (prog1 | |
380 ;; If NEmacs, end of message may look like: "\256\215" (".^M") | |
381 (nntp-send-command "^\\.\r$" "BODY" id) | |
382 (nntp-decode-text) | |
383 )) | |
384 | |
385 (defun nntp-request-head (id) | |
386 "Select article head by message ID (or number)." | |
387 (prog1 | |
388 (nntp-send-command "^\\.\r$" "HEAD" id) | |
389 (nntp-decode-text) | |
390 )) | |
391 | |
392 (defun nntp-request-stat (id) | |
393 "Select article by message ID (or number)." | |
394 (nntp-send-command "^[23].*\r$" "STAT" id)) | |
395 | |
396 (defun nntp-request-group (group) | |
397 "Select news GROUP." | |
398 ;; 1.2a NNTP's group command is buggy. "^M" (\r) is not appended to | |
399 ;; end of the status message. | |
400 (nntp-send-command "^[23].*$" "GROUP" group)) | |
401 | |
402 (defun nntp-request-list () | |
403 "List valid newsgoups." | |
404 (prog1 | |
405 (nntp-send-command "^\\.\r$" "LIST") | |
406 (nntp-decode-text) | |
407 )) | |
408 | |
409 (defun nntp-request-last () | |
232 | 410 "Set current article pointer to the previous article in the current news group." |
87 | 411 (nntp-send-command "^[23].*\r$" "LAST")) |
412 | |
413 (defun nntp-request-next () | |
414 "Advance current article pointer." | |
415 (nntp-send-command "^[23].*\r$" "NEXT")) | |
416 | |
417 (defun nntp-request-post () | |
418 "Post a new news in current buffer." | |
419 (if (nntp-send-command "^[23].*\r$" "POST") | |
420 (progn | |
421 (nntp-encode-text) | |
422 (nntp-send-region-to-server (point-min) (point-max)) | |
423 ;; 1.2a NNTP's post command is buggy. "^M" (\r) is not | |
424 ;; appended to end of the status message. | |
425 (nntp-wait-for-response "^[23].*$") | |
426 ))) | |
427 | |
428 (defun nntp-default-sentinel (proc status) | |
429 "Default sentinel function for NNTP server process." | |
430 (if (and nntp-server-process | |
431 (not (nntp-server-opened))) | |
432 (error "NNTP: Connection closed.") | |
433 )) | |
434 | |
435 ;; Encoding and decoding of NNTP text. | |
436 | |
437 (defun nntp-decode-text () | |
438 "Decode text transmitted by NNTP. | |
439 0. Delete status line. | |
440 1. Delete `^M' at end of line. | |
441 2. Delete `.' at end of buffer (end of text mark). | |
442 3. Delete `.' at beginning of line." | |
443 (save-excursion | |
444 (set-buffer nntp-server-buffer) | |
445 ;; Insert newline at end of buffer. | |
446 (goto-char (point-max)) | |
447 (if (not (bolp)) | |
448 (insert "\n")) | |
449 ;; Delete status line. | |
450 (goto-char (point-min)) | |
451 (delete-region (point) (progn (forward-line 1) (point))) | |
452 ;; Delete `^M' at end of line. | |
453 ;; (replace-regexp "\r$" "") | |
454 (while (not (eobp)) | |
455 (end-of-line) | |
456 (if (= (preceding-char) ?\r) | |
457 (delete-char -1)) | |
458 (forward-line 1) | |
459 ) | |
460 ;; Delete `.' at end of buffer (end of text mark). | |
461 (goto-char (point-max)) | |
462 (forward-line -1) ;(beginning-of-line) | |
463 (if (looking-at "^\\.$") | |
464 (delete-region (point) (progn (forward-line 1) (point)))) | |
465 ;; Replace `..' at beginning of line with `.'. | |
466 (goto-char (point-min)) | |
467 ;; (replace-regexp "^\\.\\." ".") | |
468 (while (search-forward "\n.." nil t) | |
469 (delete-char -1)) | |
470 )) | |
471 | |
472 (defun nntp-encode-text () | |
473 "Encode text in current buffer for NNTP transmission. | |
474 1. Insert `.' at beginning of line. | |
475 2. Insert `.' at end of buffer (end of text mark)." | |
476 (save-excursion | |
477 ;; Insert newline at end of buffer. | |
478 (goto-char (point-max)) | |
479 (if (not (bolp)) | |
480 (insert "\n")) | |
481 ;; Replace `.' at beginning of line with `..'. | |
482 (goto-char (point-min)) | |
483 ;; (replace-regexp "^\\." "..") | |
484 (while (search-forward "\n." nil t) | |
485 (insert ".")) | |
486 ;; Insert `.' at end of buffer (end of text mark). | |
487 (goto-char (point-max)) | |
488 (insert ".\n") | |
489 )) | |
490 | |
491 | |
492 ;;; | |
493 ;;; Synchronous Communication with NNTP Server. | |
494 ;;; | |
495 | |
496 (defun nntp-send-command (response cmd &rest args) | |
497 "Wait for server RESPONSE after sending CMD and optional ARGS to server." | |
498 (save-excursion | |
499 ;; Clear communication buffer. | |
500 (set-buffer nntp-server-buffer) | |
501 (erase-buffer) | |
502 (apply 'nntp-send-strings-to-server cmd args) | |
503 (if response | |
504 (nntp-wait-for-response response) | |
505 t) | |
506 )) | |
507 | |
508 (defun nntp-wait-for-response (regexp) | |
509 "Wait for server response which matches REGEXP." | |
510 (save-excursion | |
511 (let ((status t) | |
512 (wait t)) | |
513 (set-buffer nntp-server-buffer) | |
514 ;; Wait for status response (RFC977). | |
515 ;; 1xx - Informative message. | |
516 ;; 2xx - Command ok. | |
517 ;; 3xx - Command ok so far, send the rest of it. | |
518 ;; 4xx - Command was correct, but couldn't be performed for some | |
519 ;; reason. | |
520 ;; 5xx - Command unimplemented, or incorrect, or a serious | |
521 ;; program error occurred. | |
522 (nntp-accept-response) | |
523 (while wait | |
524 (goto-char (point-min)) | |
525 (cond ((looking-at "[23]") | |
526 (setq wait nil)) | |
527 ((looking-at "[45]") | |
528 (setq status nil) | |
529 (setq wait nil)) | |
530 (t (nntp-accept-response)) | |
531 )) | |
532 ;; Save status message. | |
533 (end-of-line) | |
534 (setq nntp-status-message-string | |
535 (buffer-substring (point-min) (point))) | |
536 (if status | |
537 (progn | |
538 (setq wait t) | |
539 (while wait | |
540 (goto-char (point-max)) | |
541 (forward-line -1) ;(beginning-of-line) | |
542 ;;(message (buffer-substring | |
543 ;; (point) | |
544 ;; (save-excursion (end-of-line) (point)))) | |
545 (if (looking-at regexp) | |
546 (setq wait nil) | |
547 (message "NNTP: Reading...") | |
548 (nntp-accept-response) | |
549 (message "") | |
550 )) | |
551 ;; Successfully received server response. | |
552 t | |
553 )) | |
554 ))) | |
555 | |
556 | |
557 ;;; | |
558 ;;; Low-Level Interface to NNTP Server. | |
559 ;;; | |
560 | |
561 (defun nntp-send-strings-to-server (&rest strings) | |
562 "Send list of STRINGS to news server as command and its arguments." | |
563 (let ((cmd (car strings)) | |
564 (strings (cdr strings))) | |
565 ;; Command and each argument must be separeted by one or more spaces. | |
566 (while strings | |
567 (setq cmd (concat cmd " " (car strings))) | |
568 (setq strings (cdr strings))) | |
569 ;; Command line must be terminated by a CR-LF. | |
570 (process-send-string nntp-server-process (concat cmd "\n")) | |
571 )) | |
572 | |
573 (defun nntp-send-region-to-server (begin end) | |
574 "Send current buffer region (from BEGIN to END) to news server." | |
575 (save-excursion | |
576 ;; We have to work in the buffer associated with NNTP server | |
577 ;; process because of NEmacs hack. | |
578 (copy-to-buffer nntp-server-buffer begin end) | |
579 (set-buffer nntp-server-buffer) | |
580 (setq begin (point-min)) | |
581 (setq end (point-max)) | |
582 ;; `process-send-region' does not work if text to be sent is very | |
583 ;; large. I don't know maximum size of text sent correctly. | |
584 (let ((last nil) | |
585 (size 100)) ;Size of text sent at once. | |
586 (save-restriction | |
587 (narrow-to-region begin end) | |
588 (goto-char begin) | |
589 (while (not (eobp)) | |
590 ;;(setq last (min end (+ (point) size))) | |
591 ;; NEmacs gets confused if character at `last' is Kanji. | |
592 (setq last (save-excursion | |
593 (goto-char (min end (+ (point) size))) | |
594 (or (eobp) (forward-char 1)) ;Adjust point | |
595 (point))) | |
596 (process-send-region nntp-server-process (point) last) | |
597 ;; I don't know whether the next codes solve the known | |
598 ;; problem of communication error of GNU Emacs. | |
599 (accept-process-output) | |
600 ;;(sit-for 0) | |
601 (goto-char last) | |
602 ))) | |
603 ;; We cannot erase buffer, because reply may be received. | |
604 (delete-region begin end) | |
605 )) | |
606 | |
607 (defun nntp-open-server-internal (host &optional service) | |
608 "Open connection to news server on HOST by SERVICE (default is nntp)." | |
609 (save-excursion | |
610 ;; Use TCP/IP stream emulation package if needed. | |
611 (or (fboundp 'open-network-stream) | |
612 (require 'tcp)) | |
613 ;; Initialize communication buffer. | |
614 (setq nntp-server-buffer (get-buffer-create " *nntpd*")) | |
615 (set-buffer nntp-server-buffer) | |
616 (buffer-flush-undo (current-buffer)) | |
617 (erase-buffer) | |
618 (kill-all-local-variables) | |
619 (setq case-fold-search t) ;Should ignore case. | |
620 (setq nntp-server-process | |
621 (open-network-stream "nntpd" (current-buffer) | |
622 host (or service "nntp"))) | |
623 (setq nntp-server-name host) | |
624 ;; It is possible to change kanji-fileio-code in this hook. | |
625 (run-hooks 'nntp-server-hook) | |
626 ;; Return the server process. | |
627 nntp-server-process | |
628 )) | |
629 | |
630 (defun nntp-close-server-internal () | |
631 "Close connection to news server." | |
632 (if nntp-server-process | |
633 (delete-process nntp-server-process)) | |
634 (if nntp-server-buffer | |
635 (kill-buffer nntp-server-buffer)) | |
636 (setq nntp-server-buffer nil) | |
637 (setq nntp-server-process nil)) | |
638 | |
639 (defun nntp-accept-response () | |
640 "Read response of server. | |
641 It is well-known that the communication speed will be much improved by | |
642 defining this function as macro." | |
643 ;; To deal with server process exiting before | |
644 ;; accept-process-output is called. | |
645 ;; Suggested by Jason Venner <jason@violet.berkeley.edu>. | |
646 ;; This is a copy of `nntp-default-sentinel'. | |
647 (or (memq (process-status nntp-server-process) '(open run)) | |
648 (error "NNTP: Connection closed.")) | |
649 (if nntp-buggy-select | |
650 (progn | |
651 ;; We cannot use `accept-process-output'. | |
652 ;; Fujitsu UTS requires messages during sleep-for. I don't know why. | |
653 (message "NNTP: Reading...") | |
654 (sleep-for 1) | |
655 (message "")) | |
656 (condition-case errorcode | |
657 (accept-process-output nntp-server-process) | |
658 (error | |
659 (cond ((string-equal "select error: Invalid argument" (nth 1 errorcode)) | |
660 ;; Ignore select error. | |
661 nil | |
662 ) | |
663 (t | |
664 (signal (car errorcode) (cdr errorcode)))) | |
665 )) | |
666 )) | |
584 | 667 |
668 (provide 'nntp) | |
669 | |
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
670 ;;; nntp.el ends here |