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