annotate lisp/nntp.el @ 21818:af741167f81e

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