Synch to No Gnus 200504250650.
[elisp/gnus.git-] / lisp / gnus-art.el
index f155e5f..14d0144 100644 (file)
@@ -3015,10 +3015,14 @@ how much time has lapsed since DATE.  For `lapsed', the value of
 should replace the \"Date:\" one, or should be added below it."
   (interactive (list 'ut t))
   (let* ((tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
-        (date-regexp (if (and gnus-article-date-lapsed-new-header
-                              (eq type 'lapsed))
-                         "^X-Sent:[ \t]"
-                       tdate-regexp))
+        (date-regexp (cond ((not gnus-article-date-lapsed-new-header)
+                            tdate-regexp)
+                           ((eq type 'lapsed)
+                            "^X-Sent:[ \t]")
+                           (article-lapsed-timer
+                            "^Date:[ \t]")
+                           (t
+                            tdate-regexp)))
         (case-fold-search t)
         (inhibit-read-only t)
         (inhibit-point-motion-hooks t)
@@ -3027,20 +3031,15 @@ should replace the \"Date:\" one, or should be added below it."
       (save-restriction
        (widen)
        (goto-char (point-min))
-       (while (and (or (setq date (get-text-property (setq pos (point))
-                                                     'original-date))
-                       (and (setq pos (next-single-property-change
-                                       (point) 'original-date))
-                            (progn
-                              (goto-char pos)
-                              (bolp))
-                            (setq date (get-text-property pos
-                                                          'original-date))))
-                   (not (string-equal date "")))
-         (narrow-to-region
-          pos
-          (or (text-property-any pos (point-max) 'original-date nil)
-              (point-max)))
+       (while (or (setq date (get-text-property (setq pos (point))
+                                                'original-date))
+                  (when (setq pos (next-single-property-change
+                                   (point) 'original-date))
+                    (setq date (get-text-property pos 'original-date))
+                    t))
+         (narrow-to-region pos (or (text-property-any pos (point-max)
+                                                      'original-date nil)
+                                   (point-max)))
          (goto-char (point-min))
          (when (re-search-forward tdate-regexp nil t)
            (setq bface (get-text-property (point-at-bol) 'face)
@@ -3222,7 +3221,10 @@ function and want to see what the date was before converting."
        (walk-windows
         (lambda (w)
           (set-buffer (window-buffer w))
-          (when (eq major-mode 'gnus-article-mode)
+          (when (or (and (eq major-mode 'mime-view-mode)
+                         (eq (mime-preview-original-major-mode)
+                             'gnus-original-article-mode))
+                    (eq major-mode 'gnus-article-mode))
             (let ((mark (point-marker)))
               (goto-char (point-min))
               (when (re-search-forward "^X-Sent:" nil t)
@@ -3260,21 +3262,28 @@ This format is defined by the `gnus-article-time-format' variable."
   (interactive (list t))
   (article-date-ut 'iso8601 highlight))
 
-(defun gnus-article-save-original-date ()
+(defun gnus-article-date-value ()
+  "Return the value of the date header.
+The buffer is expected to be narrowed to just the header of the article."
+  (goto-char (point-min))
+  (let* ((case-fold-search t)
+        (start (when (and (re-search-forward "^date:[\t\n ]+" nil t)
+                          (not (bolp)))
+                 (match-end 0))))
+    (when (and start
+              (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)" nil t))
+      (buffer-substring-no-properties start (match-beginning 0)))))
+
+(defmacro gnus-article-save-original-date (&rest forms)
   "Save the original date as a text property."
-  ;;(goto-char (point-max))
-  (skip-chars-backward "\n")
-  (let (start
-       (end (point))
-       (case-fold-search t))
-    (goto-char (point-min))
-    (when (and (re-search-forward "^date:[\t\n ]+" nil t)
-              (progn
-                (setq start (match-end 0))
-                (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)" nil t)))
-      (put-text-property
-       (point-min) end 'original-date
-       (buffer-substring-no-properties start (match-beginning 0))))))
+  `(let ((date (,(symbol-function 'gnus-article-date-value))))
+     (goto-char (point-max))
+     (skip-chars-backward "\n")
+     (put-text-property (point-min) (point) 'original-date date)
+     ,@forms
+     (goto-char (point-max))
+     (skip-chars-backward "\n")
+     (put-text-property (point-min) (point) 'original-date date)))
 
 ;; (defun article-show-all ()
 ;;   "Show all hidden text in the article buffer."
@@ -4214,8 +4223,7 @@ If ALL-HEADERS is non-nil, no headers are hidden."
                        (if (search-forward "\n\n" nil t)
                            (point)
                          (point-max)))
-      (gnus-article-save-original-date)
-      (gnus-treat-article 'head)
+      (gnus-article-save-original-date (gnus-treat-article 'head))
       (put-text-property (point-min) (point-max) 'article-treated-header t)
       (goto-char (point-max)))
     (while (and (not (eobp)) entity)
@@ -4310,8 +4318,7 @@ If ALL-HEADERS is non-nil, no headers are hidden."
                          (if (search-forward "\n\n" nil t)
                              (point)
                            (point-max)))
-       (gnus-article-save-original-date)
-       (gnus-treat-article 'head)
+       (gnus-article-save-original-date (gnus-treat-article 'head))
        (put-text-property (point-min) (point-max) 'article-treated-header t)
        (goto-char (point-max))
        (widen)
@@ -5031,7 +5038,7 @@ N is the numerical prefix."
          (set-window-point window point)))
       (let ((handles ihandles)
            (inhibit-read-only t)
-           handle name type b e display)
+           handle date)
        (cond (handles)
              ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
               (when gnus-article-emulate-mime
@@ -5070,8 +5077,8 @@ N is the numerical prefix."
            (save-restriction
              (article-goto-body)
              (narrow-to-region (point-min) (point))
-             (gnus-article-save-original-date)
-             (gnus-treat-article 'head))))))))
+             (gnus-article-save-original-date
+              (gnus-treat-article 'head)))))))))
 
 (defcustom gnus-mime-display-multipart-as-mixed nil
   "Display \"multipart\" parts as  \"multipart/mixed\".