(gnus-dribble-read-file): Quote file-precious-flag.
[gnus] / lisp / nnfolder.el
index 9d19f5c..cc1251c 100644 (file)
@@ -1,6 +1,7 @@
 ;;; nnfolder.el --- mail folder access for Gnus
-;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
-;;        Free Software Foundation, Inc.
+
+;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
+;;   2005 Free Software Foundation, Inc.
 
 ;; Author: Simon Josefsson <simon@josefsson.org> (adding MARKS)
 ;;      ShengHuo Zhu <zsh@cs.rochester.edu> (adding NOV)
@@ -23,8 +24,8 @@
 
 ;; 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.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;;; Commentary:
 
@@ -158,7 +159,7 @@ the group.  Then the marks file will be regenerated properly by Gnus.")
   (save-excursion
     (set-buffer nntp-server-buffer)
     (erase-buffer)
-    (let (article start stop)
+    (let (article start stop num)
       (nnfolder-possibly-change-group group server)
       (when nnfolder-current-buffer
        (set-buffer nnfolder-current-buffer)
@@ -173,16 +174,53 @@ the group.  Then the marks file will be regenerated properly by Gnus.")
                            (nnfolder-existing-articles)))
            (while (setq article (pop articles))
              (set-buffer nnfolder-current-buffer)
-             (when (nnfolder-goto-article article)
-               (setq start (point))
-               (setq stop (if (search-forward "\n\n" nil t)
-                              (1- (point))
-                            (point-max)))
-               (set-buffer nntp-server-buffer)
-               (insert (format "221 %d Article retrieved.\n" article))
-               (insert-buffer-substring nnfolder-current-buffer start stop)
-               (goto-char (point-max))
-               (insert ".\n")))
+             (cond ((nnfolder-goto-article article)
+                    (setq start (point))
+                    (setq stop (if (search-forward "\n\n" nil t)
+                                   (1- (point))
+                                 (point-max)))
+                    (set-buffer nntp-server-buffer)
+                    (insert (format "221 %d Article retrieved.\n" article))
+                    (insert-buffer-substring nnfolder-current-buffer
+                                             start stop)
+                    (goto-char (point-max))
+                    (insert ".\n"))
+
+                   ;; If we couldn't find this article, skip over ranges
+                   ;; of missing articles so we don't search the whole file
+                   ;; for each of them.
+                   ((numberp article)
+                    (setq start (point))
+                    (and
+                     ;; Check that we are either at BOF or after an
+                     ;; article with a lower number.  We do this so we
+                     ;; won't be confused by out-of-order article numbers,
+                     ;; as caused by active file bogosity.
+                     (cond
+                      ((bobp))
+                      ((search-backward (concat "\n" nnfolder-article-marker)
+                                        nil t)
+                       (goto-char (match-end 0))
+                       (setq num (string-to-number
+                                  (buffer-substring
+                                   (point) (point-at-eol))))
+                       (goto-char start)
+                       (< num article)))
+                     ;; Check that we are before an article with a
+                     ;; higher number.
+                     (search-forward (concat "\n" nnfolder-article-marker)
+                                     nil t)
+                     (progn
+                       (setq num (string-to-number
+                                  (buffer-substring
+                                   (point) (point-at-eol))))
+                       (> num article))
+                     ;; Discard any article numbers before the one we're
+                     ;; now looking at.
+                     (while (and articles
+                                 (< (car articles) num))
+                       (setq articles (cdr articles))))
+                    (goto-char start))))
            (set-buffer nntp-server-buffer)
            (nnheader-fold-continuation-lines)
            'headers))))))
@@ -248,9 +286,8 @@ the group.  Then the marks file will be regenerated properly by Gnus.")
            (cons nnfolder-current-group
                  (if (search-forward (concat "\n" nnfolder-article-marker)
                                      nil t)
-                     (string-to-int
-                      (buffer-substring
-                       (point) (progn (end-of-line) (point))))
+                     (string-to-number (buffer-substring
+                                     (point) (point-at-eol)))
                    -1))))))))
 
 (deffoo nnfolder-request-group (group &optional server dont-check)
@@ -334,10 +371,11 @@ the group.  Then the marks file will be regenerated properly by Gnus.")
 (deffoo nnfolder-request-create-group (group &optional server args)
   (nnfolder-possibly-change-group nil server)
   (nnmail-activate 'nnfolder)
-  (when group
-    (unless (assoc group nnfolder-group-alist)
-      (push (list group (cons 1 0)) nnfolder-group-alist)
-      (nnfolder-save-active nnfolder-group-alist nnfolder-active-file)
+  (when (and group
+            (not (assoc group nnfolder-group-alist)))
+    (push (list group (cons 1 0)) nnfolder-group-alist)
+    (nnfolder-save-active nnfolder-group-alist nnfolder-active-file)
+    (save-current-buffer
       (nnfolder-read-folder group)))
   t)
 
@@ -430,8 +468,8 @@ the group.  Then the marks file will be regenerated properly by Gnus.")
       (nnfolder-save-active nnfolder-group-alist nnfolder-active-file)
       (gnus-sorted-difference articles (nreverse deleted-articles)))))
 
-(deffoo nnfolder-request-move-article (article group server
-                                              accept-form &optional last)
+(deffoo nnfolder-request-move-article (article group server accept-form 
+                                              &optional last move-is-internal)
   (save-excursion
     (let ((buf (get-buffer-create " *nnfolder move*"))
          result)
@@ -446,8 +484,7 @@ the group.  Then the marks file will be regenerated properly by Gnus.")
                 (concat "^" nnfolder-article-marker)
                 (save-excursion (and (search-forward "\n\n" nil t) (point)))
                 t)
-          (delete-region (progn (beginning-of-line) (point))
-                         (progn (forward-line 1) (point))))
+          (gnus-delete-line))
         (setq result (eval accept-form))
         (kill-buffer buf)
         result)
@@ -473,9 +510,9 @@ the group.  Then the marks file will be regenerated properly by Gnus.")
          result art-group)
       (goto-char (point-min))
       (when (looking-at "X-From-Line: ")
-       (save-match-data
-         (mail-header-unfold-field))
-       (replace-match "From "))
+       (replace-match "From ")
+       (while (progn (forward-line) (looking-at "[ \t]"))
+         (delete-char -1)))
       (with-temp-buffer
        (let ((nnmail-file-coding-system nnfolder-active-file-coding-system)
              (nntp-server-buffer (current-buffer)))
@@ -489,7 +526,10 @@ the group.  Then the marks file will be regenerated properly by Gnus.")
        (while (re-search-backward (concat "^" nnfolder-article-marker) nil t)
          (delete-region (point) (progn (forward-line 1) (point))))
        (when nnmail-cache-accepted-message-ids
-         (nnmail-cache-insert (nnmail-fetch-field "message-id") group))
+         (nnmail-cache-insert (nnmail-fetch-field "message-id") 
+                              group
+                              (nnmail-fetch-field "subject")
+                              (nnmail-fetch-field "from")))
        (setq result (if (stringp group)
                         (list (cons group (nnfolder-active-number group)))
                       (setq art-group
@@ -834,8 +874,9 @@ deleted.  Point is left where the deleted region was."
         (buffer (set-buffer
                  (let ((nnheader-file-coding-system
                         nnfolder-file-coding-system))
-                   (nnheader-find-file-noselect file)))))
+                   (nnheader-find-file-noselect file t)))))
     (mm-enable-multibyte) ;; Use multibyte buffer for future copying.
+    (buffer-disable-undo)
     (if (equal (cadr (assoc group nnfolder-scantime-alist))
               (nth 5 (file-attributes file)))
        ;; This looks up-to-date, so we don't do any scanning.
@@ -862,7 +903,6 @@ deleted.  Point is left where the deleted region was."
              maxid start end newscantime
              novbuf articles newnum
              buffer-read-only)
-         (buffer-disable-undo)
          (setq maxid (cdr active))
 
          (unless (or gnus-nov-is-evil nnfolder-nov-is-evil
@@ -989,9 +1029,7 @@ This command does not work if you use short group names."
       (when (not (message-mail-file-mbox-p file))
        (ignore-errors
          (delete-file file)))))
-  (let ((files (directory-files nnfolder-directory))
-       file)
-    (while (setq file (pop files))
+    (dolist (file (directory-files nnfolder-directory))
       (when (and (not (backup-file-name-p file))
                 (message-mail-file-mbox-p
                  (nnheader-concat nnfolder-directory file)))
@@ -1006,10 +1044,10 @@ This command does not work if you use short group names."
          (nnfolder-possibly-change-folder file)
          (nnfolder-possibly-change-group file)
          (nnfolder-close-group file))))
-    (nnheader-message 5 "")))
+    (nnheader-message 5 ""))
 
 (defun nnfolder-group-pathname (group)
-  "Make pathname for GROUP."
+  "Make file name for GROUP."
   (setq group
        (mm-encode-coding-string group nnmail-pathname-coding-system))
   (let ((dir (file-name-as-directory (expand-file-name nnfolder-directory))))
@@ -1033,7 +1071,8 @@ This command does not work if you use short group names."
     (gnus-make-directory (file-name-directory (buffer-file-name)))
     (let ((coding-system-for-write
           (or nnfolder-file-coding-system-for-write
-              nnfolder-file-coding-system)))
+              nnfolder-file-coding-system))
+         (copyright-update nil))
       (save-buffer)))
   (unless (or gnus-nov-is-evil nnfolder-nov-is-evil)
     (nnfolder-save-nov)))
@@ -1113,13 +1152,7 @@ This command does not work if you use short group names."
        (if (search-forward "\n\n" e t) (setq e (1- (point)))))
       (with-temp-buffer
        (insert-buffer-substring buf b e)
-       ;; Fold continuation lines.
-       (goto-char (point-min))
-       (while (re-search-forward "\\(\r?\n[ \t]+\\)+" nil t)
-         (replace-match " " t t))
-       ;; Remove any tabs; they are too confusing.
-       (subst-char-in-region (point-min) (point-max) ?\t ? )
-       (let ((headers (nnheader-parse-head t)))
+       (let ((headers (nnheader-parse-naked-head)))
          (mail-header-set-chars headers chars)
          (mail-header-set-number headers number)
          headers)))))
@@ -1142,7 +1175,7 @@ This command does not work if you use short group names."
       (let ((range (nth 0 action))
            (what  (nth 1 action))
            (marks (nth 2 action)))
-       (assert (or (eq what 'add) (eq what 'del)) t
+       (assert (or (eq what 'add) (eq what 'del)) nil
                "Unknown request-set-mark action: %s" what)
        (dolist (mark marks)
          (setq nnfolder-marks (gnus-update-alist-soft
@@ -1163,16 +1196,16 @@ This command does not work if you use short group names."
     (nnheader-message 8 "Updating marks for %s..." group)
     (nnfolder-open-marks group server)
     ;; Update info using `nnfolder-marks'.
-    (mapcar (lambda (pred)
-             (unless (memq (cdr pred) gnus-article-unpropagated-mark-lists)
-               (gnus-info-set-marks
-                info
-                (gnus-update-alist-soft
-                 (cdr pred)
-                 (cdr (assq (cdr pred) nnfolder-marks))
-                 (gnus-info-marks info))
-                t)))
-           gnus-article-mark-lists)
+    (mapc (lambda (pred)
+           (unless (memq (cdr pred) gnus-article-unpropagated-mark-lists)
+             (gnus-info-set-marks
+              info
+              (gnus-update-alist-soft
+               (cdr pred)
+               (cdr (assq (cdr pred) nnfolder-marks))
+               (gnus-info-marks info))
+              t)))
+         gnus-article-mark-lists)
     (let ((seen (cdr (assq 'read nnfolder-marks))))
       (gnus-info-set-read info
                          (if (and (integerp (car seen))
@@ -1208,7 +1241,7 @@ This command does not work if you use short group names."
                        nnfolder-marks-modtime))
       (error (or (gnus-yes-or-no-p
                  (format "Could not write to %s (%s).  Continue? " file err))
-                (error "Cannot write to %s (%s)" err))))))
+                (error "Cannot write to %s (%s)" file err))))))
 
 (defun nnfolder-open-marks (group server)
   (let ((file (nnfolder-group-marks-pathname group)))
@@ -1240,4 +1273,5 @@ This command does not work if you use short group names."
 
 (provide 'nnfolder)
 
+;;; arch-tag: a040d0f4-4f4e-445f-8972-839575c5f7e6
 ;;; nnfolder.el ends here