*** 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
33 (eval-and-compile
34   (autoload 'mail-send-and-exit "sendmail"))
35
36 (defvar nndir-directory nil)
37
38 \f
39
40 (defconst nndir-version "nndir 1.0")
41
42 (defvar nndir-status-string "")
43
44 (defvar nndir-nov-is-evil nil
45   "*Non-nil means that nndir will never retrieve NOV headers.")
46
47 \f
48
49 (defvar nndir-current-server nil)
50 (defvar nndir-server-alist nil)
51 (defvar nndir-server-variables 
52   (list
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 group server fetch-old)
63   (nndir-execute-nnml-command
64    (` (nnml-retrieve-headers 
65        (quote (, sequence)) group (, server) (, fetch-old)))))
66
67 (defun nndir-open-server (server &optional defs)
68   (nnheader-init-server-buffer)
69   (if (equal server nndir-current-server)
70       t
71     (if nndir-current-server
72         (setq nndir-server-alist 
73               (cons (list nndir-current-server
74                           (nnheader-save-variables nndir-server-variables))
75                     nndir-server-alist)))
76     (let ((state (assoc server nndir-server-alist)))
77       (if state 
78           (progn
79             (nnheader-restore-variables (nth 1 state))
80             (setq nndir-server-alist (delq state nndir-server-alist)))
81         (nnheader-set-init-variables nndir-server-variables defs))
82       (or (assq 'nndir-directory defs)
83           (setq nndir-directory server)))
84     (setq nndir-current-server server)))
85
86 (defun nndir-close-server (&optional server)
87   t)
88
89 (defun nndir-server-opened (&optional server)
90   (and nntp-server-buffer
91        (get-buffer nntp-server-buffer)
92        nndir-current-server
93        (equal nndir-current-server server)))
94
95 (defun nndir-status-message (&optional server)
96   nndir-status-string)
97
98 (defun nndir-request-article (id &optional group server buffer)
99   (nndir-execute-nnmh-command
100    (` (nnmh-request-article (, id) group (, server) (, buffer)))))
101
102 (defun nndir-request-group (group &optional server dont-check)
103   (nndir-execute-nnmh-command
104    (` (nnmh-request-group group "" (, dont-check)))))
105
106 (defun nndir-request-list (&optional server dir)
107   (nndir-execute-nnmh-command
108    (` (nnmh-request-list nil (, 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-post (&optional server)
115   (mail-send-and-exit nil))
116
117 (defun nndir-request-expire-articles 
118   (articles group &optional server force)
119   (nndir-execute-nnmh-command
120    (` (nnmh-request-expire-articles (quote (, articles)) group
121                                     (, server) (, force)))))
122
123 (defun nndir-request-accept-article (group &optional last)
124   (nndir-execute-nnmh-command
125    (` (nnmh-request-accept-article group (, last)))))
126
127 (defun nndir-close-group (group &optional server)
128   t)
129
130 (defun nndir-request-create-group (group &optional server)
131   (if (file-exists-p nndir-directory)
132       (if (file-directory-p nndir-directory)
133           t
134         nil)
135     (condition-case ()
136         (progn
137           (make-directory nndir-directory t)
138           t)
139       (file-error nil))))
140
141 \f
142 ;;; Low-Level Interface
143
144 (defun nndir-execute-nnmh-command (command)
145   (let ((dir (expand-file-name nndir-directory)))
146     (and (string-match "/$" dir)
147          (setq dir (substring dir 0 (match-beginning 0))))
148     (string-match "/[^/]+$" dir)
149     (let ((group (substring dir (1+ (match-beginning 0))))
150           (nnmh-directory (substring dir 0 (1+ (match-beginning 0))))
151           (nnmh-get-new-mail nil))
152       (eval command))))
153
154 (defun nndir-execute-nnml-command (command)
155   (let ((dir (expand-file-name nndir-directory)))
156     (and (string-match "/$" dir)
157          (setq dir (substring dir 0 (match-beginning 0))))
158     (string-match "/[^/]+$" dir)
159     (let ((group (substring dir (1+ (match-beginning 0))))
160           (nnml-directory (substring dir 0 (1+ (match-beginning 0))))
161           (nnml-nov-is-evil nndir-nov-is-evil)
162           (nnml-get-new-mail nil))
163       (eval command))))
164
165 (provide 'nndir)
166
167 ;;; nndir.el ends here