Sync up with Gnus 5.6.30.
[elisp/gnus.git-] / lisp / gnus-cache.el
index ea61f5d..ff070f8 100644 (file)
@@ -1,7 +1,7 @@
 ;;; gnus-cache.el --- cache interface for Gnus
 ;; Copyright (C) 1995,96,97,98 Free Software Foundation, Inc.
 
-;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
+;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
 ;; Keywords: news
 
 ;; This file is part of GNU Emacs.
 (eval-when-compile
   (require 'gnus-sum))
 
-(defgroup gnus-cache nil
-  "Cache interface."
-  :group 'gnus)
-
-(defcustom gnus-cache-directory
-  (nnheader-concat gnus-directory "cache/")
-  "*The directory where cached articles will be stored."
-  :group 'gnus-cache
-  :type 'directory)
-
 (defcustom gnus-cache-active-file
   (concat (file-name-as-directory gnus-cache-directory) "active")
   "*The cache active file."
   :type 'file)
 
 (defcustom gnus-cache-enter-articles '(ticked dormant)
-  "*Classes of articles to enter into the cache."
+  "Classes of articles to enter into the cache."
   :group 'gnus-cache
   :type '(set (const ticked) (const dormant) (const unread) (const read)))
 
 (defcustom gnus-cache-remove-articles '(read)
-  "*Classes of articles to remove from the cache."
+  "Classes of articles to remove from the cache."
   :group 'gnus-cache
   :type '(set (const ticked) (const dormant) (const unread) (const read)))
 
@@ -191,8 +181,12 @@ variable to \"^nnml\"."
              ;; [number subject from date id references chars lines xref]
              (insert (format "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t\n"
                              (mail-header-number headers)
-                             (mail-header-subject headers)
-                             (mail-header-from headers)
+                             (let ((subject (mail-header-subject headers)))
+                               (or (get-text-property 0 'raw-text subject)
+                                   subject))
+                             (let ((from (mail-header-from headers)))
+                               (or (get-text-property 0 'raw-text from)
+                                   from))
                              (mail-header-date headers)
                              (mail-header-id headers)
                              (or (mail-header-references headers) "")
@@ -252,7 +246,7 @@ variable to \"^nnml\"."
     (when (file-exists-p file)
       (erase-buffer)
       (gnus-kill-all-overlays)
-      (insert-file-contents file)
+      (nnheader-insert-file-contents file)
       t)))
 
 (defun gnus-cache-possibly-alter-active (group active)
@@ -298,7 +292,7 @@ variable to \"^nnml\"."
            ;; unsuccessful), so we use the cached headers exclusively.
            (set-buffer nntp-server-buffer)
            (erase-buffer)
-           (insert-file-contents cache-file)
+           (nnheader-insert-file-contents cache-file)
            'nov)
           ((eq type 'nov)
            ;; We have both cached and uncached NOV headers, so we
@@ -319,6 +313,7 @@ Returns the list of articles entered."
   (let ((articles (gnus-summary-work-articles n))
        article out)
     (while (setq article (pop articles))
+      (gnus-summary-remove-process-mark article)
       (if (natnump article)
          (when (gnus-cache-possibly-enter-article
                 gnus-newsgroup-name article
@@ -326,7 +321,6 @@ Returns the list of articles entered."
                 nil nil nil t)
            (push article out))
        (gnus-message 2 "Can't cache article %d" article))
-      (gnus-summary-remove-process-mark article)
       (gnus-summary-update-secondary-mark article))
     (gnus-summary-next-subject 1)
     (gnus-summary-position-point)
@@ -342,9 +336,9 @@ Returns the list of articles removed."
        article out)
     (while articles
       (setq article (pop articles))
+      (gnus-summary-remove-process-mark article)
       (when (gnus-cache-possibly-remove-article article nil nil nil t)
        (push article out))
-      (gnus-summary-remove-process-mark article)
       (gnus-summary-update-secondary-mark article))
     (gnus-summary-next-subject 1)
     (gnus-summary-position-point)
@@ -357,7 +351,7 @@ Returns the list of articles removed."
 (defun gnus-summary-insert-cached-articles ()
   "Insert all the articles cached for this group into the current buffer."
   (interactive)
-  (let ((cached gnus-newsgroup-cached)
+  (let ((cached (sort (copy-sequence gnus-newsgroup-cached) '<))
        (gnus-verbose (max 6 gnus-verbose)))
     (unless cached
       (gnus-message 3 "No cached articles for this group"))
@@ -409,12 +403,14 @@ Returns the list of articles removed."
                ;; Translate the first colon into a slash.
                (when (string-match ":" group)
                  (aset group (match-beginning 0) ?/))
-               (nnheader-replace-chars-in-string group ?. ?/)))))
+               (nnheader-replace-chars-in-string group ?. ?/)))
+           t))
          (if (stringp article) article (int-to-string article))))
 
 (defun gnus-cache-update-article (group article)
   "If ARTICLE is in the cache, remove it and re-enter it."
-  (when (gnus-cache-possibly-remove-article article nil nil nil t)
+  (gnus-cache-change-buffer group)
+  (when (gnus-cache-possibly-remove-article article nil nil nil t)    
     (let ((gnus-use-cache nil))
       (gnus-cache-possibly-enter-article
        gnus-newsgroup-name article (gnus-summary-article-header article)
@@ -474,7 +470,7 @@ Returns the list of articles removed."
       (set-buffer cache-buf)
       (buffer-disable-undo (current-buffer))
       (erase-buffer)
-      (insert-file-contents (or file (gnus-cache-file-name group ".overview")))
+      (nnheader-insert-file-contents (or file (gnus-cache-file-name group ".overview")))
       (goto-char (point-min))
       (insert "\n")
       (goto-char (point-min)))
@@ -517,7 +513,7 @@ Returns the list of articles removed."
       (save-excursion
        (set-buffer cache-buf)
        (erase-buffer)
-       (insert-file-contents (gnus-cache-file-name group (car cached)))
+       (nnheader-insert-file-contents (gnus-cache-file-name group (car cached)))
        (goto-char (point-min))
        (insert "220 ")
        (princ (car cached) (current-buffer))
@@ -568,7 +564,7 @@ $ emacs -batch -l ~/.emacs -l gnus -f gnus-jog-cache"
     ;; We simply read the active file.
     (save-excursion
       (gnus-set-work-buffer)
-      (insert-file-contents gnus-cache-active-file)
+      (nnheader-insert-file-contents gnus-cache-active-file)
       (gnus-active-to-gnus-format
        nil (setq gnus-cache-active-hashtb
                 (gnus-make-hashtable
@@ -616,8 +612,9 @@ If LOW, update the lower bound instead."
          (if top
              ""
            (string-match
-            (concat "^" (file-name-as-directory
-                         (expand-file-name gnus-cache-directory)))
+            (concat "^" (regexp-quote
+                         (file-name-as-directory
+                          (expand-file-name gnus-cache-directory))))
             (directory-file-name directory))
            (nnheader-replace-chars-in-string
             (substring (directory-file-name directory) (match-end 0))