annotate lisp/=nntp.el @ 612:68ef62058595

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