*** empty log message ***
[gnus] / lisp / nnbabyl.el
index 41d6684..2df3070 100644 (file)
@@ -57,6 +57,8 @@
 (defvar nnbabyl-group-alist nil)
 (defvar nnbabyl-active-timestamp nil)
 
+(defvar nnbabyl-previous-buffer-mode nil)
+
 \f
 
 (defvar nnbabyl-current-server nil)
    (list 'nnbabyl-get-new-mail nnbabyl-get-new-mail)
    '(nnbabyl-current-group nil)
    '(nnbabyl-status-string "")
+   '(nnbabyl-previous-buffer-mode nil)
    '(nnbabyl-group-alist nil)))
 
 \f
 
 ;;; Interface functions
 
-(defun nnbabyl-retrieve-headers (sequence &optional newsgroup server)
+(defun nnbabyl-retrieve-headers (sequence &optional newsgroup server fetch-old)
   (save-excursion
     (set-buffer nntp-server-buffer)
     (erase-buffer)
     (setq nnbabyl-current-server server)))
 
 (defun nnbabyl-close-server (&optional server)
+  ;; Restore buffer mode.
+  (when (and (nnbabyl-server-opened)
+            nnbabyl-previous-buffer-mode)
+    (save-excursion
+      (set-buffer nnbabyl-mbox-buffer)
+      (narrow-to-region
+       (car (car nnbabyl-previous-buffer-mode))
+       (cdr (car nnbabyl-previous-buffer-mode)))
+      (funcall (cdr nnbabyl-previous-buffer-mode))))
+  (setq nnbabyl-current-server nil
+       nnbabyl-mbox-buffer nil)
   t)
 
 (defun nnbabyl-server-opened (&optional server)
     (set-buffer nnbabyl-mbox-buffer)
     (goto-char (point-min))
     (if (search-forward (nnbabyl-article-string article) nil t)
-       (let (start stop)
+       (let (start stop summary-line)
          (re-search-backward (concat "^" nnbabyl-mail-delimiter) nil t)
          (while (and (not (looking-at ".+:"))
                      (zerop (forward-line 1))))
            (erase-buffer)
            (insert-buffer-substring nnbabyl-mbox-buffer start stop)
            (goto-char (point-min))
-           (if (search-forward "\n*** EOOH ***" nil t)
-               (progn
-                 (delete-region (progn (beginning-of-line) (point))
-                                (or (search-forward "\n\n" nil t)
-                                    (point)))))
+           ;; If there is an EOOH header, then we have to remove some
+           ;; duplicated headers. 
+           (setq summary-line (looking-at "Summary-line:"))
+           (when (search-forward "\n*** EOOH ***" nil t)
+             (if summary-line
+                 ;; The headers to be deleted are located before the
+                 ;; EOOH line...
+                 (delete-region (point-min) (progn (forward-line 1)
+                 (point)))
+               ;; ...or after.
+               (delete-region (progn (beginning-of-line) (point))
+                              (or (search-forward "\n\n" nil t)
+                                  (point)))))
            (if (numberp article) 
                (cons nnbabyl-current-group article)
              (nnbabyl-article-group-number)))))))
        (goto-char (point-max))
        (search-backward "\n\^_")
        (goto-char (match-end 0))
-       (insert-buffer buf)
+       (insert-buffer-substring buf)
        (and last (progn 
                   (save-buffer)
                   (nnmail-save-active
       (save-buffer)
       t)))
 
+(defun nnbabyl-request-delete-group (group &optional force server)
+  (nnbabyl-possibly-change-newsgroup group)
+  ;; Delete all articles in GROUP.
+  (if (not force)
+      ()                               ; Don't delete the articles.
+    (save-excursion
+      (set-buffer nnbabyl-mbox-buffer)
+      (goto-char (point-min))
+      ;; Delete all articles in this group.
+      (let ((ident (concat "\nX-Gnus-Newsgroup: " nnbabyl-current-group ":"))
+           found)
+       (while (search-forward ident nil t)
+         (setq found t)
+         (nnbabyl-delete-mail))
+       (and found (save-buffer)))))
+  ;; Remove the group from all structures.
+  (setq nnbabyl-group-alist 
+       (delq (assoc group nnbabyl-group-alist) nnbabyl-group-alist)
+       nnbabyl-current-group nil)
+  ;; Save the active file.
+  (nnmail-save-active nnbabyl-group-alist nnbabyl-active-file)
+  t)
+
+(defun nnbabyl-request-rename-group (group new-name &optional server)
+  (nnbabyl-possibly-change-newsgroup group)
+  (save-excursion
+    (set-buffer nnbabyl-mbox-buffer)
+    (goto-char (point-min))
+    (let ((ident (concat "\nX-Gnus-Newsgroup: " nnbabyl-current-group ":"))
+         (new-ident (concat "\nX-Gnus-Newsgroup: " new-name ":"))
+         found)
+      (while (search-forward ident nil t)
+       (replace-match new-ident t t)
+       (setq found t))
+      (and found (save-buffer))))
+  (let ((entry (assoc group nnbabyl-group-alist)))
+    (and entry (setcar entry new-name))
+    (setq nnbabyl-current-group nil)
+    ;; Save the new group alist.
+    (nnmail-save-active nnbabyl-group-alist nnbabyl-active-file)
+    t))
+
 \f
-;;; Low-Level Interface
+;;; Internal functions.
 
 ;; If FORCE, delete article no matter how many X-Gnus-Newsgroup
 ;; headers there are. If LEAVE-DELIM, don't delete the Unix mbox
        (set-buffer (setq nnbabyl-mbox-buffer 
                          (nnheader-find-file-noselect 
                           nnbabyl-mbox-file nil 'raw)))
+       ;; Save buffer mode.
+       (setq nnbabyl-previous-buffer-mode 
+             (cons (cons (point-min) (point-max))
+                   major-mode))
+
        (buffer-disable-undo (current-buffer))
        (widen)
        (setq buffer-read-only nil)