*** 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 Ingebrigtsen <larsi@ifi.uio.no>
5 ;;      Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
6 ;; Keywords: news, mail
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 \f
33
34 (defconst nndir-version "nndir 0.0")
35
36 (defvar nndir-current-directory nil
37   "Current news group directory.")
38
39 (defvar nndir-status-string "")
40
41 (defvar nndir-nov-is-evil nil
42   "*Non-nil means that nndir will never retrieve NOV headers.")
43
44 \f
45
46 ;;; Interface functions.
47
48
49 (defun nndir-retrieve-headers (sequence &optional newsgroup server)
50   (nndir-execute-nnml-command
51    '(nnml-retrieve-headers sequence group server) server))
52
53 (defun nndir-open-server (host &optional service)
54   "Open nndir backend."
55   (setq nndir-status-string "")
56   (nndir-open-server-internal host service))
57
58 (defun nndir-close-server (&optional server)
59   "Close news server."
60   (nndir-close-server-internal))
61
62 (defalias 'nndir-request-quit 'nndir-close-server)
63
64 (defun nndir-server-opened (&optional server)
65   "Return server process status, T or NIL.
66 If the stream is opened, return T, otherwise return NIL."
67   (and nntp-server-buffer
68        (get-buffer nntp-server-buffer)))
69
70 (defun nndir-status-message ()
71   "Return server status response as string."
72   nndir-status-string)
73
74 (defun nndir-request-article (id &optional newsgroup server buffer)
75   (nndir-execute-nnmh-command
76    '(nnmh-request-article id group server buffer) server))
77
78 (defun nndir-request-group (group &optional server dont-check)
79   "Select news GROUP."
80   (nndir-execute-nnmh-command
81    '(nnmh-request-group group "" dont-check) server))
82
83 (defun nndir-request-list (&optional server dir)
84   "Get list of active articles in all newsgroups."
85   (nndir-execute-nnmh-command
86    '(nnmh-request-list nil dir) server))
87
88 (defun nndir-request-newgroups (date &optional server)
89   (nndir-execute-nnmh-command
90    '(nnmh-request-newgroups date server) server))
91
92 (defun nndir-request-post (&optional server)
93   "Post a new news in current buffer."
94   (mail-send-and-exit nil))
95
96 (fset 'nndir-request-post-buffer 'nnmail-request-post-buffer)
97
98 (defun nndir-request-expire-articles (articles newsgroup &optional server force)
99   "Expire all articles in the ARTICLES list in group GROUP."
100   (setq nndir-status-string "nndir: expire not possible")
101   nil)
102
103 (defun nndir-close-group (group &optional server)
104   t)
105
106 (defun nndir-request-move-article (article group server accept-form)
107   (setq nndir-status-string "nndir: move not possible")
108   nil)
109
110 (defun nndir-request-accept-article (group)
111   (setq nndir-status-string "nndir: accept not possible")
112   nil)
113
114 \f
115 ;;; Low-Level Interface
116
117 (defun nndir-open-server-internal (host &optional service)
118   "Open connection to news server on HOST by SERVICE."
119   (save-excursion
120     ;; Initialize communication buffer.
121     (setq nntp-server-buffer (get-buffer-create " *nntpd*"))
122     (set-buffer nntp-server-buffer)
123     (buffer-disable-undo (current-buffer))
124     (erase-buffer)
125     (kill-all-local-variables)
126     (setq case-fold-search t)           ;Should ignore case.
127     t))
128
129 (defun nndir-close-server-internal ()
130   "Close connection to news server."
131   nil)
132
133 (defun nndir-execute-nnmh-command (command server)
134   (let ((dir (expand-file-name server)))
135     (and (string-match "/$" dir)
136          (setq dir (substring dir 0 (match-beginning 0))))
137     (string-match "/[^/]+$" dir)
138     (let ((group (substring dir (1+ (match-beginning 0))))
139           (nnmh-directory (substring dir 0 (1+ (match-beginning 0))))
140           (nnmh-get-new-mail nil))
141       (eval command))))
142
143 (defun nndir-execute-nnml-command (command server)
144   (let ((dir (expand-file-name server)))
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           (nnml-directory (substring dir 0 (1+ (match-beginning 0))))
150           (nnml-nov-is-evil nndir-nov-is-evil)
151           (nnml-get-new-mail nil))
152       (eval command))))
153
154 (provide 'nndir)
155
156 ;;; nndir.el ends here