annotate lisp/=nnspool.el @ 2676:8958f29e417c

Don't include calc directory. Exclude many files in the man directory; copy a few.
author Richard M. Stallman <rms@gnu.org>
date Thu, 06 May 1993 18:11:39 +0000
parents bff32d8ecc5e
children cd90d49526ae
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
882
bff32d8ecc5e entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 853
diff changeset
3 ;; Copyright (C) 1988, 1989, 1990 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
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
40 (defvar nnspool-history-file "/usr/lib/news/history"
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
41 "*Local news history file.")
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
42
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
43
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
44
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
45 (defconst nnspool-version "NNSPOOL 1.10"
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
46 "Version numbers of this version of NNSPOOL.")
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
47
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
48 (defvar nnspool-current-directory nil
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
49 "Current news group directory.")
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
50
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
51 ;;;
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
52 ;;; Replacement of Extended Command for retrieving many headers.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
53 ;;;
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
54
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
55 (defun nnspool-retrieve-headers (sequence)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
56 "Return list of article headers specified by SEQUENCE of article id.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
57 The format of list is
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
58 `([NUMBER SUBJECT FROM XREF LINES DATE MESSAGE-ID REFERENCES] ...)'.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
59 Reader macros for the vector are defined as `nntp-header-FIELD'.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
60 Writer macros for the vector are defined as `nntp-set-header-FIELD'.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
61 News group must be selected before calling me."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
62 (save-excursion
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
63 (set-buffer nntp-server-buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
64 ;;(erase-buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
65 (let ((file nil)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
66 (number (length sequence))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
67 (count 0)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
68 (headers nil) ;Result list.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
69 (article 0)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
70 (subject nil)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
71 (message-id nil)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
72 (from nil)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
73 (xref nil)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
74 (lines 0)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
75 (date nil)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
76 (references nil))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
77 (while sequence
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
78 ;;(nntp-send-strings-to-server "HEAD" (car sequence))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
79 (setq article (car sequence))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
80 (setq file
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
81 (concat nnspool-current-directory (prin1-to-string article)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
82 (if (and (file-exists-p file)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
83 (not (file-directory-p file)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
84 (progn
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
85 (erase-buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
86 (insert-file-contents file)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
87 ;; Make message body invisible.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
88 (goto-char (point-min))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
89 (search-forward "\n\n" nil 'move)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
90 (narrow-to-region (point-min) (point))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
91 ;; Fold continuation lines.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
92 (goto-char (point-min))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
93 (while (re-search-forward "\\(\r?\n[ \t]+\\)+" nil t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
94 (replace-match " " t t))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
95 ;; Make it possible to search for `\nFIELD'.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
96 (goto-char (point-min))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
97 (insert "\n")
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
98 ;; Extract From:
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
99 (goto-char (point-min))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
100 (if (search-forward "\nFrom: " nil t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
101 (setq from (buffer-substring
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
102 (point)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
103 (save-excursion (end-of-line) (point))))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
104 (setq from "(Unknown User)"))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
105 ;; Extract Subject:
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 "\nSubject: " nil t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
108 (setq subject (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 subject "(None)"))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
112 ;; Extract Message-ID:
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 "\nMessage-ID: " nil t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
115 (setq message-id (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 message-id nil))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
119 ;; Extract Date:
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 "\nDate: " nil t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
122 (setq date (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 date nil))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
126 ;; Extract Lines:
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 "\nLines: " nil t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
129 (setq lines (string-to-int
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
130 (buffer-substring
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
131 (point)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
132 (save-excursion (end-of-line) (point)))))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
133 (setq lines 0))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
134 ;; Extract Xref:
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
135 (goto-char (point-min))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
136 (if (search-forward "\nXref: " nil t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
137 (setq xref (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 xref nil))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
141 ;; Extract References:
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 "\nReferences: " nil t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
144 (setq references (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 references nil))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
148 (setq headers
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
149 (cons (vector article subject from
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
150 xref lines date
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
151 message-id references) headers))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
152 ))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
153 (setq sequence (cdr sequence))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
154 (setq count (1+ count))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
155 (and (numberp nntp-large-newsgroup)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
156 (> number nntp-large-newsgroup)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
157 (zerop (% count 20))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
158 (message "NNSPOOL: %d%% of headers received."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
159 (/ (* count 100) number)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
160 )
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
161 (and (numberp nntp-large-newsgroup)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
162 (> number nntp-large-newsgroup)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
163 (message "NNSPOOL: 100%% of headers received."))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
164 (nreverse headers)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
165 )))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
166
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
167
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
168 ;;;
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
169 ;;; Replacement of NNTP Raw Interface.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
170 ;;;
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
171
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
172 (defun nnspool-open-server (host &optional service)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
173 "Open news server on HOST.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
174 If HOST is nil, use value of environment variable `NNTPSERVER'.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
175 If optional argument SERVICE is non-nil, open by the service name."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
176 (let ((host (or host (getenv "NNTPSERVER")))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
177 (status nil))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
178 (setq nntp-status-message-string "")
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
179 (cond ((and (file-directory-p nnspool-spool-directory)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
180 (file-exists-p nnspool-active-file)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
181 (string-equal host (system-name)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
182 (setq status (nnspool-open-server-internal host service)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
183 ((string-equal host (system-name))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
184 (setq nntp-status-message-string
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
185 (format "%s has no news spool. Goodbye." host)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
186 ((null host)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
187 (setq nntp-status-message-string "NNTP server is not specified."))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
188 (t
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
189 (setq nntp-status-message-string
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
190 (format "NNSPOOL: cannot talk to %s." host)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
191 )
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
192 status
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
193 ))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
194
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
195 (defun nnspool-close-server ()
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
196 "Close news server."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
197 (nnspool-close-server-internal))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
198
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
199 (fset 'nnspool-request-quit (symbol-function 'nnspool-close-server))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
200
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
201 (defun nnspool-server-opened ()
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
202 "Return server process status, T or NIL.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
203 If the stream is opened, return T, otherwise return NIL."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
204 (and nntp-server-buffer
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
205 (get-buffer nntp-server-buffer)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
206
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
207 (defun nnspool-status-message ()
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
208 "Return server status response as string."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
209 nntp-status-message-string
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
210 )
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
211
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
212 (defun nnspool-request-article (id)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
213 "Select article by message ID (or number)."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
214 (let ((file (if (stringp id)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
215 (nnspool-find-article-by-message-id id)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
216 (concat nnspool-current-directory (prin1-to-string id)))))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
217 (if (and (stringp file)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
218 (file-exists-p file)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
219 (not (file-directory-p file)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
220 (save-excursion
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
221 (nnspool-find-file file)))
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-body (id)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
225 "Select article body by message ID (or number)."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
226 (if (nnspool-request-article id)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
227 (save-excursion
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
228 (set-buffer nntp-server-buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
229 (goto-char (point-min))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
230 (if (search-forward "\n\n" nil t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
231 (delete-region (point-min) (point)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
232 t
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
233 )
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-head (id)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
237 "Select article head 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 (1- (point)) (point-max)))
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-stat (id)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
249 "Select article by message ID (or number)."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
250 (error "NNSPOOL: STAT is not implemented."))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
251
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
252 (defun nnspool-request-group (group)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
253 "Select news GROUP."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
254 (let ((pathname (nnspool-article-pathname
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
255 (nnspool-replace-chars-in-string group ?. ?/))))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
256 (if (file-directory-p pathname)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
257 (setq nnspool-current-directory pathname))
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-list ()
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
261 "List valid newsgoups."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
262 (save-excursion
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
263 (nnspool-find-file nnspool-active-file)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
264
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
265 (defun nnspool-request-last ()
232
c0bd9c7f9c42 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 87
diff changeset
266 "Set current article pointer to the previous article in the current news group."
87
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
267 (error "NNSPOOL: LAST is not implemented."))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
268
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
269 (defun nnspool-request-next ()
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
270 "Advance current article pointer."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
271 (error "NNSPOOL: NEXT is not implemented."))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
272
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
273 (defun nnspool-request-post ()
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
274 "Post a new news in current buffer."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
275 (save-excursion
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
276 ;; We have to work in the server buffer because of NEmacs hack.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
277 (copy-to-buffer nntp-server-buffer (point-min) (point-max))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
278 (set-buffer nntp-server-buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
279 (apply 'call-process-region
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
280 (point-min) (point-max)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
281 nnspool-inews-program 'delete t nil nnspool-inews-switches)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
282 (prog1
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
283 (or (zerop (buffer-size))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
284 ;; If inews returns strings, it must be error message
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
285 ;; unless SPOOLNEWS is defined.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
286 ;; This condition is very weak, but there is no good rule
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
287 ;; identifying errors when SPOOLNEWS is defined.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
288 ;; Suggested by ohm@kaba.junet.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
289 (string-match "spooled" (buffer-string)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
290 ;; Make status message by unfolding lines.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
291 (subst-char-in-region (point-min) (point-max) ?\n ?\\ 'noundo)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
292 (setq nntp-status-message-string (buffer-string))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
293 (erase-buffer))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
294 ))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
295
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
296
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
297 ;;;
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
298 ;;; Replacement of Low-Level Interface to NNTP Server.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
299 ;;;
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
300
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
301 (defun nnspool-open-server-internal (host &optional service)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
302 "Open connection to news server on HOST by SERVICE (default is nntp)."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
303 (save-excursion
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
304 (if (not (string-equal host (system-name)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
305 (error "NNSPOOL: cannot talk to %s." host))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
306 ;; Initialize communication buffer.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
307 (setq nntp-server-buffer (get-buffer-create " *nntpd*"))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
308 (set-buffer nntp-server-buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
309 (buffer-flush-undo (current-buffer))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
310 (erase-buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
311 (kill-all-local-variables)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
312 (setq case-fold-search t) ;Should ignore case.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
313 (setq nntp-server-process nil)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
314 (setq nntp-server-name host)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
315 ;; It is possible to change kanji-fileio-code in this hook.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
316 (run-hooks 'nntp-server-hook)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
317 t
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
318 ))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
319
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
320 (defun nnspool-close-server-internal ()
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
321 "Close connection to news server."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
322 (if (get-file-buffer nnspool-history-file)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
323 (kill-buffer (get-file-buffer nnspool-history-file)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
324 (if nntp-server-buffer
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
325 (kill-buffer nntp-server-buffer))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
326 (setq nntp-server-buffer nil)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
327 (setq nntp-server-process nil))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
328
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
329 (defun nnspool-find-article-by-message-id (id)
232
c0bd9c7f9c42 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 87
diff changeset
330 "Return full pathname of an article identified by message-ID."
87
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
331 (save-excursion
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
332 (let ((buffer (get-file-buffer nnspool-history-file)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
333 (if buffer
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
334 (set-buffer buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
335 ;; Finding history file may take lots of time.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
336 (message "Reading history file...")
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
337 (set-buffer (find-file-noselect nnspool-history-file))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
338 (message "Reading history file... done")))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
339 ;; Search from end of the file. I think this is much faster than
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
340 ;; do from the beginning of the file.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
341 (goto-char (point-max))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
342 (if (re-search-backward
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
343 (concat "^" (regexp-quote id)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
344 "[ \t].*[ \t]\\([^ \t/]+\\)/\\([0-9]+\\)[ \t]*$") nil t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
345 (let ((group (buffer-substring (match-beginning 1) (match-end 1)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
346 (number (buffer-substring (match-beginning 2) (match-end 2))))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
347 (concat (nnspool-article-pathname
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
348 (nnspool-replace-chars-in-string group ?. ?/))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
349 number))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
350 )))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
351
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
352 (defun nnspool-find-file (file)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
353 "Insert FILE in server buffer safely."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
354 (set-buffer nntp-server-buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
355 (erase-buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
356 (condition-case ()
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
357 (progn (insert-file-contents file) t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
358 (file-error nil)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
359 ))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
360
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
361 (defun nnspool-article-pathname (group)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
362 "Make pathname for GROUP."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
363 (concat (file-name-as-directory nnspool-spool-directory) group "/"))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
364
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
365 (defun nnspool-replace-chars-in-string (string from to)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
366 "Replace characters in STRING from FROM to TO."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
367 (let ((string (substring string 0)) ;Copy string.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
368 (len (length string))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
369 (idx 0))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
370 ;; Replace all occurence of FROM with TO.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
371 (while (< idx len)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
372 (if (= (aref string idx) from)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
373 (aset string idx to))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
374 (setq idx (1+ idx)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
375 string
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
376 ))
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 232
diff changeset
377
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 232
diff changeset
378 (provide 'nnspool)
659
505130d1ddf8 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 584
diff changeset
379
505130d1ddf8 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 584
diff changeset
380 ;;; nnspool.el ends here