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