annotate lisp/gnus/nntp.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children ac2d302a0011
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; nntp.el --- nntp access for Gnus
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;; Copyright (C) 1987,88,89,90,92,93,94,95,96 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Keywords: news
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;; Boston, MA 02111-1307, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 (require 'nnheader)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 (require 'nnoo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 (eval-when-compile (require 'cl))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 (nnoo-declare nntp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 (eval-and-compile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 (unless (fboundp 'open-network-stream)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 (require 'tcp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (eval-when-compile (require 'cl))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (eval-and-compile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (autoload 'cancel-timer "timer")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 (autoload 'telnet "telnet" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (autoload 'telnet-send-input "telnet" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (autoload 'timezone-parse-date "timezone"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (defvoo nntp-server-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 "*Hooks for the NNTP server.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 If the kanji code of the NNTP server is different from the local kanji
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 code, the correct kanji code of the buffer associated with the NNTP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 server must be specified as follows:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 \(setq nntp-server-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;; Server's Kanji code is EUC (NEmacs hack).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (make-local-variable 'kanji-fileio-code)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (setq kanji-fileio-code 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 If you'd like to change something depending on the server in this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 hook, use the variable `nntp-address'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (defvoo nntp-server-opened-hook '(nntp-send-mode-reader)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 "*Hook used for sending commands to the server at startup.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 The default value is `nntp-send-mode-reader', which makes an innd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 server spawn an nnrpd server. Another useful function to put in this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 hook might be `nntp-send-authinfo', which will prompt for a password
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 to allow posting from the server. Note that this is only necessary to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 do on servers that use strict access control.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (add-hook 'nntp-server-opened-hook 'nntp-send-mode-reader)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (defvoo nntp-server-action-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 '(("nntpd 1\\.5\\.11t"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (remove-hook 'nntp-server-opened-hook 'nntp-send-mode-reader)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 "Alist of regexps to match on server types and actions to be taken.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 For instance, if you want Gnus to beep every time you connect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 to innd, you could say something like:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 \(setq nntp-server-action-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 '((\"innd\" (ding))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 You probably don't want to do that, though.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (defvoo nntp-open-server-function 'nntp-open-network-stream
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 "*Function used for connecting to a remote system.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 It will be called with the address of the remote system.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 Two pre-made functions are `nntp-open-network-stream', which is the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 default, and simply connects to some port or other on the remote
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 system (see nntp-port-number). The other is `nntp-open-rlogin', which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 does an rlogin on the remote system, and then does a telnet to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 NNTP server available there (see nntp-rlogin-parameters).")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (defvoo nntp-rlogin-parameters '("telnet" "${NNTPSERVER:=localhost}" "nntp")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 "*Parameters to `nntp-open-login'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 That function may be used as `nntp-open-server-function'. In that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 case, this list will be used as the parameter list given to rsh.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (defvoo nntp-rlogin-user-name nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 "*User name on remote system when using the rlogin connect method.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (defvoo nntp-address nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 "*The name of the NNTP server.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (defvoo nntp-port-number "nntp"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 "*Port number to connect to.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (defvoo nntp-end-of-line "\r\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 "String to use on the end of lines when talking to the NNTP server.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 This is \"\\r\\n\" by default, but should be \"\\n\" when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 using rlogin to communicate with the server.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (defvoo nntp-large-newsgroup 50
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 "*The number of the articles which indicates a large newsgroup.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 If the number of the articles is greater than the value, verbose
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 messages will be shown to indicate the current status.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (defvoo nntp-buggy-select (memq system-type '(fujitsu-uts))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 "*t if your select routine is buggy.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 If the select routine signals error or fall into infinite loop while
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 waiting for the server response, the variable must be set to t. In
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 case of Fujitsu UTS, it is set to T since `accept-process-output'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 doesn't work properly.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (defvoo nntp-maximum-request 400
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 "*The maximum number of the requests sent to the NNTP server at one time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 If Emacs hangs up while retrieving headers, set the variable to a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 lower value.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (defvoo nntp-debug-read 10000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 "*Display '...' every 10Kbytes of a message being received if it is non-nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 If it is a number, dots are displayed per the number.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (defvoo nntp-nov-is-evil nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 "*If non-nil, nntp will never attempt to use XOVER when talking to the server.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (defvoo nntp-xover-commands '("XOVER" "XOVERVIEW")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 "*List of strings that are used as commands to fetch NOV lines from a server.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 The strings are tried in turn until a positive response is gotten. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 none of the commands are successful, nntp will just grab headers one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 by one.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (defvoo nntp-nov-gap 20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 "*Maximum allowed gap between two articles.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 If the gap between two consecutive articles is bigger than this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 variable, split the XOVER request into two requests.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (defvoo nntp-connection-timeout nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 "*Number of seconds to wait before an nntp connection times out.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 If this variable is nil, which is the default, no timers are set.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (defvoo nntp-command-timeout nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 "*Number of seconds to wait for a response when sending a command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 If this variable is nil, which is the default, no timers are set.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (defvoo nntp-retry-on-break nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 "*If non-nil, re-send the command when the user types `C-g'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (defvoo nntp-news-default-headers nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 "*If non-nil, override `mail-default-headers' when posting news.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (defvoo nntp-prepare-server-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 "*Hook run before a server is opened.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 If can be used to set up a server remotely, for instance. Say you
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 have an account at the machine \"other.machine\". This machine has
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 access to an NNTP server that you can't access locally. You could
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 then use this hook to rsh to the remote machine and start a proxy NNTP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 server there that you can connect to.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (defvoo nntp-async-number 5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 "*How many articles should be prefetched when in asynchronous mode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (defvoo nntp-warn-about-losing-connection t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 "*If non-nil, beep when a server closes connection.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (defconst nntp-version "nntp 4.0"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 "Version numbers of this version of NNTP.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (defvar nntp-server-buffer nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 "Buffer associated with the NNTP server process.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (defvoo nntp-server-process nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 "The NNTP server process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 You'd better not use this variable in NNTP front-end program, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 instead use `nntp-server-buffer'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (defvoo nntp-status-string nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 "Save the server response message.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (defvar nntp-opened-connections nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 "All (possibly) opened connections.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (defvoo nntp-server-xover 'try)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (defvoo nntp-server-list-active-group 'try)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (defvoo nntp-current-group "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (defvoo nntp-server-type nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (defvoo nntp-async-process nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (defvoo nntp-async-buffer nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (defvoo nntp-async-articles nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (defvoo nntp-async-fetched nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (defvoo nntp-async-group-alist nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 ;;; Interface functions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (nnoo-define-basics nntp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (deffoo nntp-retrieve-headers (articles &optional group server fetch-old)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 "Retrieve the headers of ARTICLES."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (nntp-possibly-change-server group server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (set-buffer nntp-server-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (if (and (not gnus-nov-is-evil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (not nntp-nov-is-evil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (nntp-retrieve-headers-with-xover articles fetch-old))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 ;; We successfully retrieved the headers via XOVER.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 'nov
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 ;; XOVER didn't work, so we do it the hard, slow and inefficient
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 ;; way.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (let ((number (length articles))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (received 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (message-log-max nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (last-point (point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 ;; Send HEAD command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (while articles
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (nntp-send-strings-to-server
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 "HEAD" (if (numberp (car articles))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (int-to-string (car articles))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 ;; `articles' is either a list of article numbers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 ;; or a list of article IDs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (car articles)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (setq articles (cdr articles)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 count (1+ count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 ;; Every 400 header requests we have to read the stream in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 ;; order to avoid deadlocks.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (when (or (null articles) ;All requests have been sent.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (zerop (% count nntp-maximum-request)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (nntp-accept-response)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (while (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (goto-char last-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 ;; Count replies.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (while (re-search-forward "^[0-9]" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (setq received (1+ received)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (setq last-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (< received count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 ;; If number of headers is greater than 100, give
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 ;; informative messages.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (and (numberp nntp-large-newsgroup)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (> number nntp-large-newsgroup)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (zerop (% received 20))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (nnheader-message 7 "NNTP: Receiving headers... %d%%"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (/ (* received 100) number)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (nntp-accept-response))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 ;; Wait for text of last command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (re-search-backward "^[0-9]" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (when (looking-at "^[23]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (while (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (goto-char (- (point-max) 3))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (not (looking-at "^\\.\r?\n")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (nntp-accept-response)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (and (numberp nntp-large-newsgroup)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (> number nntp-large-newsgroup)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (nnheader-message 7 "NNTP: Receiving headers...done"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 ;; Now all of replies are received. Fold continuation lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (nnheader-fold-continuation-lines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 ;; Remove all "\r"'s.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (while (search-forward "\r" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (replace-match "" t t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 'headers))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (deffoo nntp-retrieve-groups (groups &optional server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 "Retrieve group info on GROUPS."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (nntp-possibly-change-server nil server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (set-buffer nntp-server-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 ;; The first time this is run, this variable is `try'. So we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 ;; try.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (when (eq nntp-server-list-active-group 'try)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (nntp-try-list-active (car groups)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (let ((count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (received 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (last-point (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (command (if nntp-server-list-active-group "LIST ACTIVE" "GROUP")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (while groups
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 ;; Send the command to the server.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (nntp-send-strings-to-server command (car groups))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (setq groups (cdr groups))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (setq count (1+ count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 ;; Every 400 requests we have to read the stream in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 ;; order to avoid deadlocks.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (when (or (null groups) ;All requests have been sent.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (zerop (% count nntp-maximum-request)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (nntp-accept-response)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (while (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (goto-char last-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 ;; Count replies.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (while (re-search-forward "^[0-9]" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (setq received (1+ received)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (setq last-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (< received count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (nntp-accept-response))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 ;; Wait for the reply from the final command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (when nntp-server-list-active-group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (re-search-backward "^[0-9]" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (when (looking-at "^[23]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (while (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (goto-char (- (point-max) 3))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 (not (looking-at "^\\.\r?\n")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 (nntp-accept-response))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 ;; Now all replies are received. We remove CRs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (while (search-forward "\r" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (replace-match "" t t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (if (not nntp-server-list-active-group)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 'group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 ;; We have read active entries, so we just delete the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 ;; superfluos gunk.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (while (re-search-forward "^[.2-5]" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (delete-region (match-beginning 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (progn (forward-line 1) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 'active))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (deffoo nntp-open-server (server &optional defs connectionless)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 "Open the virtual server SERVER.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 If CONNECTIONLESS is non-nil, don't attempt to connect to any physical
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 servers."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 ;; Called with just a port number as the defs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (when (or (stringp (car defs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (numberp (car defs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (setq defs `((nntp-port-number ,(car defs)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (unless (assq 'nntp-address defs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (setq defs (append defs `((nntp-address ,server)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (nnoo-change-server 'nntp server defs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (if (nntp-server-opened server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (or (nntp-server-opened server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 connectionless
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 (prog2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (run-hooks 'nntp-prepare-server-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (nntp-open-server-semi-internal nntp-address nntp-port-number)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 (nnheader-insert "")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (deffoo nntp-close-server (&optional server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 "Close connection to SERVER."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (nntp-possibly-change-server nil server t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 ;; Un-set default sentinel function before closing connection.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 (and nntp-server-process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 (eq 'nntp-default-sentinel
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (process-sentinel nntp-server-process))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 (set-process-sentinel nntp-server-process nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 ;; We cannot send QUIT command unless the process is running.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 (when (nntp-server-opened server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 (nntp-send-command nil "QUIT")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 ;; Give the QUIT time to arrive.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 (sleep-for 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 (nntp-close-server-internal server)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (deffoo nntp-request-close ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 "Close all server connections."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 (let (proc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 (while nntp-opened-connections
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 (when (setq proc (pop nntp-opened-connections))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 ;; Un-set default sentinel function before closing connection.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 (when (eq 'nntp-default-sentinel (process-sentinel proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 (set-process-sentinel proc nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 (process-send-string proc (concat "QUIT" nntp-end-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 (error nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 ;; Give the QUIT time to reach the server before we close
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 ;; down the process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 (sleep-for 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (delete-process proc)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 (and nntp-async-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 (buffer-name nntp-async-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 (kill-buffer nntp-async-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (let ((alist (cddr (assq 'nntp nnoo-state-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 (while (setq entry (pop alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 (and (setq proc (cdr (assq 'nntp-async-buffer entry)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 (buffer-name proc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 (kill-buffer proc))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 (nnoo-close-server 'nntp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 (setq nntp-async-group-alist nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 (deffoo nntp-server-opened (&optional server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 "Say whether a connection to SERVER has been opened."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (and (nnoo-current-server-p 'nntp server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 nntp-server-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 (buffer-name nntp-server-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 nntp-server-process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 (memq (process-status nntp-server-process) '(open run))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (deffoo nntp-status-message (&optional server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 "Return server status as a string."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (if (and nntp-status-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 ;; NNN MESSAGE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 (string-match "[0-9][0-9][0-9][ \t]+\\([^\r]*\\).*$"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 nntp-status-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 (substring nntp-status-string (match-beginning 1) (match-end 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 ;; Empty message if nothing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 (or nntp-status-string "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (deffoo nntp-request-article (id &optional group server buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 "Request article ID (Message-ID or number)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 (nntp-possibly-change-server group server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (let (found)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 ;; First we see whether we can get the article from the async buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (when (and (numberp id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 nntp-async-articles
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 (memq id nntp-async-fetched))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 (set-buffer nntp-async-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (let ((opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 (art (if (numberp id) (int-to-string id) id))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (when (and (or (re-search-forward (concat "^2.. +" art) nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (re-search-forward (concat "^2.. +" art) opoint t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 (setq beg (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 end (re-search-forward "^\\.\r?\n" nil t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 (setq found t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 (set-buffer (or buffer nntp-server-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 (insert-buffer-substring nntp-async-buffer beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 (let ((nntp-server-buffer (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (nntp-decode-text)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (delete-region beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (when nntp-async-articles
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 (nntp-async-fetch-articles id))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 (if found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 id
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 ;; The article was not in the async buffer, so we fetch it now.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (if buffer (set-process-buffer nntp-server-process buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (let ((nntp-server-buffer (or buffer nntp-server-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 (art (or (and (numberp id) (int-to-string id)) id)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 (and (nntp-send-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 ;; A bit odd regexp to ensure working over rlogin.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 "^\\.\r?\n" "ARTICLE" art)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 (if (numberp id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 (cons nntp-current-group id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 ;; We find out what the article number was.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 (nntp-find-group-and-number)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (nntp-decode-text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 (and nntp-async-articles (nntp-async-fetch-articles id)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 (when buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (set-process-buffer nntp-server-process nntp-server-buffer))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 (deffoo nntp-request-body (id &optional group server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 "Request body of article ID (Message-ID or number)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (nntp-possibly-change-server group server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 ;; If NEmacs, end of message may look like: "\256\215" (".^M")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 (nntp-send-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 "^\\.\r?\n" "BODY" (or (and (numberp id) (int-to-string id)) id))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 (nntp-decode-text)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 (deffoo nntp-request-head (id &optional group server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 "Request head of article ID (Message-ID or number)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 (nntp-possibly-change-server group server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 (when (nntp-send-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 "^\\.\r?\n" "HEAD" (if (numberp id) (int-to-string id) id))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 (if (numberp id) id
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 ;; We find out what the article number was.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 (nntp-find-group-and-number)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 (nntp-decode-text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (set-buffer nntp-server-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (nnheader-fold-continuation-lines))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 (deffoo nntp-request-stat (id &optional group server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 "Request STAT of article ID (Message-ID or number)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 (nntp-possibly-change-server group server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (nntp-send-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 "^[23].*\r?\n" "STAT" (or (and (numberp id) (int-to-string id)) id)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 (deffoo nntp-request-type (group &optional article)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 'news)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 (deffoo nntp-request-group (group &optional server dont-check)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 "Select GROUP."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 (nntp-possibly-change-server nil server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 (setq nntp-current-group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 (when (nntp-send-command "^2.*\r?\n" "GROUP" group)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 group)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 (deffoo nntp-request-asynchronous (group &optional server articles)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 "Enable pre-fetch in GROUP."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 (when nntp-async-articles
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 (nntp-async-request-group group))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (when nntp-async-number
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 (if (not (or (nntp-async-server-opened)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 (nntp-async-open-server)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 ;; Couldn't open the second connection
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 (message "Can't open second connection to %s" nntp-address)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 (ding)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (setq nntp-async-articles nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 (sit-for 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 ;; We opened the second connection (or it was opened already).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 (setq nntp-async-articles articles)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 (setq nntp-async-fetched nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 ;; Clear any old data.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 (set-buffer nntp-async-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 (erase-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 ;; Select the correct current group on this server.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 (nntp-async-send-strings "GROUP" group)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 (deffoo nntp-list-active-group (group &optional server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 "Return the active info on GROUP (which can be a regexp."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 (nntp-possibly-change-server group server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 (nntp-send-command "^.*\r?\n" "LIST ACTIVE" group))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 (deffoo nntp-request-group-description (group &optional server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 "Get the description of GROUP."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 (nntp-possibly-change-server nil server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 (nntp-send-command "^.*\r?\n" "XGTITLE" group)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 (nntp-decode-text)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 (deffoo nntp-close-group (group &optional server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 "Close GROUP."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 (setq nntp-current-group nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 (deffoo nntp-request-list (&optional server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 "List all active groups."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 (nntp-possibly-change-server nil server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 (nntp-send-command "^\\.\r?\n" "LIST")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 (nntp-decode-text)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 (deffoo nntp-request-list-newsgroups (&optional server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 "Get descriptions on all groups on SERVER."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 (nntp-possibly-change-server nil server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 (nntp-send-command "^\\.\r?\n" "LIST NEWSGROUPS")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 (nntp-decode-text)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 (deffoo nntp-request-newgroups (date &optional server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 "List groups that have arrived since DATE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 (nntp-possibly-change-server nil server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 (let* ((date (timezone-parse-date date))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 (time-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 (format "%s%02d%02d %s%s%s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 (substring (aref date 0) 2) (string-to-int (aref date 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 (string-to-int (aref date 2)) (substring (aref date 3) 0 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 (substring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 (aref date 3) 3 5) (substring (aref date 3) 6 8))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 (nntp-send-command "^\\.\r?\n" "NEWGROUPS" time-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 (nntp-decode-text))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 (deffoo nntp-request-list-distributions (&optional server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 "List distributions."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 (nntp-possibly-change-server nil server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 (nntp-send-command "^\\.\r?\n" "LIST DISTRIBUTIONS")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 (nntp-decode-text)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 (deffoo nntp-request-last (&optional group server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 "Decrease the current article pointer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 (nntp-possibly-change-server group server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 (nntp-send-command "^[23].*\r?\n" "LAST"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 (deffoo nntp-request-next (&optional group server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 "Advance the current article pointer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 (nntp-possibly-change-server group server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 (nntp-send-command "^[23].*\r?\n" "NEXT"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 (deffoo nntp-request-post (&optional server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 "Post the current buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 (nntp-possibly-change-server nil server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 (when (nntp-send-command "^[23].*\r?\n" "POST")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 (nnheader-insert "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 (nntp-encode-text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 (nntp-send-region-to-server (point-min) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 ;; 1.2a NNTP's post command is buggy. "^M" (\r) is not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 ;; appended to end of the status message.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 (nntp-wait-for-response "^[23].*\n")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 ;;; Internal functions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 (defun nntp-send-mode-reader ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 "Send the MODE READER command to the nntp server.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 This function is supposed to be called from `nntp-server-opened-hook'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 It will make innd servers spawn an nnrpd process to allow actual article
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 reading."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 (nntp-send-command "^.*\r?\n" "MODE READER"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 (defun nntp-send-nosy-authinfo ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 "Send the AUTHINFO to the nntp server.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 This function is supposed to be called from `nntp-server-opened-hook'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 It will prompt for a password."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 (nntp-send-command "^.*\r?\n" "AUTHINFO USER"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 (read-string "NNTP user name: "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 (nntp-send-command "^.*\r?\n" "AUTHINFO PASS"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 (read-string "NNTP password: ")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 (defun nntp-send-authinfo ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 "Send the AUTHINFO to the nntp server.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 This function is supposed to be called from `nntp-server-opened-hook'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 It will prompt for a password."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 (nntp-send-command "^.*\r?\n" "AUTHINFO USER" (user-login-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 (nntp-send-command "^.*\r?\n" "AUTHINFO PASS"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 (read-string "NNTP password: ")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 (defun nntp-send-authinfo-from-file ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 "Send the AUTHINFO to the nntp server.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 This function is supposed to be called from `nntp-server-opened-hook'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 It will prompt for a password."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 (when (file-exists-p "~/.nntp-authinfo")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 (set-buffer (get-buffer-create " *authinfo*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 (buffer-disable-undo (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 (insert-file-contents "~/.nntp-authinfo")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 (nntp-send-command "^.*\r?\n" "AUTHINFO USER" (user-login-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 (nntp-send-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 "^.*\r?\n" "AUTHINFO PASS"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 (buffer-substring (point) (progn (end-of-line) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 (kill-buffer (current-buffer)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 (defun nntp-default-sentinel (proc status)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 "Default sentinel function for NNTP server process."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 (let ((servers (cddr (assq 'nntp nnoo-state-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 ;; Go through the alist of server names and find the name of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 ;; server that the process that sent the signal is connected to.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 ;; If you get my drift.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 (if (equal proc nntp-server-process)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 (setq server nntp-address)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 (while (and servers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 (not (equal proc (cdr (assq 'nntp-server-process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 (car servers))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 (setq servers (cdr servers)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 (setq server (caar servers)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 (when (and server
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 nntp-warn-about-losing-connection)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 (nnheader-message 3 "nntp: Connection closed to server %s" server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 (setq nntp-current-group "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 (ding))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 (defun nntp-kill-connection (server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 "Choke the connection to SERVER."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 (let ((proc (cdr (assq 'nntp-server-process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 (assoc server (cddr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 (assq 'nntp nnoo-state-alist)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 (when proc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 (delete-process (process-name proc)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 (nntp-close-server server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 (nnheader-report
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 'nntp (message "Connection timed out to server %s" server))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 (ding)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 (sit-for 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 ;; Encoding and decoding of NNTP text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 (defun nntp-decode-text ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 "Decode text transmitted by NNTP.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 0. Delete status line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 1. Delete `^M' at end of line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 2. Delete `.' at end of buffer (end of text mark).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 3. Delete `.' at beginning of line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 (set-buffer nntp-server-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 ;; Insert newline at end of buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 (or (bolp) (insert "\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 ;; Delete status line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 (delete-region (goto-char (point-min)) (progn (forward-line 1) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 ;; Delete `^M's.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 (while (search-forward "\r" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 (replace-match "" t t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 ;; Delete `.' at end of the buffer (end of text mark).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 (forward-line -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 (when (looking-at "^\\.\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 (delete-region (point) (progn (forward-line 1) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 ;; Replace `..' at beginning of line with `.'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 ;; (replace-regexp "^\\.\\." ".")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 (while (search-forward "\n.." nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 (delete-char -1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 (defun nntp-encode-text ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 "Encode text in current buffer for NNTP transmission.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 1. Insert `.' at beginning of line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 2. Insert `.' at end of buffer (end of text mark)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 ;; Replace `.' at beginning of line with `..'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 (while (search-forward "\n." nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 (insert "."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 ;; Insert newline at end of buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 (or (bolp) (insert "\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 ;; Insert `.' at end of buffer (end of text mark).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 (insert "." nntp-end-of-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 ;;; Synchronous Communication with NNTP servers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 (defvar nntp-retry-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 (defun nntp-send-command (response cmd &rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 "Wait for server RESPONSE after sending CMD and optional ARGS to server."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 (let ((timer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 (and nntp-command-timeout
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 (nnheader-run-at-time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 nntp-command-timeout nil 'nntp-kill-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 (nnoo-current-server 'nntp))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 (nntp-retry-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 (while nntp-retry-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 (setq nntp-retry-command nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 ;; Clear communication buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 (set-buffer nntp-server-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 (if nntp-retry-on-break
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 (apply 'nntp-send-strings-to-server cmd args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 (setq result
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 (if response
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 (nntp-wait-for-response response)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 (quit (setq nntp-retry-command t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 (apply 'nntp-send-strings-to-server cmd args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 (setq result
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 (if response
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 (nntp-wait-for-response response)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 (when timer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 (nnheader-cancel-timer timer)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 (defun nntp-kill-command (server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 "Kill and restart the connection to SERVER."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 (let ((proc (cdr (assq
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 'nntp-server-process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 (assoc server (cddr (assq 'nntp nnoo-state-alist)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 (when proc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 (delete-process (process-name proc)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 (nntp-close-server server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 (nntp-open-server server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 (when nntp-current-group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 (nntp-request-group nntp-current-group))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 (setq nntp-retry-command t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 (defun nntp-send-command-old (response cmd &rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 "Wait for server RESPONSE after sending CMD and optional ARGS to server."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 ;; Clear communication buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 (set-buffer nntp-server-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 (apply 'nntp-send-strings-to-server cmd args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 (if response
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 (nntp-wait-for-response response)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 (defun nntp-wait-for-response (regexp &optional slow)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 "Wait for server response which matches REGEXP."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 (let ((status t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 (wait t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 (dotnum 0) ;Number of "." being displayed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 (dotsize ;How often "." displayed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 (if (numberp nntp-debug-read) nntp-debug-read 10000)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 (set-buffer nntp-server-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 ;; Wait for status response (RFC977).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 ;; 1xx - Informative message.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 ;; 2xx - Command ok.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 ;; 3xx - Command ok so far, send the rest of it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 ;; 4xx - Command was correct, but couldn't be performed for some
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 ;; reason.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 ;; 5xx - Command unimplemented, or incorrect, or a serious
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 ;; program error occurred.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 (nntp-accept-response)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 (while wait
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 (if slow
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 (cond ((re-search-forward "^[23][0-9][0-9]" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 (setq wait nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 ((re-search-forward "^[45][0-9][0-9]" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 (setq status nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 (setq wait nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 (t (nntp-accept-response)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 (if (not wait) (delete-region (point-min)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 (progn (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 (cond ((looking-at "[23]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 (setq wait nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 ((looking-at "[45]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 (setq status nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 (setq wait nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 (t (nntp-accept-response)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 ;; Save status message.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 (setq nntp-status-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 (nnheader-replace-chars-in-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 (buffer-substring (point-min) (point)) ?\r ? ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 (when status
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 (setq wait t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 (while wait
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 (if (bolp) (forward-line -1) (beginning-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 (if (looking-at regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 (setq wait nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 (when nntp-debug-read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 (let ((newnum (/ (buffer-size) dotsize))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 (message-log-max nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 (unless (= dotnum newnum)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 (setq dotnum newnum)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 (nnheader-message 7 "NNTP: Reading %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 (make-string dotnum ?.)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 (nntp-accept-response)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 ;; Remove "...".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 (when (and nntp-debug-read (> dotnum 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 (message ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 ;; Successfully received server response.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 ;;; Low-Level Interface to NNTP Server.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 (defun nntp-find-group-and-number ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 (set-buffer nntp-server-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 (narrow-to-region (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 (or (search-forward "\n\n" nil t) (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 ;; We first find the number by looking at the status line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 (let ((number (and (looking-at "2[0-9][0-9] +\\([0-9]+\\) ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 (string-to-int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 (buffer-substring (match-beginning 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 (match-end 1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 group newsgroups xref)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 (and number (zerop number) (setq number nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 ;; Then we find the group name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 (setq group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 ;; If there is only one group in the Newsgroups header,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 ;; then it seems quite likely that this article comes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 ;; from that group, I'd say.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 ((and (setq newsgroups (mail-fetch-field "newsgroups"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 (not (string-match "," newsgroups)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 newsgroups)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 ;; If there is more than one group in the Newsgroups
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 ;; header, then the Xref header should be filled out.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 ;; We hazard a guess that the group that has this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 ;; article number in the Xref header is the one we are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 ;; looking for. This might very well be wrong if this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 ;; article happens to have the same number in several
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 ;; groups, but that's life.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 ((and (setq xref (mail-fetch-field "xref"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 number
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 (string-match (format "\\([^ :]+\\):%d" number) xref))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 (substring xref (match-beginning 1) (match-end 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 (t "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 (when (string-match "\r" group)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 (setq group (substring group 0 (match-beginning 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 (cons group number)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 (defun nntp-retrieve-headers-with-xover (articles &optional fetch-old)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 ;; This server does not talk NOV.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 ((not nntp-server-xover)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 ;; We don't care about gaps.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 ((or (not nntp-nov-gap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 fetch-old)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 (nntp-send-xover-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 (if fetch-old
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 (if (numberp fetch-old)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 (max 1 (- (car articles) fetch-old))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 (car articles))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922 (nntp-last-element articles) 'wait)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 (when (looking-at "[1-5][0-9][0-9] ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 (delete-region (point) (progn (forward-line 1) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 (while (search-forward "\r" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 (replace-match "" t t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930 (forward-line -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 (when (looking-at "\\.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 (delete-region (point) (progn (forward-line 1) (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934 ;; We do it the hard way. For each gap, an XOVER command is sent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935 ;; to the server. We do not wait for a reply from the server, we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 ;; just send them off as fast as we can. That means that we have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 ;; to count the number of responses we get back to find out when we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938 ;; have gotten all we asked for.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 ((numberp nntp-nov-gap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 (let ((count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941 (received 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942 (last-point (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943 (buf (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944 first)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 ;; We have to check `nntp-server-xover'. If it gets set to nil,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946 ;; that means that the server does not understand XOVER, but we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947 ;; won't know that until we try.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948 (while (and nntp-server-xover articles)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949 (setq first (car articles))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950 ;; Search forward until we find a gap, or until we run out of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 ;; articles.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 (while (and (cdr articles)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953 (< (- (nth 1 articles) (car articles)) nntp-nov-gap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954 (setq articles (cdr articles)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 (when (nntp-send-xover-command first (car articles))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957 (setq articles (cdr articles)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958 count (1+ count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960 ;; Every 400 requests we have to read the stream in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961 ;; order to avoid deadlocks.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962 (when (or (null articles) ;All requests have been sent.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963 (zerop (% count nntp-maximum-request)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964 (accept-process-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 ;; On some Emacs versions the preceding function has
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966 ;; a tendency to change the buffer. Perhaps. It's
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967 ;; quite difficult to reproduce, because it only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968 ;; seems to happen once in a blue moon.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969 (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 (while (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971 (goto-char last-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972 ;; Count replies.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973 (while (re-search-forward "^[0-9][0-9][0-9] " nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974 (setq received (1+ received)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975 (setq last-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976 (< received count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977 (accept-process-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978 (set-buffer buf)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980 (when nntp-server-xover
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981 ;; Wait for the reply from the final command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983 (re-search-backward "^[0-9][0-9][0-9] " nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984 (when (looking-at "^[23]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985 (while (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987 (forward-line -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988 (not (looking-at "^\\.\r?\n")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989 (nntp-accept-response)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991 ;; We remove any "." lines and status lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
992 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993 (while (search-forward "\r" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994 (delete-char -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996 (delete-matching-lines "^\\.$\\|^[1-5][0-9][0-9] ")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998 nntp-server-xover)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000 (defun nntp-send-xover-command (beg end &optional wait-for-reply)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1001 "Send the XOVER command to the server."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002 (let ((range (format "%d-%d" (or beg 1) (or end beg 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003 (if (stringp nntp-server-xover)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004 ;; If `nntp-server-xover' is a string, then we just send this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005 ;; command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006 (if wait-for-reply
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007 (nntp-send-command "^\\.\r?\n" nntp-server-xover range)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 ;; We do not wait for the reply.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009 (nntp-send-strings-to-server nntp-server-xover range))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010 (let ((commands nntp-xover-commands))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011 ;; `nntp-xover-commands' is a list of possible XOVER commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 ;; We try them all until we get at positive response.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013 (while (and commands (eq nntp-server-xover 'try))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014 (nntp-send-command "^\\.\r?\n" (car commands) range)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1015 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1016 (set-buffer nntp-server-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1017 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1018 (and (looking-at "[23]") ; No error message.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019 ;; We also have to look at the lines. Some buggy
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020 ;; servers give back simple lines with just the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1021 ;; article number. How... helpful.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024 (looking-at "[0-9]+\t...")) ; More text after number.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1025 (setq nntp-server-xover (car commands))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1026 (setq commands (cdr commands)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1027 ;; If none of the commands worked, we disable XOVER.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1028 (when (eq nntp-server-xover 'try)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1029 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030 (set-buffer nntp-server-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1032 (setq nntp-server-xover nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1033 nntp-server-xover))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1034
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035 (defun nntp-send-strings-to-server (&rest strings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036 "Send STRINGS to the server."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1037 (let ((cmd (concat (mapconcat 'identity strings " ") nntp-end-of-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1038 ;; We open the nntp server if it is down.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1039 (or (nntp-server-opened (nnoo-current-server 'nntp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1040 (nntp-open-server (nnoo-current-server 'nntp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1041 (error (nntp-status-message)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1042 ;; Send the strings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043 (process-send-string nntp-server-process cmd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1044 t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1045
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1046 (defun nntp-send-region-to-server (begin end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1047 "Send the current buffer region (from BEGIN to END) to the server."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1048 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1049 (let ((cur (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1050 ;; Copy the buffer over to the send buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1051 (nnheader-set-temp-buffer " *nntp send*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1052 (insert-buffer-substring cur begin end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1053 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1054 (set-buffer cur)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1055 (erase-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1056 ;; `process-send-region' does not work if the text to be sent is very
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1057 ;; large, so we send it piecemeal.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1058 (let ((last (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1059 (size 100)) ;Size of text sent at once.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1060 (while (and (/= last (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1061 (memq (process-status nntp-server-process) '(open run)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1062 (process-send-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1063 nntp-server-process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1064 last (setq last (min (+ last size) (point-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1065 ;; Read any output from the server. May be unnecessary.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1066 (accept-process-output)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1067 (kill-buffer (current-buffer)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1068
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1069 (defun nntp-open-server-semi-internal (server &optional service)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1070 "Open SERVER.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1071 If SERVER is nil, use value of environment variable `NNTPSERVER'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1072 If SERVICE, this this as the port number."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1073 (nnheader-insert "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1074 (let ((server (or server (getenv "NNTPSERVER")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1075 (status nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1076 (timer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1077 (and nntp-connection-timeout
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1078 (nnheader-run-at-time nntp-connection-timeout
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1079 nil 'nntp-kill-connection server))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1080 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1081 (set-buffer nntp-server-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1082 (setq nntp-status-string "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1083 (nnheader-message 5 "nntp: Connecting to server on %s..." nntp-address)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1084 (cond ((and server (nntp-open-server-internal server service))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1085 (setq nntp-address server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1086 (setq status
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1087 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1088 (nntp-wait-for-response "^[23].*\r?\n" 'slow)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1089 (error nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1090 (quit nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1091 (unless status
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1092 (nntp-close-server-internal server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1093 (nnheader-report
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1094 'nntp "Couldn't open connection to %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1095 (if (and nntp-address
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1096 (not (equal nntp-address "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1097 nntp-address server)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1098 (when nntp-server-process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1099 (set-process-sentinel
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1100 nntp-server-process 'nntp-default-sentinel)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1101 ;; You can send commands at startup like AUTHINFO here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1102 ;; Added by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1103 (run-hooks 'nntp-server-opened-hook)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1104 ((null server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1105 (nnheader-report 'nntp "NNTP server is not specified."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1106 (t ; We couldn't open the server.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1107 (nnheader-report
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1108 'nntp (buffer-substring (point-min) (point-max)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1109 (when timer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1110 (nnheader-cancel-timer timer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1111 (message "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1112 (unless status
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1113 (nnoo-close-server 'nntp server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1114 (setq nntp-async-number nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1115 status)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1116
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1117 (defvar nntp-default-directories '("~" "/tmp" "/")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1118 "Directories to as current directory in the nntp server buffer.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1119
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1120 (defun nntp-open-server-internal (server &optional service)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1121 "Open connection to news server on SERVER by SERVICE (default is nntp)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1122 (let (proc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1123 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1124 (set-buffer nntp-server-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1125 ;; Make sure we have a valid current directory for the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1126 ;; nntp server buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1127 (unless (file-exists-p default-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1128 (let ((dirs nntp-default-directories))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1129 (while dirs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1130 (when (file-exists-p (car dirs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1131 (setq default-directory (car dirs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1132 dirs nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1133 (setq dirs (cdr dirs)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1134 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1135 ((and (setq proc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1136 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1137 (funcall nntp-open-server-function server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1138 (error nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1139 (memq (process-status proc) '(open run)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1140 (setq nntp-server-process proc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1141 (setq nntp-address server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1142 ;; Suggested by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1143 (process-kill-without-query proc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1144 (run-hooks 'nntp-server-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1145 (push proc nntp-opened-connections)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1146 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1147 (nntp-read-server-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1148 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1149 (nnheader-report 'nntp "Couldn't open server %s" server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1150 (nntp-close-server)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1151 nntp-server-process)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1152 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1153 (nnheader-report 'nntp "Couldn't open server %s" server))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1154
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1155 (defun nntp-read-server-type ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1156 "Find out what the name of the server we have connected to is."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1157 ;; Wait for the status string to arrive.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1158 (nntp-wait-for-response "^.*\n" t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1159 (setq nntp-server-type (buffer-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1160 (let ((alist nntp-server-action-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1161 entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1162 ;; Run server-specific commmands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1163 (while alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1164 (setq entry (pop alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1165 (when (string-match (car entry) nntp-server-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1166 (if (and (listp (cadr entry))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1167 (not (eq 'lambda (caadr entry))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1168 (eval (cadr entry))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1169 (funcall (cadr entry)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1170
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1171 (defun nntp-open-network-stream (server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1172 (open-network-stream
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1173 "nntpd" nntp-server-buffer server nntp-port-number))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1174
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1175 (defun nntp-open-rlogin (server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1176 (let ((proc (if nntp-rlogin-user-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1177 (start-process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1178 "nntpd" nntp-server-buffer "rsh"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1179 "-l" nntp-rlogin-user-name server
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1180 (mapconcat 'identity
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1181 nntp-rlogin-parameters " "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1182 (start-process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1183 "nntpd" nntp-server-buffer "rsh" server
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1184 (mapconcat 'identity
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1185 nntp-rlogin-parameters " ")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1186 proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1187
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1188 (defun nntp-telnet-to-machine ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1189 (let (b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1190 (telnet "localhost")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1191 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1192 (while (not (re-search-forward "^login: *" nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1193 (sit-for 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1194 (goto-char (point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1195 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1196 (insert "larsi")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1197 (telnet-send-input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1198 (setq b (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1199 (while (not (re-search-forward ">" nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1200 (sit-for 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1201 (goto-char b))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1202 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1203 (insert "ls")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1204 (telnet-send-input)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1205
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1206 (defun nntp-close-server-internal (&optional server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1207 "Close connection to news server."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1208 (nntp-possibly-change-server nil server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1209 (if nntp-server-process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1210 (delete-process nntp-server-process))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1211 (setq nntp-server-process nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1212 (setq nntp-address ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1213
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1214 (defun nntp-accept-response ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1215 "Read response of server.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1216 It is well-known that the communication speed will be much improved by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1217 defining this function as macro."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1218 ;; To deal with server process exiting before
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1219 ;; accept-process-output is called.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1220 ;; Suggested by Jason Venner <jason@violet.berkeley.edu>.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1221 ;; This is a copy of `nntp-default-sentinel'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1222 (let ((buf (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1223 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1224 (if (or (not nntp-server-process)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1225 (not (memq (process-status nntp-server-process) '(open run))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1226 (error "nntp: Process connection closed; %s" (nntp-status-message))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1227 (if nntp-buggy-select
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1228 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1229 ;; We cannot use `accept-process-output'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1230 ;; Fujitsu UTS requires messages during sleep-for.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1231 ;; I don't know why.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1232 (nnheader-message 5 "NNTP: Reading...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1233 (sleep-for 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1234 (nnheader-message 5 ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1235 (condition-case errorcode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1236 (accept-process-output nntp-server-process 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1237 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1238 (cond ((string-equal "select error: Invalid argument"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1239 (nth 1 errorcode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1240 ;; Ignore select error.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1241 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1242 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1243 (signal (car errorcode) (cdr errorcode))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1244 (set-buffer buf))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1245
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1246 (defun nntp-last-element (list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1247 "Return last element of LIST."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1248 (while (cdr list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1249 (setq list (cdr list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1250 (car list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1251
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1252 (defun nntp-possibly-change-server (newsgroup server &optional connectionless)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1253 "Check whether the virtual server needs changing."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1254 (when (and server
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1255 (not (nntp-server-opened server)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1256 ;; This virtual server isn't open, so we (re)open it here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1257 (nntp-open-server server nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1258 (when (and newsgroup
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1259 (not (equal newsgroup nntp-current-group)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1260 ;; Set the proper current group.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1261 (nntp-request-group newsgroup server)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1262
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1263 (defun nntp-try-list-active (group)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1264 (nntp-list-active-group group)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1265 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1266 (set-buffer nntp-server-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1267 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1268 (cond ((looking-at "5[0-9]+")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1269 (setq nntp-server-list-active-group nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1270 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1271 (setq nntp-server-list-active-group t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1272
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1273 (defun nntp-async-server-opened ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1274 (and nntp-async-process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1275 (memq (process-status nntp-async-process) '(open run))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1276
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1277 (defun nntp-async-open-server ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1278 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1279 (set-buffer (generate-new-buffer " *async-nntp*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1280 (setq nntp-async-buffer (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1281 (buffer-disable-undo (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1282 (let ((nntp-server-process nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1283 (nntp-server-buffer nntp-async-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1284 (nntp-open-server-semi-internal nntp-address nntp-port-number)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1285 (if (not (setq nntp-async-process nntp-server-process))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1286 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1287 (setq nntp-async-number nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1288 (set-process-buffer nntp-async-process nntp-async-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1289
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1290 (defun nntp-async-fetch-articles (article)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1291 (if (stringp article)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1292 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1293 (let ((articles (cdr (memq (assq article nntp-async-articles)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1294 nntp-async-articles)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1295 (max (cond ((numberp nntp-async-number)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1296 nntp-async-number)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1297 ((eq nntp-async-number t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1298 (length nntp-async-articles))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1299 (t 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1300 nart)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1301 (while (and (>= (setq max (1- max)) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1302 articles)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1303 (or (memq (setq nart (caar articles)) nntp-async-fetched)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1304 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1305 (nntp-async-send-strings "ARTICLE " (int-to-string nart))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1306 (setq nntp-async-fetched (cons nart nntp-async-fetched))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1307 (setq articles (cdr articles))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1308
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1309 (defun nntp-async-send-strings (&rest strings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1310 (let ((cmd (concat (mapconcat 'identity strings " ") nntp-end-of-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1311 (or (nntp-async-server-opened)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1312 (nntp-async-open-server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1313 (error (nntp-status-message)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1314 (process-send-string nntp-async-process cmd)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1315
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1316 (defun nntp-async-request-group (group)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1317 (if (equal group nntp-current-group)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1318 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1319 (let ((asyncs (assoc group nntp-async-group-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1320 ;; A new group has been selected, so we push the current state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1321 ;; of async articles on an alist, and pull the old state off.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1322 (setq nntp-async-group-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1323 (cons (list nntp-current-group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1324 nntp-async-articles nntp-async-fetched
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1325 nntp-async-process)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1326 (delq asyncs nntp-async-group-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1327 (and asyncs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1328 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1329 (setq nntp-async-articles (nth 1 asyncs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1330 (setq nntp-async-fetched (nth 2 asyncs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1331 (setq nntp-async-process (nth 3 asyncs)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1332
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1333 (provide 'nntp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1334
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1335 ;;; nntp.el ends here