annotate lisp/=nnspool.el @ 5820:3443820118a0

(makefile-browser-fill, makefile-browser-toggle): Bind inhibit-read-only; don't set buffer-read-only.
author Richard M. Stallman <rms@gnu.org>
date Mon, 07 Feb 1994 05:54:34 +0000
parents 507f64624555
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
659
505130d1ddf8 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 584
diff changeset
1 ;;; nnspool.el --- spool access using NNTP for GNU Emacs
505130d1ddf8 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 584
diff changeset
2
2843
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
3 ;; Copyright (C) 1988, 1989, 1990, 1993 Free Software Foundation, Inc.
846
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 814
diff changeset
4
790
47ec7c4c42bc *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 659
diff changeset
5 ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
814
38b2499cb3e9 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 790
diff changeset
6 ;; Keywords: news
790
47ec7c4c42bc *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 659
diff changeset
7
87
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
9
882
bff32d8ecc5e entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 853
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
bff32d8ecc5e entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 853
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
bff32d8ecc5e entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 853
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
bff32d8ecc5e entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 853
diff changeset
13 ;; any later version.
87
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
14
882
bff32d8ecc5e entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 853
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
bff32d8ecc5e entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 853
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
bff32d8ecc5e entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 853
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bff32d8ecc5e entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 853
diff changeset
18 ;; GNU General Public License for more details.
bff32d8ecc5e entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 853
diff changeset
19
bff32d8ecc5e entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 853
diff changeset
20 ;; You should have received a copy of the GNU General Public License
bff32d8ecc5e entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 853
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to
bff32d8ecc5e entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 853
diff changeset
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
87
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
23
790
47ec7c4c42bc *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 659
diff changeset
24 ;;; Code:
47ec7c4c42bc *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 659
diff changeset
25
87
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
26 (require 'nntp)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
27
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
28 (defvar nnspool-inews-program news-inews-program
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
29 "*Program to post news.")
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
30
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
31 (defvar nnspool-inews-switches '("-h")
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
32 "*Switches for nnspool-request-post to pass to `inews' for posting news.")
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
33
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
34 (defvar nnspool-spool-directory news-path
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
35 "*Local news spool directory.")
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
36
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
37 (defvar nnspool-active-file "/usr/lib/news/active"
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
38 "*Local news active file.")
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
39
2843
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
40 (defvar nnspool-newsgroups-file "/usr/lib/news/newsgroups"
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
41 "*Local news newsgroups file.")
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
42
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
43 (defvar nnspool-distributions-file "/usr/lib/news/distributions"
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
44 "*Local news distributions file.")
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
45
87
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
46 (defvar nnspool-history-file "/usr/lib/news/history"
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
47 "*Local news history file.")
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
48
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
49
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
50
2843
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
51 (defconst nnspool-version "NNSPOOL 1.12"
87
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
52 "Version numbers of this version of NNSPOOL.")
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
53
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
54 (defvar nnspool-current-directory nil
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
55 "Current news group directory.")
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
56
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
57 ;;;
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
58 ;;; Replacement of Extended Command for retrieving many headers.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
59 ;;;
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
60
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
61 (defun nnspool-retrieve-headers (sequence)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
62 "Return list of article headers specified by SEQUENCE of article id.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
63 The format of list is
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
64 `([NUMBER SUBJECT FROM XREF LINES DATE MESSAGE-ID REFERENCES] ...)'.
2843
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
65 If there is no References: field, In-Reply-To: field is used instead.
87
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
66 Reader macros for the vector are defined as `nntp-header-FIELD'.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
67 Writer macros for the vector are defined as `nntp-set-header-FIELD'.
2843
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
68 Newsgroup must be selected before calling this."
87
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
69 (save-excursion
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
70 (set-buffer nntp-server-buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
71 ;;(erase-buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
72 (let ((file nil)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
73 (number (length sequence))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
74 (count 0)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
75 (headers nil) ;Result list.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
76 (article 0)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
77 (subject nil)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
78 (message-id nil)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
79 (from nil)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
80 (xref nil)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
81 (lines 0)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
82 (date nil)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
83 (references nil))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
84 (while sequence
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
85 ;;(nntp-send-strings-to-server "HEAD" (car sequence))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
86 (setq article (car sequence))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
87 (setq file
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
88 (concat nnspool-current-directory (prin1-to-string article)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
89 (if (and (file-exists-p file)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
90 (not (file-directory-p file)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
91 (progn
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
92 (erase-buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
93 (insert-file-contents file)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
94 ;; Make message body invisible.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
95 (goto-char (point-min))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
96 (search-forward "\n\n" nil 'move)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
97 (narrow-to-region (point-min) (point))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
98 ;; Fold continuation lines.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
99 (goto-char (point-min))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
100 (while (re-search-forward "\\(\r?\n[ \t]+\\)+" nil t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
101 (replace-match " " t t))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
102 ;; Make it possible to search for `\nFIELD'.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
103 (goto-char (point-min))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
104 (insert "\n")
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
105 ;; Extract From:
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
106 (goto-char (point-min))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
107 (if (search-forward "\nFrom: " nil t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
108 (setq from (buffer-substring
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
109 (point)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
110 (save-excursion (end-of-line) (point))))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
111 (setq from "(Unknown User)"))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
112 ;; Extract Subject:
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
113 (goto-char (point-min))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
114 (if (search-forward "\nSubject: " nil t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
115 (setq subject (buffer-substring
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
116 (point)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
117 (save-excursion (end-of-line) (point))))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
118 (setq subject "(None)"))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
119 ;; Extract Message-ID:
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
120 (goto-char (point-min))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
121 (if (search-forward "\nMessage-ID: " nil t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
122 (setq message-id (buffer-substring
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
123 (point)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
124 (save-excursion (end-of-line) (point))))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
125 (setq message-id nil))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
126 ;; Extract Date:
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
127 (goto-char (point-min))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
128 (if (search-forward "\nDate: " nil t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
129 (setq date (buffer-substring
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
130 (point)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
131 (save-excursion (end-of-line) (point))))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
132 (setq date nil))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
133 ;; Extract Lines:
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
134 (goto-char (point-min))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
135 (if (search-forward "\nLines: " nil t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
136 (setq lines (string-to-int
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
137 (buffer-substring
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
138 (point)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
139 (save-excursion (end-of-line) (point)))))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
140 (setq lines 0))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
141 ;; Extract Xref:
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
142 (goto-char (point-min))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
143 (if (search-forward "\nXref: " nil t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
144 (setq xref (buffer-substring
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
145 (point)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
146 (save-excursion (end-of-line) (point))))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
147 (setq xref nil))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
148 ;; Extract References:
2843
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
149 ;; If no References: field, use In-Reply-To: field instead.
87
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
150 (goto-char (point-min))
2843
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
151 (if (or (search-forward "\nReferences: " nil t)
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
152 (search-forward "\nIn-Reply-To: " nil t))
87
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
153 (setq references (buffer-substring
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
154 (point)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
155 (save-excursion (end-of-line) (point))))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
156 (setq references nil))
2843
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
157 ;; Collect valid article only.
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
158 (and article
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
159 message-id
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
160 (setq headers
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
161 (cons (vector article subject from
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
162 xref lines date
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
163 message-id references) headers)))
87
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
164 ))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
165 (setq sequence (cdr sequence))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
166 (setq count (1+ count))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
167 (and (numberp nntp-large-newsgroup)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
168 (> number nntp-large-newsgroup)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
169 (zerop (% count 20))
2843
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
170 (message "NNSPOOL: Receiving headers... %d%%"
87
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
171 (/ (* count 100) number)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
172 )
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
173 (and (numberp nntp-large-newsgroup)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
174 (> number nntp-large-newsgroup)
2843
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
175 (message "NNSPOOL: Receiving headers... done"))
87
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
176 (nreverse headers)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
177 )))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
178
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
179
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
180 ;;;
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
181 ;;; Replacement of NNTP Raw Interface.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
182 ;;;
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
183
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
184 (defun nnspool-open-server (host &optional service)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
185 "Open news server on HOST.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
186 If HOST is nil, use value of environment variable `NNTPSERVER'.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
187 If optional argument SERVICE is non-nil, open by the service name."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
188 (let ((host (or host (getenv "NNTPSERVER")))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
189 (status nil))
2843
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
190 (setq nntp-status-string "")
87
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
191 (cond ((and (file-directory-p nnspool-spool-directory)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
192 (file-exists-p nnspool-active-file)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
193 (string-equal host (system-name)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
194 (setq status (nnspool-open-server-internal host service)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
195 ((string-equal host (system-name))
2843
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
196 (setq nntp-status-string
87
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
197 (format "%s has no news spool. Goodbye." host)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
198 ((null host)
2843
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
199 (setq nntp-status-string "NNTP server is not specified."))
87
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
200 (t
2843
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
201 (setq nntp-status-string
87
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
202 (format "NNSPOOL: cannot talk to %s." host)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
203 )
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
204 status
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
205 ))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
206
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
207 (defun nnspool-close-server ()
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
208 "Close news server."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
209 (nnspool-close-server-internal))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
210
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
211 (fset 'nnspool-request-quit (symbol-function 'nnspool-close-server))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
212
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
213 (defun nnspool-server-opened ()
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
214 "Return server process status, T or NIL.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
215 If the stream is opened, return T, otherwise return NIL."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
216 (and nntp-server-buffer
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
217 (get-buffer nntp-server-buffer)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
218
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
219 (defun nnspool-status-message ()
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
220 "Return server status response as string."
2843
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
221 nntp-status-string
87
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
222 )
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
223
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
224 (defun nnspool-request-article (id)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
225 "Select article by message ID (or number)."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
226 (let ((file (if (stringp id)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
227 (nnspool-find-article-by-message-id id)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
228 (concat nnspool-current-directory (prin1-to-string id)))))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
229 (if (and (stringp file)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
230 (file-exists-p file)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
231 (not (file-directory-p file)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
232 (save-excursion
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
233 (nnspool-find-file file)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
234 ))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
235
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
236 (defun nnspool-request-body (id)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
237 "Select article body by message ID (or number)."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
238 (if (nnspool-request-article id)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
239 (save-excursion
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
240 (set-buffer nntp-server-buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
241 (goto-char (point-min))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
242 (if (search-forward "\n\n" nil t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
243 (delete-region (point-min) (point)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
244 t
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
245 )
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
246 ))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
247
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
248 (defun nnspool-request-head (id)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
249 "Select article head by message ID (or number)."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
250 (if (nnspool-request-article id)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
251 (save-excursion
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
252 (set-buffer nntp-server-buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
253 (goto-char (point-min))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
254 (if (search-forward "\n\n" nil t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
255 (delete-region (1- (point)) (point-max)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
256 t
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
257 )
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
258 ))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
259
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
260 (defun nnspool-request-stat (id)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
261 "Select article by message ID (or number)."
2843
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
262 (setq nntp-status-string "NNSPOOL: STAT is not implemented.")
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
263 nil
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
264 )
87
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
265
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
266 (defun nnspool-request-group (group)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
267 "Select news GROUP."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
268 (let ((pathname (nnspool-article-pathname
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
269 (nnspool-replace-chars-in-string group ?. ?/))))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
270 (if (file-directory-p pathname)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
271 (setq nnspool-current-directory pathname))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
272 ))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
273
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
274 (defun nnspool-request-list ()
2843
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
275 "List active newsgoups."
87
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
276 (save-excursion
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
277 (nnspool-find-file nnspool-active-file)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
278
2843
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
279 (defun nnspool-request-list-newsgroups ()
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
280 "List newsgroups (defined in NNTP2)."
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
281 (save-excursion
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
282 (nnspool-find-file nnspool-newsgroups-file)))
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
283
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
284 (defun nnspool-request-list-distributions ()
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
285 "List distributions (defined in NNTP2)."
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
286 (save-excursion
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
287 (nnspool-find-file nnspool-distributions-file)))
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
288
87
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
289 (defun nnspool-request-last ()
2843
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
290 "Set current article pointer to the previous article
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
291 in the current news group."
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
292 (setq nntp-status-string "NNSPOOL: LAST is not implemented.")
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
293 nil
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
294 )
87
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
295
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
296 (defun nnspool-request-next ()
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
297 "Advance current article pointer."
2843
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
298 (setq nntp-status-string "NNSPOOL: NEXT is not implemented.")
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
299 nil
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
300 )
87
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
301
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
302 (defun nnspool-request-post ()
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
303 "Post a new news in current buffer."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
304 (save-excursion
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
305 ;; We have to work in the server buffer because of NEmacs hack.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
306 (copy-to-buffer nntp-server-buffer (point-min) (point-max))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
307 (set-buffer nntp-server-buffer)
2843
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
308 (apply (function call-process-region)
87
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
309 (point-min) (point-max)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
310 nnspool-inews-program 'delete t nil nnspool-inews-switches)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
311 (prog1
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
312 (or (zerop (buffer-size))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
313 ;; If inews returns strings, it must be error message
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
314 ;; unless SPOOLNEWS is defined.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
315 ;; This condition is very weak, but there is no good rule
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
316 ;; identifying errors when SPOOLNEWS is defined.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
317 ;; Suggested by ohm@kaba.junet.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
318 (string-match "spooled" (buffer-string)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
319 ;; Make status message by unfolding lines.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
320 (subst-char-in-region (point-min) (point-max) ?\n ?\\ 'noundo)
2843
cd90d49526ae Version 3.15 from Umeda.
Richard M. Stallman <rms@gnu.org>
parents: 882
diff changeset
321 (setq nntp-status-string (buffer-string))
87
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
322 (erase-buffer))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
323 ))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
324
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
325
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
326 ;;;
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
327 ;;; Replacement of Low-Level Interface to NNTP Server.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
328 ;;;
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
329
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
330 (defun nnspool-open-server-internal (host &optional service)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
331 "Open connection to news server on HOST by SERVICE (default is nntp)."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
332 (save-excursion
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
333 (if (not (string-equal host (system-name)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
334 (error "NNSPOOL: cannot talk to %s." host))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
335 ;; Initialize communication buffer.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
336 (setq nntp-server-buffer (get-buffer-create " *nntpd*"))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
337 (set-buffer nntp-server-buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
338 (buffer-flush-undo (current-buffer))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
339 (erase-buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
340 (kill-all-local-variables)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
341 (setq case-fold-search t) ;Should ignore case.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
342 (setq nntp-server-process nil)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
343 (setq nntp-server-name host)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
344 ;; It is possible to change kanji-fileio-code in this hook.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
345 (run-hooks 'nntp-server-hook)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
346 t
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
347 ))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
348
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
349 (defun nnspool-close-server-internal ()
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
350 "Close connection to news server."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
351 (if (get-file-buffer nnspool-history-file)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
352 (kill-buffer (get-file-buffer nnspool-history-file)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
353 (if nntp-server-buffer
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
354 (kill-buffer nntp-server-buffer))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
355 (setq nntp-server-buffer nil)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
356 (setq nntp-server-process nil))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
357
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
358 (defun nnspool-find-article-by-message-id (id)
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 2843
diff changeset
359 "Return full pathname of an article identified by message-ID."
87
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
360 (save-excursion
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
361 (let ((buffer (get-file-buffer nnspool-history-file)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
362 (if buffer
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
363 (set-buffer buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
364 ;; Finding history file may take lots of time.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
365 (message "Reading history file...")
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
366 (set-buffer (find-file-noselect nnspool-history-file))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
367 (message "Reading history file... done")))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
368 ;; Search from end of the file. I think this is much faster than
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
369 ;; do from the beginning of the file.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
370 (goto-char (point-max))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
371 (if (re-search-backward
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
372 (concat "^" (regexp-quote id)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
373 "[ \t].*[ \t]\\([^ \t/]+\\)/\\([0-9]+\\)[ \t]*$") nil t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
374 (let ((group (buffer-substring (match-beginning 1) (match-end 1)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
375 (number (buffer-substring (match-beginning 2) (match-end 2))))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
376 (concat (nnspool-article-pathname
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
377 (nnspool-replace-chars-in-string group ?. ?/))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
378 number))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
379 )))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
380
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
381 (defun nnspool-find-file (file)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
382 "Insert FILE in server buffer safely."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
383 (set-buffer nntp-server-buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
384 (erase-buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
385 (condition-case ()
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
386 (progn (insert-file-contents file) t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
387 (file-error nil)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
388 ))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
389
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
390 (defun nnspool-article-pathname (group)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
391 "Make pathname for GROUP."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
392 (concat (file-name-as-directory nnspool-spool-directory) group "/"))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
393
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
394 (defun nnspool-replace-chars-in-string (string from to)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
395 "Replace characters in STRING from FROM to TO."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
396 (let ((string (substring string 0)) ;Copy string.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
397 (len (length string))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
398 (idx 0))
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 2843
diff changeset
399 ;; Replace all occurrences of FROM with TO.
87
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
400 (while (< idx len)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
401 (if (= (aref string idx) from)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
402 (aset string idx to))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
403 (setq idx (1+ idx)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
404 string
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
405 ))
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 232
diff changeset
406
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 232
diff changeset
407 (provide 'nnspool)
659
505130d1ddf8 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 584
diff changeset
408
505130d1ddf8 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 584
diff changeset
409 ;;; nnspool.el ends here