dfd2e6194b93edb6d3f4c90e2be42b24e545e9d1
[gnus] / lisp / nntp.el
1 ;;; nntp.el --- NNTP (RFC977) Interface for GNU Emacs
2 ;; Copyright (C) 1987,88,89,90,92,93,94,95 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
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23
24 ;;; Commentary:
25
26 ;;; Code:
27
28 (require 'rnews)
29 (require 'nnheader)
30
31 (eval-and-compile
32   (autoload 'news-setup "rnewspost")
33   (autoload 'news-reply-mode "rnewspost")
34   (autoload 'nnmail-request-post-buffer "nnmail")
35   (autoload 'cancel-timer "timer"))
36
37 (defvar nntp-server-hook nil
38   "Hooks for the NNTP server.
39 If the kanji code of the NNTP server is different from the local kanji
40 code, the correct kanji code of the buffer associated with the NNTP
41 server must be specified as follows:
42
43 \(setq nntp-server-hook
44       (function
45        (lambda ()
46          ;; Server's Kanji code is EUC (NEmacs hack).
47          (make-local-variable 'kanji-fileio-code)
48          (setq kanji-fileio-code 0))))
49
50 If you'd like to change something depending on the server in this
51 hook, use the variable `nntp-address'.")
52
53 (defvar nntp-server-opened-hook nil
54   "Hook used for sending commands to the server at startup.  The
55 default value is `nntp-send-mode-reader', whick makes an innd server
56 spawn an nnrpd server.  Another useful function to put in this hook
57 might be `nntp-send-authinfo', which will prompt for a password to
58 allow posting from the server.  Note that this is only necessary to do
59 on servers that use strict access control.")
60 (add-hook 'nntp-server-opened-hook 'nntp-send-mode-reader)
61
62 (defvar nntp-address nil
63   "The name of the NNTP server.")
64
65 (defvar nntp-port-number "nntp"
66   "Port number to connect to.")
67
68 (defvar nntp-large-newsgroup 50
69   "The number of the articles which indicates a large newsgroup.
70 If the number of the articles is greater than the value, verbose
71 messages will be shown to indicate the current status.")
72
73 (defvar nntp-buggy-select (memq system-type '(fujitsu-uts))
74   "t if your select routine is buggy.
75 If the select routine signals error or fall into infinite loop while
76 waiting for the server response, the variable must be set to t.  In
77 case of Fujitsu UTS, it is set to T since `accept-process-output'
78 doesn't work properly.")
79
80 (defvar nntp-maximum-request 400
81   "The maximum number of the requests sent to the NNTP server at one time.
82 If Emacs hangs up while retrieving headers, set the variable to a
83 lower value.")
84
85 (defvar nntp-debug-read 10000
86   "Display '...' every 10Kbytes of a message being received if it is non-nil.
87 If it is a number, dots are displayed per the number.")
88
89 (defvar nntp-nov-is-evil nil
90   "If non-nil, nntp will never attempt to use XOVER when talking to the server.")
91
92 (defvar nntp-xover-commands '("XOVER" "XOVERVIEW")
93   "List of strings that are used as commands to fetch NOV lines from a server.
94 The strings are tried in turn until a positive response is gotten. If
95 none of the commands are successful, nntp will just grab headers one
96 by one.")
97
98 (defvar nntp-connection-timeout nil
99   "Number of seconds to wait before an nntp connection times out.
100 If this variable is nil, which is the default, no timers are set.")
101
102 (defvar nntp-news-default-headers nil
103   "If non-nil, override `mail-default-headers' when posting news.")
104
105 \f
106
107 (defconst nntp-version "nntp 4.0"
108   "Version numbers of this version of NNTP.")
109
110 (defvar nntp-server-buffer nil
111   "Buffer associated with the NNTP server process.")
112
113 (defvar nntp-server-process nil
114   "The NNTP server process.
115 You'd better not use this variable in NNTP front-end program, but
116 instead use `nntp-server-buffer'.")
117
118 (defvar nntp-status-string nil
119   "Save the server response message.
120 You'd better not use this variable in NNTP front-end program but
121 instead call function `nntp-status-message' to get status message.")
122
123 (defvar nntp-server-xover t)
124 (defvar nntp-server-list-active-group t)
125 (defvar nntp-current-group "")
126
127 \f
128 (defvar nntp-current-server nil)
129 (defvar nntp-server-alist nil)
130 (defvar nntp-server-variables 
131   (list
132    (list 'nntp-server-hook nntp-server-hook)
133    (list 'nntp-server-opened-hook nntp-server-opened-hook)
134    (list 'nntp-port-number nntp-port-number)
135    (list 'nntp-address nntp-address)
136    (list 'nntp-large-newsgroup nntp-large-newsgroup)
137    (list 'nntp-buggy-select nntp-buggy-select)
138    (list 'nntp-maximum-request nntp-maximum-request)
139    (list 'nntp-debug-read nntp-debug-read)
140    (list 'nntp-nov-is-evil nntp-nov-is-evil)
141    (list 'nntp-xover-commands nntp-xover-commands)
142    (list 'nntp-connection-timeout nntp-connection-timeout)
143    (list 'nntp-news-default-headers nntp-news-default-headers)
144    '(nntp-server-process nil)
145    '(nntp-status-string nil)
146    '(nntp-server-xover t)
147    '(nntp-server-list-active-group t)
148    '(nntp-current-group "")))
149
150 \f
151 ;;; Interface funtions.
152
153 (defun nntp-retrieve-headers (sequence &optional newsgroup server)
154   "Retrieve the headers to the articles in SEQUENCE."
155   (nntp-possibly-change-server newsgroup server)
156   (save-excursion
157     (set-buffer nntp-server-buffer)
158     (erase-buffer)
159     (if (and (not gnus-nov-is-evil) 
160