* gnus-sum.el (gnus-summary-search-article):
[gnus] / lisp / nndir.el
index 6ae862b..469e026 100644 (file)
@@ -1,16 +1,16 @@
 ;;; nndir.el --- single directory newsgroup access for Gnus
-;; Copyright (C) 1995 Free Software Foundation, Inc.
 
-;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
-;;     Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
+;; Copyright (C) 1995-2015 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
@@ -18,8 +18,7 @@
 ;; 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, 675 Mass Ave, Cambridge, MA 02139, 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))
 
-(eval-and-compile
-  (autoload 'mail-send-and-exit "sendmail"))
-
-(defvar nndir-directory nil)
-
-\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-nov-is-evil nil
-  "*Non-nil means that nndir will never retrieve NOV headers.")
+(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 
-  (list
-   '(nndir-directory nil)
-   '(nndir-status-string "")
-   '(nndir-group-alist)))
+(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.
 
-
-(defun nndir-retrieve-headers (sequence &optional group server fetch-old)
-  (nndir-execute-nnml-command
-   (` (nnml-retrieve-headers 
-       (quote (, sequence)) group (, server) (, fetch-old)))))
-
-(defun nndir-open-server (server &optional defs)
-  (nnheader-init-server-buffer)
-  (if (equal server nndir-current-server)
-      t
-    (if nndir-current-server
-       (setq nndir-server-alist 
-             (cons (list nndir-current-server
-                         (nnheader-save-variables nndir-server-variables))
-                   nndir-server-alist)))
-    (let ((state (assoc server nndir-server-alist)))
-      (if state 
-         (progn
-           (nnheader-restore-variables (nth 1 state))
-           (setq nndir-server-alist (delq state nndir-server-alist)))
-       (nnheader-set-init-variables nndir-server-variables defs))
-      (or (assq 'nndir-directory defs)
-         (setq nndir-directory server)))
-    (setq nndir-current-server server)))
-
-(defun nndir-close-server (&optional server)
-  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 group server buffer)
-  (nndir-execute-nnmh-command
-   (` (nnmh-request-article (, id) group (, server) (, buffer)))))
-
-(defun nndir-request-group (group &optional server dont-check)
-  (nndir-execute-nnmh-command
-   (` (nnmh-request-group group "" (, dont-check)))))
-
-(defun nndir-request-list (&optional server dir)
-  (nndir-execute-nnmh-command
-   (` (nnmh-request-list nil (, dir)))))
-
-(defun nndir-request-newgroups (date &optional server)
-  (nndir-execute-nnmh-command
-   (` (nnmh-request-newgroups (, date) (, server)))))
-
-(defun nndir-request-post (&optional server)
-  (mail-send-and-exit nil))
-
-(defun nndir-request-expire-articles 
-  (articles group &optional server force)
-  (nndir-execute-nnmh-command
-   (` (nnmh-request-expire-articles (, articles) group
-                                   (, server) (, force)))))
-
-(defun nndir-request-accept-article (group &optional last)
-  (nndir-execute-nnmh-command
-   (` (nnmh-request-accept-article group (, last)))))
-
-(defun nndir-close-group (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 (expand-file-name nndir-directory)))
-    (and (string-match "/$" dir)
-        (setq dir (substring dir 0 (match-beginning 0))))
-    (string-match "/[^/]+$" dir)
-    (let ((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 (expand-file-name nndir-directory)))
-    (and (string-match "/$" dir)
-        (setq dir (substring dir 0 (match-beginning 0))))
-    (string-match "/[^/]+$" dir)
-    (let ((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-define-basics nndir)
+
+(deffoo nndir-open-server (server &optional defs)
+  (setq nndir-directory
+       (or (cadr (assq 'nndir-directory defs))
+           server))
+  (unless (assq 'nndir-directory defs)
+    (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
+     ((not (condition-case arg
+              (file-exists-p nndir-directory)
+            (ftp-error (setq err (format "%s" arg)))))
+      (nndir-close-server)
+      (nnheader-report
+       'nndir (or err "No such file or directory: %s" nndir-directory)))
+     ((not (file-directory-p (file-truename nndir-directory)))
+      (nndir-close-server)
+      (nnheader-report 'nndir "Not a directory: %s" nndir-directory))
+     (t
+      (nnheader-report 'nndir "Opened server %s using directory %s"
+                      server nndir-directory)
+      t))))
+
+(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)))
 
 (provide 'nndir)