annotate lisp/=nnspool.el @ 170:b062439c29cd

Initial revision
author Jim Blandy <jimb@redhat.com>
date Mon, 28 Jan 1991 18:42:22 +0000
parents d39407c00c09
children c0bd9c7f9c42
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
87
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
1 ;;; Spool access using NNTP for GNU Emacs
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
2 ;; Copyright (C) 1988, 1989 Fujitsu Laboratories LTD.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
3 ;; Copyright (C) 1988, 1989, 1990 Masanobu UMEDA
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
4 ;; $Header: nnspool.el,v 1.10 90/03/23 13:25:25 umerin Locked $
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
5
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
6 ;; This file is part of GNU Emacs.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
7
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
8 ;; GNU Emacs is distributed in the hope that it will be useful,
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
9 ;; but WITHOUT ANY WARRANTY. No author or distributor
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
10 ;; accepts responsibility to anyone for the consequences of using it
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
11 ;; or for whether it serves any particular purpose or works at all,
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
12 ;; unless he says so in writing. Refer to the GNU Emacs General Public
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
13 ;; License for full details.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
14
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
15 ;; Everyone is granted permission to copy, modify and redistribute
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
16 ;; GNU Emacs, but only under the conditions described in the
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
17 ;; GNU Emacs General Public License. A copy of this license is
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
18 ;; supposed to have been given to you along with GNU Emacs so you
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
19 ;; can know your rights and responsibilities. It should be in a
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
20 ;; file named COPYING. Among other things, the copyright notice
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
21 ;; and this notice must be preserved on all copies.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
22
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
23 (provide 'nnspool)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
24 (require 'nntp)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
25
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
26 (defvar nnspool-inews-program news-inews-program
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
27 "*Program to post news.")
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
28
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
29 (defvar nnspool-inews-switches '("-h")
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
30 "*Switches for nnspool-request-post to pass to `inews' for posting news.")
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
31
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
32 (defvar nnspool-spool-directory news-path
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
33 "*Local news spool directory.")
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
34
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
35 (defvar nnspool-active-file "/usr/lib/news/active"
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
36 "*Local news active file.")
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
37
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
38 (defvar nnspool-history-file "/usr/lib/news/history"
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
39 "*Local news history file.")
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
40
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
41
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
42
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
43 (defconst nnspool-version "NNSPOOL 1.10"
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
44 "Version numbers of this version of NNSPOOL.")
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
45
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
46 (defvar nnspool-current-directory nil
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
47 "Current news group directory.")
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 ;;; Replacement of Extended Command for retrieving many headers.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
51 ;;;
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
52
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
53 (defun nnspool-retrieve-headers (sequence)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
54 "Return list of article headers specified by SEQUENCE of article id.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
55 The format of list is
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
56 `([NUMBER SUBJECT FROM XREF LINES DATE MESSAGE-ID REFERENCES] ...)'.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
57 Reader macros for the vector are defined as `nntp-header-FIELD'.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
58 Writer macros for the vector are defined as `nntp-set-header-FIELD'.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
59 News group must be selected before calling me."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
60 (save-excursion
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
61 (set-buffer nntp-server-buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
62 ;;(erase-buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
63 (let ((file nil)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
64 (number (length sequence))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
65 (count 0)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
66 (headers nil) ;Result list.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
67 (article 0)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
68 (subject nil)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
69 (message-id nil)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
70 (from nil)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
71 (xref nil)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
72 (lines 0)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
73 (date nil)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
74 (references nil))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
75 (while sequence
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
76 ;;(nntp-send-strings-to-server "HEAD" (car sequence))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
77 (setq article (car sequence))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
78 (setq file
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
79 (concat nnspool-current-directory (prin1-to-string article)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
80 (if (and (file-exists-p file)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
81 (not (file-directory-p file)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
82 (progn
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
83 (erase-buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
84 (insert-file-contents file)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
85 ;; Make message body invisible.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
86 (goto-char (point-min))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
87 (search-forward "\n\n" nil 'move)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
88 (narrow-to-region (point-min) (point))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
89 ;; Fold continuation lines.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
90 (goto-char (point-min))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
91 (while (re-search-forward "\\(\r?\n[ \t]+\\)+" nil t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
92 (replace-match " " t t))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
93 ;; Make it possible to search for `\nFIELD'.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
94 (goto-char (point-min))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
95 (insert "\n")
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
96 ;; Extract From:
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
97 (goto-char (point-min))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
98 (if (search-forward "\nFrom: " nil t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
99 (setq from (buffer-substring
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
100 (point)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
101 (save-excursion (end-of-line) (point))))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
102 (setq from "(Unknown User)"))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
103 ;; Extract Subject:
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
104 (goto-char (point-min))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
105 (if (search-forward "\nSubject: " nil t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
106 (setq subject (buffer-substring
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
107 (point)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
108 (save-excursion (end-of-line) (point))))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
109 (setq subject "(None)"))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
110 ;; Extract Message-ID:
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
111 (goto-char (point-min))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
112 (if (search-forward "\nMessage-ID: " nil t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
113 (setq message-id (buffer-substring
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
114 (point)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
115 (save-excursion (end-of-line) (point))))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
116 (setq message-id nil))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
117 ;; Extract Date:
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
118 (goto-char (point-min))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
119 (if (search-forward "\nDate: " nil t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
120 (setq date (buffer-substring
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
121 (point)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
122 (save-excursion (end-of-line) (point))))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
123 (setq date nil))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
124 ;; Extract Lines:
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
125 (goto-char (point-min))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
126 (if (search-forward "\nLines: " nil t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
127 (setq lines (string-to-int
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
128 (buffer-substring
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
129 (point)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
130 (save-excursion (end-of-line) (point)))))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
131 (setq lines 0))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
132 ;; Extract Xref:
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
133 (goto-char (point-min))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
134 (if (search-forward "\nXref: " nil t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
135 (setq xref (buffer-substring
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
136 (point)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
137 (save-excursion (end-of-line) (point))))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
138 (setq xref nil))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
139 ;; Extract References:
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
140 (goto-char (point-min))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
141 (if (search-forward "\nReferences: " nil t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
142 (setq references (buffer-substring
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
143 (point)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
144 (save-excursion (end-of-line) (point))))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
145 (setq references nil))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
146 (setq headers
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
147 (cons (vector article subject from
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
148 xref lines date
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
149 message-id references) headers))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
150 ))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
151 (setq sequence (cdr sequence))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
152 (setq count (1+ count))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
153 (and (numberp nntp-large-newsgroup)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
154 (> number nntp-large-newsgroup)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
155 (zerop (% count 20))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
156 (message "NNSPOOL: %d%% of headers received."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
157 (/ (* count 100) number)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
158 )
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
159 (and (numberp nntp-large-newsgroup)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
160 (> number nntp-large-newsgroup)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
161 (message "NNSPOOL: 100%% of headers received."))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
162 (nreverse headers)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
163 )))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
164
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 ;;; Replacement of NNTP Raw Interface.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
168 ;;;
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
169
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
170 (defun nnspool-open-server (host &optional service)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
171 "Open news server on HOST.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
172 If HOST is nil, use value of environment variable `NNTPSERVER'.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
173 If optional argument SERVICE is non-nil, open by the service name."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
174 (let ((host (or host (getenv "NNTPSERVER")))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
175 (status nil))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
176 (setq nntp-status-message-string "")
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
177 (cond ((and (file-directory-p nnspool-spool-directory)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
178 (file-exists-p nnspool-active-file)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
179 (string-equal host (system-name)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
180 (setq status (nnspool-open-server-internal host service)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
181 ((string-equal host (system-name))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
182 (setq nntp-status-message-string
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
183 (format "%s has no news spool. Goodbye." host)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
184 ((null host)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
185 (setq nntp-status-message-string "NNTP server is not specified."))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
186 (t
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
187 (setq nntp-status-message-string
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
188 (format "NNSPOOL: cannot talk to %s." host)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
189 )
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
190 status
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
191 ))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
192
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
193 (defun nnspool-close-server ()
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
194 "Close news server."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
195 (nnspool-close-server-internal))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
196
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
197 (fset 'nnspool-request-quit (symbol-function 'nnspool-close-server))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
198
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
199 (defun nnspool-server-opened ()
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
200 "Return server process status, T or NIL.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
201 If the stream is opened, return T, otherwise return NIL."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
202 (and nntp-server-buffer
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
203 (get-buffer nntp-server-buffer)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
204
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
205 (defun nnspool-status-message ()
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
206 "Return server status response as string."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
207 nntp-status-message-string
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
208 )
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
209
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
210 (defun nnspool-request-article (id)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
211 "Select article by message ID (or number)."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
212 (let ((file (if (stringp id)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
213 (nnspool-find-article-by-message-id id)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
214 (concat nnspool-current-directory (prin1-to-string id)))))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
215 (if (and (stringp file)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
216 (file-exists-p file)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
217 (not (file-directory-p file)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
218 (save-excursion
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
219 (nnspool-find-file file)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
220 ))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
221
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
222 (defun nnspool-request-body (id)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
223 "Select article body by message ID (or number)."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
224 (if (nnspool-request-article id)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
225 (save-excursion
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
226 (set-buffer nntp-server-buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
227 (goto-char (point-min))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
228 (if (search-forward "\n\n" nil t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
229 (delete-region (point-min) (point)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
230 t
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
231 )
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
232 ))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
233
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
234 (defun nnspool-request-head (id)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
235 "Select article head by message ID (or number)."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
236 (if (nnspool-request-article id)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
237 (save-excursion
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
238 (set-buffer nntp-server-buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
239 (goto-char (point-min))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
240 (if (search-forward "\n\n" nil t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
241 (delete-region (1- (point)) (point-max)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
242 t
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
243 )
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
244 ))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
245
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
246 (defun nnspool-request-stat (id)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
247 "Select article by message ID (or number)."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
248 (error "NNSPOOL: STAT is not implemented."))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
249
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
250 (defun nnspool-request-group (group)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
251 "Select news GROUP."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
252 (let ((pathname (nnspool-article-pathname
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
253 (nnspool-replace-chars-in-string group ?. ?/))))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
254 (if (file-directory-p pathname)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
255 (setq nnspool-current-directory pathname))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
256 ))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
257
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
258 (defun nnspool-request-list ()
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
259 "List valid newsgoups."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
260 (save-excursion
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
261 (nnspool-find-file nnspool-active-file)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
262
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
263 (defun nnspool-request-last ()
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
264 "Set current article pointer to the previous article
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
265 in the current news group."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
266 (error "NNSPOOL: LAST is not implemented."))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
267
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
268 (defun nnspool-request-next ()
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
269 "Advance current article pointer."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
270 (error "NNSPOOL: NEXT is not implemented."))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
271
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
272 (defun nnspool-request-post ()
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
273 "Post a new news in current buffer."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
274 (save-excursion
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
275 ;; We have to work in the server buffer because of NEmacs hack.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
276 (copy-to-buffer nntp-server-buffer (point-min) (point-max))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
277 (set-buffer nntp-server-buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
278 (apply 'call-process-region
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
279 (point-min) (point-max)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
280 nnspool-inews-program 'delete t nil nnspool-inews-switches)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
281 (prog1
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
282 (or (zerop (buffer-size))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
283 ;; If inews returns strings, it must be error message
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
284 ;; unless SPOOLNEWS is defined.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
285 ;; This condition is very weak, but there is no good rule
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
286 ;; identifying errors when SPOOLNEWS is defined.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
287 ;; Suggested by ohm@kaba.junet.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
288 (string-match "spooled" (buffer-string)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
289 ;; Make status message by unfolding lines.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
290 (subst-char-in-region (point-min) (point-max) ?\n ?\\ 'noundo)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
291 (setq nntp-status-message-string (buffer-string))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
292 (erase-buffer))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
293 ))
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 ;;; Replacement of Low-Level Interface to NNTP Server.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
298 ;;;
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
299
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
300 (defun nnspool-open-server-internal (host &optional service)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
301 "Open connection to news server on HOST by SERVICE (default is nntp)."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
302 (save-excursion
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
303 (if (not (string-equal host (system-name)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
304 (error "NNSPOOL: cannot talk to %s." host))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
305 ;; Initialize communication buffer.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
306 (setq nntp-server-buffer (get-buffer-create " *nntpd*"))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
307 (set-buffer nntp-server-buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
308 (buffer-flush-undo (current-buffer))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
309 (erase-buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
310 (kill-all-local-variables)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
311 (setq case-fold-search t) ;Should ignore case.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
312 (setq nntp-server-process nil)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
313 (setq nntp-server-name host)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
314 ;; It is possible to change kanji-fileio-code in this hook.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
315 (run-hooks 'nntp-server-hook)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
316 t
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
317 ))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
318
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
319 (defun nnspool-close-server-internal ()
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
320 "Close connection to news server."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
321 (if (get-file-buffer nnspool-history-file)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
322 (kill-buffer (get-file-buffer nnspool-history-file)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
323 (if nntp-server-buffer
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
324 (kill-buffer nntp-server-buffer))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
325 (setq nntp-server-buffer nil)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
326 (setq nntp-server-process nil))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
327
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
328 (defun nnspool-find-article-by-message-id (id)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
329 "Return full pathname of an artilce identified by message-ID."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
330 (save-excursion
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
331 (let ((buffer (get-file-buffer nnspool-history-file)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
332 (if buffer
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
333 (set-buffer buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
334 ;; Finding history file may take lots of time.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
335 (message "Reading history file...")
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
336 (set-buffer (find-file-noselect nnspool-history-file))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
337 (message "Reading history file... done")))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
338 ;; Search from end of the file. I think this is much faster than
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
339 ;; do from the beginning of the file.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
340 (goto-char (point-max))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
341 (if (re-search-backward
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
342 (concat "^" (regexp-quote id)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
343 "[ \t].*[ \t]\\([^ \t/]+\\)/\\([0-9]+\\)[ \t]*$") nil t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
344 (let ((group (buffer-substring (match-beginning 1) (match-end 1)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
345 (number (buffer-substring (match-beginning 2) (match-end 2))))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
346 (concat (nnspool-article-pathname
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
347 (nnspool-replace-chars-in-string group ?. ?/))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
348 number))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
349 )))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
350
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
351 (defun nnspool-find-file (file)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
352 "Insert FILE in server buffer safely."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
353 (set-buffer nntp-server-buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
354 (erase-buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
355 (condition-case ()
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
356 (progn (insert-file-contents file) t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
357 (file-error nil)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
358 ))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
359
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
360 (defun nnspool-article-pathname (group)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
361 "Make pathname for GROUP."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
362 (concat (file-name-as-directory nnspool-spool-directory) group "/"))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
363
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
364 (defun nnspool-replace-chars-in-string (string from to)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
365 "Replace characters in STRING from FROM to TO."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
366 (let ((string (substring string 0)) ;Copy string.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
367 (len (length string))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
368 (idx 0))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
369 ;; Replace all occurence of FROM with TO.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
370 (while (< idx len)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
371 (if (= (aref string idx) from)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
372 (aset string idx to))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
373 (setq idx (1+ idx)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
374 string
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
375 ))