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