(spam-mark-junk-as-spam-routine)
[gnus] / lisp / nnbabyl.el
index c8ac0a8..1281ad9 100644 (file)
@@ -1,8 +1,10 @@
 ;;; nnbabyl.el --- rmail mbox access for Gnus
 ;;; nnbabyl.el --- rmail mbox 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, 1996, 1997, 1998, 1099, 2000, 2001
+;;     Free Software Foundation, Inc.
+
+;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
+;;     Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
 ;; Keywords: news, mail
 
 ;; This file is part of GNU Emacs.
 ;; Keywords: news, mail
 
 ;; This file is part of GNU Emacs.
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
 ;; 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; see the file COPYING.  If not, write to the
+;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
 
 ;;; Commentary:
 
 ;; For an overview of what the interface functions do, please see the
 
 ;;; Commentary:
 
 ;; For an overview of what the interface functions do, please see the
-;; Gnus sources.  
+;; Gnus sources.
 
 ;;; Code:
 
 (require 'nnheader)
 
 ;;; Code:
 
 (require 'nnheader)
-(require 'rmail)
+(condition-case nil
+    (require 'rmail)
+  (t (nnheader-message
+      5 "Ignore rmail errors from this file, you don't have rmail")))
 (require 'nnmail)
 (require 'nnmail)
+(require 'nnoo)
+(eval-when-compile (require 'cl))
+
+(nnoo-declare nnbabyl)
 
 
-(defvar nnbabyl-mbox-file (expand-file-name "~/RMAIL")
+(defvoo nnbabyl-mbox-file (expand-file-name "~/RMAIL")
   "The name of the rmail box file in the users home directory.")
 
   "The name of the rmail box file in the users home directory.")
 
-(defvar nnbabyl-active-file (expand-file-name "~/.rmail-active")
+(defvoo nnbabyl-active-file (expand-file-name "~/.rmail-active")
   "The name of the active file for the rmail box.")
 
   "The name of the active file for the rmail box.")
 
-(defvar nnbabyl-get-new-mail t
+(defvoo nnbabyl-get-new-mail t
   "If non-nil, nnbabyl will check the incoming mail file and split the mail.")
 
   "If non-nil, nnbabyl will check the incoming mail file and split the mail.")
 
-(defvar nnbabyl-prepare-save-mail-hook nil
+
+(defvoo nnbabyl-prepare-save-mail-hook nil
   "Hook run narrowed to an article before saving.")
 
 \f
 
 (defvar nnbabyl-mail-delimiter "\^_")
 
   "Hook run narrowed to an article before saving.")
 
 \f
 
 (defvar nnbabyl-mail-delimiter "\^_")
 
-(defconst nnbabyl-version "nnbabyl 0.1"
+(defconst nnbabyl-version "nnbabyl 1.0"
   "nnbabyl version.")
 
   "nnbabyl version.")
 
-(defvar nnbabyl-mbox-buffer nil)
-(defvar nnbabyl-current-group nil)
-(defvar nnbabyl-status-string "")
-(defvar nnbabyl-group-alist nil)
-
-\f
+(defvoo nnbabyl-mbox-buffer nil)
+(defvoo nnbabyl-current-group nil)
+(defvoo nnbabyl-status-string "")
+(defvoo nnbabyl-group-alist nil)
+(defvoo nnbabyl-active-timestamp nil)
 
 
-(defvar nnbabyl-current-server nil)
-(defvar nnbabyl-server-alist nil)
-(defvar nnbabyl-server-variables 
-  (list
-   (list 'nnbabyl-mbox-file nnbabyl-mbox-file)
-   (list 'nnbabyl-active-file nnbabyl-active-file)
-   (list 'nnbabyl-get-new-mail nnbabyl-get-new-mail)
-   '(nnbabyl-current-group nil)
-   '(nnbabyl-status-string "")
-   '(nnbabyl-group-alist nil)))
+(defvoo nnbabyl-previous-buffer-mode nil)
 
 \f
 
 ;;; Interface functions
 
 
 \f
 
 ;;; Interface functions
 
-(defun nnbabyl-retrieve-headers (sequence &optional newsgroup server)
+(nnoo-define-basics nnbabyl)
+
+(deffoo nnbabyl-retrieve-headers (articles &optional group server fetch-old)
   (save-excursion
     (set-buffer nntp-server-buffer)
     (erase-buffer)
   (save-excursion
     (set-buffer nntp-server-buffer)
     (erase-buffer)
-    (let ((file nil)
-         (number (length sequence))
+    (let ((number (length articles))
          (count 0)
          (count 0)
+         (delim (concat "^" nnbabyl-mail-delimiter))
          article art-string start stop)
          article art-string start stop)
-      (nnbabyl-possibly-change-newsgroup newsgroup)
-      (if (stringp (car sequence))
-         'headers
-       (while sequence
-         (setq article (car sequence))
-         (setq art-string (nnbabyl-article-string article))
-         (set-buffer nnbabyl-mbox-buffer)
-         (if (or (search-forward art-string nil t)
+      (nnbabyl-possibly-change-newsgroup group server)
+      (while (setq article (pop articles))
+       (setq art-string (nnbabyl-article-string article))
+       (set-buffer nnbabyl-mbox-buffer)
+       (end-of-line)
+       (when (or (search-forward art-string nil t)
                  (search-backward art-string nil t))
                  (search-backward art-string nil t))
-             (progn
-               (re-search-backward (concat "^" nnbabyl-mail-delimiter) nil t)
-               (while (and (not (looking-at ".+:"))
-                           (zerop (forward-line 1))))
-               (setq start (point))
-               (search-forward "\n\n" nil t)
-               (setq stop (1- (point)))
-               (set-buffer nntp-server-buffer)
-               (insert "221 " (int-to-string article) " Article retrieved.\n")
-               (insert-buffer-substring nnbabyl-mbox-buffer start stop)
-               (goto-char (point-max))
-               (insert ".\n")))
-         (setq sequence (cdr sequence))
-         (setq count (1+ count))
-         (and (numberp nnmail-large-newsgroup)
-              (> number nnmail-large-newsgroup)
-              (zerop (% count 20))
-              gnus-verbose-backends
-              (message "nnbabyl: Receiving headers... %d%%"
-                       (/ (* count 100) number))))
-
+         (unless (re-search-backward delim nil t)
+           (goto-char (point-min)))
+         (while (and (not (looking-at ".+:"))
+                     (zerop (forward-line 1))))
+         (setq start (point))
+         (search-forward "\n\n" nil t)
+         (setq stop (1- (point)))
+         (set-buffer nntp-server-buffer)
+         (insert "221 ")
+         (princ article (current-buffer))
+         (insert " Article retrieved.\n")
+         (insert-buffer-substring nnbabyl-mbox-buffer start stop)
+         (goto-char (point-max))
+         (insert ".\n"))
        (and (numberp nnmail-large-newsgroup)
             (> number nnmail-large-newsgroup)
        (and (numberp nnmail-large-newsgroup)
             (> number nnmail-large-newsgroup)
-            gnus-verbose-backends
-            (message "nnbabyl: Receiving headers...done"))
-
-       ;; Fold continuation lines.
-       (goto-char (point-min))
-       (while (re-search-forward "\\(\r?\n[ \t]+\\)+" nil t)
-         (replace-match " " t t))
-       'headers))))
-
-(defun nnbabyl-open-server (server &optional defs)
-  (nnheader-init-server-buffer)
-  (if (equal server nnbabyl-current-server)
-      t
-    (if nnbabyl-current-server
-       (setq nnbabyl-server-alist 
-             (cons (list nnbabyl-current-server
-                         (nnheader-save-variables nnbabyl-server-variables))
-                   nnbabyl-server-alist)))
-    (let ((state (assoc server nnbabyl-server-alist)))
-      (if state 
-         (progn
-           (nnheader-restore-variables (nth 1 state))
-           (setq nnbabyl-server-alist (delq state nnbabyl-server-alist)))
-       (nnheader-set-init-variables nnbabyl-server-variables defs)))
-    (setq nnbabyl-current-server server)))
-
-(defun nnbabyl-close-server (&optional server)
+            (zerop (% (incf count) 20))
+            (nnheader-message 5 "nnbabyl: Receiving headers... %d%%"
+                              (/ (* count 100) number))))
+
+      (and (numberp nnmail-large-newsgroup)
+          (> number nnmail-large-newsgroup)
+          (nnheader-message 5 "nnbabyl: Receiving headers...done"))
+
+      (set-buffer nntp-server-buffer)
+      (nnheader-fold-continuation-lines)
+      'headers)))
+
+(deffoo nnbabyl-open-server (server &optional defs)
+  (nnoo-change-server 'nnbabyl server defs)
+  (nnbabyl-create-mbox)
+  (cond
+   ((not (file-exists-p nnbabyl-mbox-file))
+    (nnbabyl-close-server)
+    (nnheader-report 'nnbabyl "No such file: %s" nnbabyl-mbox-file))
+   ((file-directory-p nnbabyl-mbox-file)
+    (nnbabyl-close-server)
+    (nnheader-report 'nnbabyl "Not a regular file: %s" nnbabyl-mbox-file))
+   (t
+    (nnheader-report 'nnbabyl "Opened server %s using mbox %s" server
+                    nnbabyl-mbox-file)