;;; nndir.el --- single directory newsgroup access for Gnus
-;; Copyright (C) 1995,96 Free Software Foundation, Inc.
-;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
-;; Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
+;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
+;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+
+;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
;; Keywords: news
;; This file is part of GNU Emacs.
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING. If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
(require 'nnheader)
(require 'nnmh)
(require 'nnml)
+(require 'nnoo)
(eval-when-compile (require 'cl))
-(defvar nndir-directory nil
- "Where nndir will look for groups.")
-
-(defvar nndir-nov-is-evil nil
- "*Non-nil means that nndir will never retrieve NOV headers.")
-
-\f
-
-(defconst nndir-version "nndir 1.0")
+(nnoo-declare nndir
+ nnml nnmh)
-(defvar nndir-status-string "")
+(defvoo nndir-directory nil
+ "Where nndir will look for groups."
+ nnml-current-directory nnmh-current-directory)
-(defvar nndir-group "blououUOUOuuubhbh")
+(defvoo nndir-nov-is-evil nil
+ "*Non-nil means that nndir will never retrieve NOV headers."
+ nnml-nov-is-evil)
\f
-(defvar nndir-current-server nil)
-(defvar nndir-server-alist nil)
-(defvar nndir-server-variables
- `((nndir-directory nil)
- (nndir-status-string "")
- (nndir-nov-is-evil ,nndir-nov-is-evil)
- (nndir-group-alist nil)))
+(defvoo nndir-current-group "" nil nnml-current-group nnmh-current-group)
+(defvoo nndir-top-directory nil nil nnml-directory nnmh-directory)
+(defvoo nndir-get-new-mail nil nil nnml-get-new-mail nnmh-get-new-mail)
+
+(defvoo nndir-status-string "" nil nnmh-status-string)
+(defconst nndir-version "nndir 1.0")
\f
;;; Interface functions.
+(nnoo-define-basics nndir)
-(defun nndir-retrieve-headers (sequence &optional
- nndir-group server fetch-old)
- (nndir-execute-nnml-command
- `(nnml-retrieve-headers ',sequence nndir-group ,server ,fetch-old)))
-
-(defun nndir-open-server (server &optional defs)
- (nnheader-change-server 'nndir server defs)
+(deffoo nndir-open-server (server &optional defs)
+ (setq nndir-directory
+ (or (cadr (assq 'nndir-directory defs))
+ server))
(unless (assq 'nndir-directory defs)
- (setq nndir-directory server))
+ (push `(nndir-directory ,server) defs))
+ (push `(nndir-current-group
+ ,(file-name-nondirectory (directory-file-name nndir-directory)))
+ defs)
+ (push `(nndir-top-directory
+ ,(file-name-directory (directory-file-name nndir-directory)))
+ defs)
+ (nnoo-change-server 'nndir server defs)
(let (err)
- (cond
+ (cond
((not (condition-case arg
(file-exists-p nndir-directory)
(ftp-error (setq err (format "%s" arg)))))
(nndir-close-server)
- (nnheader-report
+ (nnheader-report
'nndir (or err "No such file or directory: %s" nndir-directory)))
((not (file-directory-p (file-truename nndir-directory)))
(nndir-close-server)
server nndir-directory)
t))))
-(defun nndir-close-server (&optional server)
- (setq nndir-current-server nil)
- t)
-
-(defun nndir-server-opened (&optional server)
- (and nntp-server-buffer
- (get-buffer nntp-server-buffer)
- nndir-current-server
- (equal nndir-current-server server)))
-
-(defun nndir-status-message (&optional server)
- nndir-status-string)
-
-(defun nndir-request-article (id &optional nndir-group server buffer)
- (nndir-execute-nnmh-command
- `(nnmh-request-article ,id nndir-group ,server ,buffer)))
-
-(defun nndir-request-group (nndir-group &optional server dont-check)
- (nndir-execute-nnmh-command
- `(nnmh-request-group nndir-group "" ,dont-check)))
-
-(defun nndir-request-list (&optional server dir)
- (let ((nndir-directory (concat (file-name-as-directory
- nndir-directory) "dummy")))
- (nndir-execute-nnmh-command
- `(nnmh-request-list ,(concat "nndir+" (or server "")) ,dir))))
-
-(defun nndir-request-newgroups (date &optional server)
- (nndir-execute-nnmh-command
- `(nnmh-request-newgroups ,date ,server)))
-
-(defun nndir-request-expire-articles
- (articles nndir-group &optional server force)
- (nndir-execute-nnmh-command
- `(nnmh-request-expire-articles ',articles nndir-group ,server ,force)))
-
-(defun nndir-request-accept-article (nndir-group &optional last)
- (nndir-execute-nnmh-command
- `(nnmh-request-accept-article nndir-group ,last)))
-
-(defun nndir-close-group (nndir-group &optional server)
- t)
-
-(defun nndir-request-create-group (group &optional server)
- (if (file-exists-p nndir-directory)
- (if (file-directory-p nndir-directory)
- t
- nil)
- (condition-case ()
- (progn
- (make-directory nndir-directory t)
- t)
- (file-error nil))))
-
-\f
-;;; Low-Level Interface
-
-(defun nndir-execute-nnmh-command (command)
- (let ((dir (file-name-as-directory (expand-file-name nndir-directory))))
- (if (and (not (file-directory-p nndir-group))
- (or (file-directory-p (concat dir nndir-group))
- (file-directory-p
- (concat dir (nnheader-replace-chars-in-string
- nndir-group ?. ?/)))))
- (let ((nnmh-directory nndir-directory)
- (nnmh-get-new-mail nil))
- (eval command))
- (let ((dir (directory-file-name (expand-file-name nndir-directory))))
- (string-match "/[^/]+$" dir)
- (let ((nndir-group (substring dir (1+ (match-beginning 0))))
- (nnmh-directory (substring dir 0 (1+ (match-beginning 0))))
- (nnmh-get-new-mail nil))
- (eval command))))))
-
-(defun nndir-execute-nnml-command (command)
- (let ((dir (file-name-as-directory (expand-file-name nndir-directory))))
- (if (and (not (file-directory-p nndir-group))
- (or (file-directory-p (concat dir nndir-group))
- (file-directory-p
- (concat dir (nnheader-replace-chars-in-string
- nndir-group ?. ?/)))))
- (let ((nnml-directory nndir-directory)
- (nnml-nov-is-evil nndir-nov-is-evil)
- (nnml-get-new-mail nil))
- (eval command))
- (let ((dir (directory-file-name (expand-file-name nndir-directory))))
- (string-match "/[^/]+$" dir)
- (let ((nndir-group (substring dir (1+ (match-beginning 0))))
- (nnml-directory (substring dir 0 (1+ (match-beginning 0))))
- (nnml-nov-is-evil nndir-nov-is-evil)
- (nnml-get-new-mail nil))
- (eval command))))))
+(nnoo-map-functions nndir
+ (nnml-retrieve-headers 0 nndir-current-group 0 0)
+ (nnml-request-article 0 nndir-current-group 0 0)
+ (nnmh-request-group nndir-current-group 0 0)
+ (nnml-close-group nndir-current-group 0)
+ (nnml-request-list (nnoo-current-server 'nndir) nndir-directory)
+ (nnml-request-newsgroups (nnoo-current-server 'nndir) nndir-directory))
(provide 'nndir)