annotate lisp/=mhspool.el @ 166:4c0d89aec359

Initial revision
author Jim Blandy <jimb@redhat.com>
date Fri, 25 Jan 1991 22:24:59 +0000
parents d39407c00c09
children 5d476a289a86
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
87
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
1 ;;; MH folder 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: mhspool.el,v 1.5 90/03/23 13:25:23 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 'mhspool)
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 ;; This package enables you to read mail or articles in MH folders, or
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
27 ;; articles saved by GNUS. In any case, the file names of mail or
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
28 ;; articles must consist of only numeric letters.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
29
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
30 ;; Before using this package, you have to create a server specific
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
31 ;; startup file according to the directory which you want to read. For
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
32 ;; example, if you want to read mail under the directory named
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
33 ;; `~/Mail', the file must be a file named `.newsrc-:Mail'. (There is
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
34 ;; no way to specify hierarchical directory now.) In this case, the
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
35 ;; name of the NNTP server passed to GNUS must be `:Mail'.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
36
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
37 (defvar mhspool-list-directory-switches '("-R")
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
38 "*Switches for nntp-request-list to pass to `ls' for gettting file lists.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
39 One entry should appear on one line. You may need to add `-1' option.")
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 mhspool-version "MHSPOOL 1.5"
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
44 "Version numbers of this version of MHSPOOL.")
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
45
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
46 (defvar mhspool-spool-directory "~/Mail"
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
47 "Private mail directory.")
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
48
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
49 (defvar mhspool-current-directory nil
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
50 "Current news group directory.")
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 ;;; Replacement of Extended Command for retrieving many headers.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
54 ;;;
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
55
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
56 (defun mhspool-retrieve-headers (sequence)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
57 "Return list of article headers specified by SEQUENCE of article id.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
58 The format of list is
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
59 `([NUMBER SUBJECT FROM XREF LINES DATE MESSAGE-ID REFERENCES] ...)'.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
60 Reader macros for the vector are defined as `nntp-header-FIELD'.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
61 Writer macros for the vector are defined as `nntp-set-header-FIELD'.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
62 News group must be selected before calling me."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
63 (save-excursion
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
64 (set-buffer nntp-server-buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
65 ;;(erase-buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
66 (let ((file nil)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
67 (number (length sequence))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
68 (count 0)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
69 (headers nil) ;Result list.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
70 (article 0)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
71 (subject nil)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
72 (message-id nil)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
73 (from nil)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
74 (xref nil)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
75 (lines 0)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
76 (date nil)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
77 (references nil))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
78 (while sequence
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
79 ;;(nntp-send-strings-to-server "HEAD" (car sequence))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
80 (setq article (car sequence))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
81 (setq file
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
82 (concat mhspool-current-directory (prin1-to-string article)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
83 (if (and (file-exists-p file)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
84 (not (file-directory-p file)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
85 (progn
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
86 (erase-buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
87 (insert-file-contents file)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
88 ;; Make message body invisible.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
89 (goto-char (point-min))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
90 (search-forward "\n\n" nil 'move)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
91 (narrow-to-region (point-min) (point))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
92 ;; Fold continuation lines.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
93 (goto-char (point-min))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
94 (while (re-search-forward "\\(\r?\n[ \t]+\\)+" nil t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
95 (replace-match " " t t))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
96 ;; Make it possible to search for `\nFIELD'.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
97 (goto-char (point-min))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
98 (insert "\n")
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
99 ;; Extract From:
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
100 (goto-char (point-min))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
101 (if (search-forward "\nFrom: " nil t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
102 (setq from (buffer-substring
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
103 (point)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
104 (save-excursion (end-of-line) (point))))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
105 (setq from "(Unknown User)"))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
106 ;; Extract Subject:
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
107 (goto-char (point-min))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
108 (if (search-forward "\nSubject: " nil t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
109 (setq subject (buffer-substring
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
110 (point)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
111 (save-excursion (end-of-line) (point))))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
112 (setq subject "(None)"))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
113 ;; Extract Message-ID:
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
114 (goto-char (point-min))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
115 (if (search-forward "\nMessage-ID: " nil t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
116 (setq message-id (buffer-substring
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
117 (point)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
118 (save-excursion (end-of-line) (point))))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
119 (setq message-id nil))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
120 ;; Extract Date:
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
121 (goto-char (point-min))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
122 (if (search-forward "\nDate: " nil t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
123 (setq date (buffer-substring
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
124 (point)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
125 (save-excursion (end-of-line) (point))))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
126 (setq date nil))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
127 ;; Extract Lines:
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
128 (goto-char (point-min))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
129 (if (search-forward "\nLines: " nil t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
130 (setq lines (string-to-int
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
131 (buffer-substring
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
132 (point)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
133 (save-excursion (end-of-line) (point)))))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
134 (setq lines 0))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
135 ;; Extract Xref:
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
136 (goto-char (point-min))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
137 (if (search-forward "\nXref: " nil t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
138 (setq xref (buffer-substring
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
139 (point)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
140 (save-excursion (end-of-line) (point))))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
141 (setq xref nil))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
142 ;; Extract References:
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
143 ;; If no References: field, use In-Reply-To: field instead.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
144 ;; Suggested by tanaka@flab.fujitsu.co.jp (Hiroshi TANAKA).
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
145 (goto-char (point-min))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
146 (if (or (search-forward "\nReferences: " nil t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
147 (search-forward "\nIn-Reply-To: " nil t))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
148 (setq references (buffer-substring
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
149 (point)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
150 (save-excursion (end-of-line) (point))))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
151 (setq references nil))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
152 (setq headers
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
153 (cons (vector article subject from
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
154 xref lines date
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
155 message-id references) headers))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
156 ))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
157 (setq sequence (cdr sequence))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
158 (setq count (1+ count))
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 (zerop (% count 20))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
162 (message "MHSPOOL: %d%% of headers received."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
163 (/ (* count 100) number)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
164 )
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
165 (and (numberp nntp-large-newsgroup)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
166 (> number nntp-large-newsgroup)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
167 (message "MHSPOOL: 100%% of headers received."))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
168 (nreverse headers)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
169 )))
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 ;;;
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
173 ;;; Replacement of NNTP Raw Interface.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
174 ;;;
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
175
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
176 (defun mhspool-open-server (host &optional service)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
177 "Open news server on HOST.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
178 If HOST is nil, use value of environment variable `NNTPSERVER'.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
179 If optional argument SERVICE is non-nil, open by the service name."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
180 (let ((host (or host (getenv "NNTPSERVER")))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
181 (status nil))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
182 ;; Get directory name from HOST name.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
183 (if (string-match ":\\(.+\\)$" host)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
184 (progn
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
185 (setq mhspool-spool-directory
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
186 (file-name-as-directory
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
187 (expand-file-name
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
188 (substring host (match-beginning 1) (match-end 1))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
189 (expand-file-name "~/" nil))))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
190 (setq host (system-name)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
191 (setq mhspool-spool-directory nil))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
192 (setq nntp-status-message-string "")
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
193 (cond ((and (stringp host)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
194 (stringp mhspool-spool-directory)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
195 (file-directory-p mhspool-spool-directory)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
196 (string-equal host (system-name)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
197 (setq status (mhspool-open-server-internal host service)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
198 ((string-equal host (system-name))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
199 (setq nntp-status-message-string
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
200 (format "No such directory: %s. Goodbye."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
201 mhspool-spool-directory)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
202 ((null host)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
203 (setq nntp-status-message-string "NNTP server is not specified."))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
204 (t
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
205 (setq nntp-status-message-string
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
206 (format "MHSPOOL: cannot talk to %s." host)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
207 )
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
208 status
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
209 ))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
210
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
211 (defun mhspool-close-server ()
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
212 "Close news server."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
213 (mhspool-close-server-internal))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
214
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
215 (fset 'mhspool-request-quit (symbol-function 'mhspool-close-server))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
216
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
217 (defun mhspool-server-opened ()
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
218 "Return server process status, T or NIL.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
219 If the stream is opened, return T, otherwise return NIL."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
220 (and nntp-server-buffer
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
221 (get-buffer nntp-server-buffer)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
222
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
223 (defun mhspool-status-message ()
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
224 "Return server status response as string."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
225 nntp-status-message-string
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
226 )
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
227
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
228 (defun mhspool-request-article (id)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
229 "Select article by message ID (or number)."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
230 (let ((file (concat mhspool-current-directory (prin1-to-string id))))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
231 (if (and (stringp file)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
232 (file-exists-p file)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
233 (not (file-directory-p file)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
234 (save-excursion
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
235 (mhspool-find-file file)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
236 ))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
237
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
238 (defun mhspool-request-body (id)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
239 "Select article body by message ID (or number)."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
240 (if (mhspool-request-article id)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
241 (save-excursion
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
242 (set-buffer nntp-server-buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
243 (goto-char (point-min))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
244 (if (search-forward "\n\n" nil t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
245 (delete-region (point-min) (point)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
246 t
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
247 )
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
248 ))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
249
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
250 (defun mhspool-request-head (id)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
251 "Select article head by message ID (or number)."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
252 (if (mhspool-request-article id)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
253 (save-excursion
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
254 (set-buffer nntp-server-buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
255 (goto-char (point-min))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
256 (if (search-forward "\n\n" nil t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
257 (delete-region (1- (point)) (point-max)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
258 t
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
259 )
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
260 ))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
261
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
262 (defun mhspool-request-stat (id)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
263 "Select article by message ID (or number)."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
264 (error "MHSPOOL: STAT is not implemented."))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
265
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
266 (defun mhspool-request-group (group)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
267 "Select news GROUP."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
268 (cond ((file-directory-p
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
269 (mhspool-article-pathname group))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
270 ;; Mail/NEWS.GROUP/N
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
271 (setq mhspool-current-directory
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
272 (mhspool-article-pathname group)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
273 ((file-directory-p
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
274 (mhspool-article-pathname
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
275 (mhspool-replace-chars-in-string group ?. ?/)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
276 ;; Mail/NEWS/GROUP/N
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
277 (setq mhspool-current-directory
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
278 (mhspool-article-pathname
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
279 (mhspool-replace-chars-in-string group ?. ?/))))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
280 ))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
281
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
282 (defun mhspool-request-list ()
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
283 "List valid newsgoups."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
284 (save-excursion
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
285 (let* ((newsgroup nil)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
286 (articles nil)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
287 (directory (file-name-as-directory
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
288 (expand-file-name mhspool-spool-directory nil)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
289 (folder-regexp (concat "^" (regexp-quote directory) "\\(.+\\):$"))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
290 (buffer (get-buffer-create " *GNUS file listing*")))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
291 (set-buffer nntp-server-buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
292 (erase-buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
293 (set-buffer buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
294 (erase-buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
295 (apply 'call-process
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
296 "ls" nil t nil
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
297 (append mhspool-list-directory-switches (list directory)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
298 (goto-char (point-min))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
299 (while (re-search-forward folder-regexp nil t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
300 (setq newsgroup
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
301 (mhspool-replace-chars-in-string
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
302 (buffer-substring (match-beginning 1) (match-end 1)) ?/ ?.))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
303 (setq articles nil)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
304 (forward-line 1) ;(beginning-of-line)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
305 ;; Thank nobu@flab.fujitsu.junet for his bug fixes.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
306 (while (and (not (eobp))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
307 (not (looking-at "^$")))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
308 (if (looking-at "^[0-9]+$")
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
309 (setq articles
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
310 (cons (string-to-int
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
311 (buffer-substring
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
312 (match-beginning 0) (match-end 0)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
313 articles)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
314 (forward-line 1))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
315 (if articles
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
316 (princ (format "%s %d %d n\n" newsgroup
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
317 (apply (function max) articles)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
318 (apply (function min) articles))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
319 nntp-server-buffer))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
320 )
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
321 (kill-buffer buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
322 (set-buffer nntp-server-buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
323 (buffer-size)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
324 )))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
325
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
326 (defun mhspool-request-last ()
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
327 "Set current article pointer to the previous article
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
328 in the current news group."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
329 (error "MHSPOOL: LAST is not implemented."))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
330
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
331 (defun mhspool-request-next ()
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
332 "Advance current article pointer."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
333 (error "MHSPOOL: NEXT is not implemented."))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
334
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
335 (defun mhspool-request-post ()
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
336 "Post a new news in current buffer."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
337 (setq nntp-status-message-string "MHSPOOL: what do you mean post?")
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
338 nil
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
339 )
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
340
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
341
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
342 ;;;
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
343 ;;; Replacement of Low-Level Interface to NNTP Server.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
344 ;;;
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
345
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
346 (defun mhspool-open-server-internal (host &optional service)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
347 "Open connection to news server on HOST by SERVICE (default is nntp)."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
348 (save-excursion
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
349 (if (not (string-equal host (system-name)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
350 (error "MHSPOOL: cannot talk to %s." host))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
351 ;; Initialize communication buffer.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
352 (setq nntp-server-buffer (get-buffer-create " *nntpd*"))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
353 (set-buffer nntp-server-buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
354 (buffer-flush-undo (current-buffer))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
355 (erase-buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
356 (kill-all-local-variables)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
357 (setq case-fold-search t) ;Should ignore case.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
358 (setq nntp-server-process nil)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
359 (setq nntp-server-name host)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
360 ;; It is possible to change kanji-fileio-code in this hook.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
361 (run-hooks 'nntp-server-hook)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
362 t
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
363 ))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
364
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
365 (defun mhspool-close-server-internal ()
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
366 "Close connection to news server."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
367 (if nntp-server-buffer
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
368 (kill-buffer nntp-server-buffer))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
369 (setq nntp-server-buffer nil)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
370 (setq nntp-server-process nil))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
371
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
372 (defun mhspool-find-file (file)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
373 "Insert FILE in server buffer safely."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
374 (set-buffer nntp-server-buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
375 (erase-buffer)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
376 (condition-case ()
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
377 (progn
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
378 (insert-file-contents file)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
379 (goto-char (point-min))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
380 ;; If there is no body, `^L' appears at end of file. Special
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
381 ;; hack for MH folder.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
382 (and (search-forward "\n\n" nil t)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
383 (string-equal (buffer-substring (point) (point-max)) "\^L")
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
384 (delete-char 1))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
385 t
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
386 )
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
387 (file-error nil)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
388 ))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
389
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
390 (defun mhspool-article-pathname (group)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
391 "Make pathname for GROUP."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
392 (concat (file-name-as-directory mhspool-spool-directory) group "/"))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
393
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
394 (defun mhspool-replace-chars-in-string (string from to)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
395 "Replace characters in STRING from FROM to TO."
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
396 (let ((string (substring string 0)) ;Copy string.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
397 (len (length string))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
398 (idx 0))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
399 ;; Replace all occurence of FROM with TO.
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
400 (while (< idx len)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
401 (if (= (aref string idx) from)
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
402 (aset string idx to))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
403 (setq idx (1+ idx)))
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
404 string
d39407c00c09 Initial revision
root <root>
parents:
diff changeset
405 ))