*** 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-group-alist)))
56
57 \f
58
59 ;;; Interface functions.
60
61
62 (defun nndir-retrieve-headers (sequence &optional 
63                                         nndir-group server fetch-old)
64   (nndir-execute-nnml-command
65    `(nnml-retrieve-headers ',sequence nndir-group ,server ,fetch-old)))
66
67 (defun nndir-open-server (server &optional defs)
68   (nnheader-change-server 'nndir server defs)
69   (unless (assq 'nndir-directory defs)
70     (setq nndir-directory server))
71   (cond 
72    ((not (file-exists-p nndir-directory))
73     (nndir-close-server)
74     (nnheader-report 'nndir "No such file or directory: %s" nndir-directory))
75    ((not (file-directory-p (file-truename nndir-directory)))
76     (nndir-close-server)
77     (nnheader-report 'nndir "Not a directory: %s" nndir-directory))
78    (t
79     (nnheader-report 'nndir "Opened server %s using directory %s"
80                      server nndir-directory)
81     t)))
82
83 (defun nndir-close-server (&optional server)
84   (setq nndir-current-server nil)
85   t)
86
87 (defun nndir-server-opened (&optional server)
88   (and nntp-server-buffer
89        (get-buffer nntp-server-buffer)
90        nndir-current-server
91        (equal nndir-current-server server)))
92
93 (defun nndir-status-message (&optional server)
94   nndir-status-string)
95
96 (defun nndir-request-article (id &optional nndir-group server buffer)
97   (nndir-execute-nnmh-command
98    `(nnmh-request-article ,id nndir-group ,server ,buffer)))
99
100 (defun nndir-request-group (nndir-group &optional server dont-check)
101   (nndir-execute-nnmh-command
102    `(nnmh-request-group nndir-group "" ,dont-check)))
103
104 (defun nndir-request-list (&optional server dir)
105   (let ((nndir-directory (concat (file-name-as-directory
106                                   nndir-directory) "dummy")))
107     (nndir-execute-nnmh-command
108      `(nnmh-request-list ,(concat "nndir+" (or server "")) ,dir))))
109
110 (defun nndir-request-newgroups (date &optional server)
111   (nndir-execute-nnmh-command
112    `(nnmh-request-newgroups ,date ,server)))
113
114 (defun nndir-request-expire-articles 
115   (articles nndir-group &optional server force)
116   (nndir-execute-nnmh-command
117    `(nnmh-request-expire-articles ',articles nndir-group ,server ,force)))
118
119 (defun nndir-request-accept-article (nndir-group &optional last)
120   (nndir-execute-nnmh-command
121    `(nnmh-request-accept-article nndir-group ,last)))
122
123 (defun nndir-close-group (nndir-group &optional server)
124   t)
125
126 (defun nndir-request-create-group (group &optional server)
127   (if (file-exists-p nndir-directory)
128       (if (file-directory-p nndir-directory)
129           t
130         nil)
131     (condition-case ()
132         (progn
133           (make-directory nndir-directory t)
134           t)
135       (file-error nil))))
136
137 \f
138 ;;; Low-Level Interface
139
140 (defun nndir-execute-nnmh-command (command)
141   (let ((dir (file-name-as-directory (expand-file-name nndir-directory))))
142     (if (or (file-directory-p (concat dir nndir-group))
143             (file-directory-p
144              (concat dir (nnheader-replace-chars-in-string 
145                           nndir-group ?. ?/))))
146         (let ((nnmh-directory nndir-directory)
147               (nnmh-get-new-mail nil))
148           (eval command))
149       (let ((dir (directory-file-name (expand-file-name nndir-directory))))
150         (string-match "/[^/]+$" dir)
151         (let ((nndir-group (substring dir (1+ (match-beginning 0))))
152               (nnmh-directory (substring dir 0 (1+ (match-beginning 0))))
153               (nnmh-get-new-mail nil))
154           (eval command))))))
155
156 (defun nndir-execute-nnml-command (command)
157   (let ((dir (file-name-as-directory (expand-file-name nndir-directory))))
158     (if (or (file-directory-p (concat dir nndir-group))
159             (file-directory-p
160              (concat dir (nnheader-replace-chars-in-string 
161                           nndir-group ?. ?/))))
162         (let ((nnml-directory nndir-directory)
163               (nnml-nov-is-evil nndir-nov-is-evil)
164               (nnml-get-new-mail nil))
165           (eval command))
166       (let ((dir (directory-file-name (expand-file-name nndir-directory))))
167         (string-match "/[^/]+$" dir)
168         (let ((nndir-group (substring dir (1+ (match-beginning 0))))
169               (nnml-directory (substring dir 0 (1+ (match-beginning 0))))
170               (nnml-nov-is-evil nndir-nov-is-evil)
171               (nnml-get-new-mail nil))
172           (eval command))))))
173
174 (provide 'nndir)
175
176 ;;; nndir.el ends here