]> code.delx.au - gnu-emacs/blobdiff - lisp/mail/rmailedit.el
* emacs-lisp/trace.el (trace-function, trace-function-background): Doc fix.
[gnu-emacs] / lisp / mail / rmailedit.el
index 868ca15923f1c858f8d5280ee6737674624f1343..b880e21b8ca6b0ec09b63720bcaecbdf5ddcd310 100644 (file)
@@ -1,6 +1,6 @@
 ;;; rmailedit.el --- "RMAIL edit mode"  Edit the current message
 
-;; Copyright (C) 1985, 1994, 2001-201 Free Software Foundation, Inc.
+;; Copyright (C) 1985, 1994, 2001-2013 Free Software Foundation, Inc.
 
 ;; Maintainer: FSF
 ;; Keywords: mail
@@ -78,6 +78,7 @@ This function runs the hooks `text-mode-hook' and `rmail-edit-mode-hook'.
 \f
 
 (defvar rmail-old-text)
+(defvar rmail-old-mime-state)
 (defvar rmail-old-pruned nil
   "Non-nil means the message being edited originally had pruned headers.")
 (put 'rmail-old-pruned 'permanent-local t)
@@ -86,6 +87,10 @@ This function runs the hooks `text-mode-hook' and `rmail-edit-mode-hook'.
   "Holds the headers of this message before editing started.")
 (put 'rmail-old-headers 'permanent-local t)
 
+;; Everything we use from here is a defsubst.
+(eval-when-compile
+  (require 'rmailmm))
+
 ;;;###autoload
 (defun rmail-edit-current-message ()
   "Edit the contents of this message."
@@ -96,6 +101,30 @@ This function runs the hooks `text-mode-hook' and `rmail-edit-mode-hook'.
   (make-local-variable 'rmail-old-pruned)
   (setq rmail-old-pruned (rmail-msg-is-pruned))
   (rmail-edit-mode)
+  (set (make-local-variable 'rmail-old-mime-state)
+       (and rmail-enable-mime
+           ;; If you use something else, you are on your own.
+           (eq rmail-mime-feature 'rmailmm)
+           (rmail-mime-message-p)
+           (let ((entity (get-text-property (point-min) 'rmail-mime-entity)))
+             ;; rmailmm has got its hands on the message.
+             ;; Even if the message is in `raw' state, boundaries etc
+             ;; are still missing.  All we can do is insert the real
+             ;; raw message.  (Bug#9840)
+             ;; FIXME?  Since the 2012-09-17 changes to rmail-mime,
+             ;; can we just use that function now?
+             (when (and entity
+                        (not (equal "text/plain"
+                                    (car (rmail-mime-entity-type entity)))))
+               (let ((inhibit-read-only t))
+                 (erase-buffer)
+                 (insert-buffer-substring
+                  rmail-view-buffer
+                  (aref (rmail-mime-entity-header entity) 0)
+                  (aref (rmail-mime-entity-body entity) 1)))
+               (goto-char (point-min))
+               ;; t = decoded; raw = raw.
+               (aref (aref (rmail-mime-entity-display entity) 0) 0)))))
   (make-local-variable 'rmail-old-text)
   (setq rmail-old-text
        (save-restriction
@@ -134,7 +163,10 @@ This function runs the hooks `text-mode-hook' and `rmail-edit-mode-hook'.
       (error "There must be a blank line at the end of the headers"))
   ;; Disguise any "From " lines so they don't start a new message.
   (goto-char (point-min))
-  (or rmail-old-pruned (forward-line 1))
+  ;; This tries to skip the mbox From.  FIXME less fragile to go to EOH?
+  (if (or rmail-old-mime-state
+         (not rmail-old-pruned))
+      (forward-line 1))
   (while (re-search-forward "^>*From " nil t)
     (beginning-of-line)
     (insert ">")
@@ -145,6 +177,7 @@ This function runs the hooks `text-mode-hook' and `rmail-edit-mode-hook'.
   (rmail-ensure-blank-line)
   (let ((old rmail-old-text)
        (pruned rmail-old-pruned)
+       (mime-state rmail-old-mime-state)
        ;; People who know what they are doing might have modified the
        ;; buffer's encoding if editing the message included inserting
        ;; characters that were unencodable by the original message's
@@ -256,7 +289,9 @@ This function runs the hooks `text-mode-hook' and `rmail-edit-mode-hook'.
 ;;;    (if (boundp 'rmail-summary-vector)
 ;;;    (aset rmail-summary-vector (1- rmail-current-message) nil))
     (rmail-show-message)
-    (rmail-toggle-header (if pruned 1 0)))
+    (rmail-toggle-header (if pruned 1 0))
+    ;; Restore mime display state.
+    (and mime-state (rmail-mime nil mime-state)))
   (run-hooks 'rmail-mode-hook))
 
 (defun rmail-abort-edit ()