*** empty log message ***
[gnus] / lisp / nndir.el
1 ;;; nndir.el --- single directory newsgroup access for Gnus
2 ;; Copyright (C) 1995,96 Free Software Foundation, Inc.
3
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
5 ;;      Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
6 ;; Keywords: news
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;;; Code:
28
29 (require 'nnheader)
30 (require 'nnmh)
31 (require 'nnml)
32 (eval-when-compile (require 'cl))
33
34 (defvar nndir-directory nil
35   "Where nndir will look for groups.")
36
37 (defvar nndir-nov-is-evil nil
38   "*Non-nil means that nndir will never retrieve NOV headers.")
39
40 \f
41
42 (defconst nndir-version "nndir 1.0")
43
44 (defvar nndir-status-string "")
45
46 (defvar nndir-group "blououUOUOuuubhbh")
47
48 \f
49
50 (defvar nndir-current-server nil)
51 (defvar nndir-server-alist nil)
52 (defvar nndir-server-variables 
53   `((nndir-directory nil)
54     (nndir-status-string "")
55     (nndir-nov-is-evil ,nndir-nov-is-evil)
56     (nndir-group-alist nil)))
57
58 \f
59
60 ;;; Interface functions.
61
62
63 (defun nndir-retrieve-headers (sequence &optional 
64                                         nndir-group server fetch-old)
65   (nndir-execute-nnml-command
66    `(nnml-retrieve-headers ',sequence nndir-group ,server ,fetch-old)))
67
68 (defun nndir-open-server (server &optional defs)
69   (nnheader-change-server 'nndir server defs)
70   (unless (assq 'nndir-directory defs)
71     (setq nndir-directory server))
72   (let (err)
73     (cond 
74      ((not (condition-case arg
75                (file-exists-p nndir-directory)
76              (ftp-error (setq err (format "%s" arg)))))
77       (nndir-close-server)
78       (nnheader-report 
79        'nndir (or err "No such file or directory: %s" nndir-directory)))
80      ((not (file-directory-p (file-truename nndir-directory)))
81       (nndir-close-server)
82       (nnheader-report 'nndir "Not a directory: %s" nndir-directory))
83      (t
84       (nnheader-report 'nndir "Opened server %s using directory %s"
85                        server nndir-directory)
86       t))))
87
88 (defun nndir-close-server (&optional server)
89   (setq nndir-current-server nil)
90   t)
91
92 (defun nndir-server-opened (&optional server)
93   (and nntp-server-buffer
94        (get-buffer nntp-server-buffer)
95        nndir-current-server
96        (equal nndir-current-server server)))
97
98 (defun nndir-status-message (&optional server)
99   nndir-status-string)
100
101 (defun nndir-request-article (id &optional nndir-group server buffer)
102   (nndir-execute-nnmh-command
103    `(nnmh-request-article ,id nndir-group ,server ,buffer)))
104
105 (defun nndir-request-group (nndir-group &optional server dont-check)
106   (nndir-execute-nnmh-command
107    `(nnmh-request-group nndir-group "" ,dont-check)))
108
109 (defun nndir-request-list (&optional server dir)
110   (let ((nndir-directory (concat (file-name-as-directory
111                                   nndir-directory) "dummy")))
112     (nndir-execute-nnmh-command
113      `(nnmh-request-list ,(concat "nndir+" (or server "")) ,dir))))
114
115 (defun nndir-request-newgroups (date &optional server)
116   (nndir-execute-nnmh-command
117    `(nnmh-request-newgroups ,date ,server)))
118
119 (defun nndir-request-expire-articles 
120   (articles nndir-group &optional server force)
121   (nndir-execute-nnmh-command
122    `(nnmh-request-expire-articles ',articles nndir-group ,server ,force)))
123
124 (defun nndir-request-accept-article (nndir-group &optional server last)
125   (nndir-execute-nnmh-command
126    `(nnmh-request-accept-article nndir-group ,server ,last)))
127
128 (defun nndir-close-group (nndir-group &optional server)
129   t)
130
131 (defun nndir-request-create-group (group &optional server)
132   (if (file-exists-p nndir-directory)
133       (if (file-directory-p nndir-directory)
134           t
135         nil)
136     (condition-case ()
137         (progn
138           (make-directory nndir-directory t)
139           t)
140       (file-error nil))))
141
142 \f
143 ;;; Low-Level Interface
144
145 (defun nndir-execute-nnmh-command (command)
146   (let ((dir (file-name-as-directory (expand-file-name nndir-directory))))
147     (if (and (not (file-directory-p nndir-group))
148              (or (file-directory-p (concat dir nndir-group))
149                  (file-directory-p
150                   (concat dir (nnheader-replace-chars-in-string 
151                                nndir-group ?. ?/)))))
152         (let ((nnmh-directory nndir-directory)
153               (nnmh-get-new-mail nil))
154           (eval command))
155       (let ((dir (directory-file-name (expand-file-name nndir-directory))))
156         (string-match "/[^/]+$" dir)
157         (let ((nndir-group (substring dir (1+ (match-beginning 0))))
158               (nnmh-directory (substring dir 0 (1+ (match-beginning 0))))
159               (nnmh-get-new-mail nil))
160           (eval command))))))
161
162 (defun nndir-execute-nnml-command (command)
163   (let ((dir (file-name-as-directory (expand-file-name nndir-directory))))
164     (if (and (not (file-directory-p nndir-group))
165              (or (file-directory-p (concat dir nndir-group))
166                  (file-directory-p
167                   (concat dir (nnheader-replace-chars-in-string 
168                                nndir-group ?. ?/)))))
169         (let ((nnml-directory nndir-directory)
170               (nnml-nov-is-evil nndir-nov-is-evil)
171               (nnml-get-new-mail nil))
172           (eval command))
173       (let ((dir (directory-file-name (expand-file-name nndir-directory))))
174         (string-match "/[^/]+$" dir)
175         (let* ((nndir-group (substring dir (1+ (match-beginning 0))))
176                (nnml-directory (substring dir 0 (1+ (match-beginning 0))))
177                (nnml-nov-is-evil nndir-nov-is-evil)
178                (nnml-get-new-mail nil)
179                (defs `((nnml-directory ,nnml-directory)
180                        (nnml-nov-is-evil ,nnml-nov-is-evil)
181                        (nnml-get-new-mail))))
182           (unless (nnml-server-opened nndir-current-server)
183             (nnml-open-server nndir-current-server defs))
184           (eval command))))))
185
186 (provide 'nndir)
187
188 ;;; nndir.el ends here