annotate lisp/=nnspool.el @ 626:ff8773516db2

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