annotate lisp/=mhspool.el @ 1156:2a92ddfaf6ba

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