*** 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 (defalias 'nndir-request-post-buffer 'nnmail-request-post-buffer)
117
118 (defun nndir-request-expire-articles 
119   (articles group &optional server force)
120   (nndir-execute-nnmh-command
121    (` (nnmh-request-expire-articles (, articles) (, group) 
122                                     (, server) (, force)))))
123
124 (defun nndir-request-accept-article (group &optional last)
125   (nndir-execute-nnmh-command
126    (` (nnmh-request-accept-article (, group) (, last)))))
127
128 (defun nndir-close-group (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 (expand-file-name nndir-directory)))
147     (and (string-match "/$" dir)
148          (setq dir (substring dir 0 (match-beginning 0))))
149     (string-match "/[^/]+$" dir)
150     (let ((group (substring dir (1+ (match-beginning 0))))
151           (nnmh-directory (substring dir 0 (1+ (match-beginning 0))))
152           (nnmh-get-new-mail nil))
153       (eval command))))
154
155 (defun nndir-execute-nnml-command (command)
156   (let ((dir (expand-file-name nndir-directory)))
157     (and (string-match "/$" dir)
158          (setq dir (substring dir 0 (match-beginning 0))))
159     (string-match "/[^/]+$" dir)
160     (let ((group (substring dir (1+ (match-beginning 0))))
161           (nnml-directory (substring dir 0 (1+ (match-beginning 0))))
162           (nnml-nov-is-evil nndir-nov-is-evil)
163           (nnml-get-new-mail nil))
164       (eval command))))
165
166 (provide 'nndir)
167
168 ;;; nndir.el ends here