annotate lisp/=mhspool.el @ 605:5f36058e31f9

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