]> code.delx.au - gnu-emacs/blobdiff - lisp/mh-e/mh-mime.el
Merge from origin/emacs-25
[gnu-emacs] / lisp / mh-e / mh-mime.el
index 66e1ba5ec696080334cb19a68765b42071efbab8..b8d700ddf5f73f491a15f188977752a62fc2f3e2 100644 (file)
@@ -1,6 +1,6 @@
 ;;; mh-mime.el --- MH-E MIME support
 
-;; Copyright (C) 1993, 1995, 2001-201 Free Software Foundation, Inc.
+;; Copyright (C) 1993, 1995, 2001-2016 Free Software Foundation, Inc.
 
 ;; Author: Bill Wohler <wohler@newt.com>
 ;; Maintainer: Bill Wohler <wohler@newt.com>
@@ -268,10 +268,12 @@ usually reads the file \"/etc/mailcap\"."
               (buffer-read-only nil))
          (when (string-match "^[^% \t]+$" method)
            (setq method (concat method " %s")))
-         (flet ((mm-handle-set-external-undisplayer (handle function)
-                  (mh-handle-set-external-undisplayer folder handle function)))
-           (unwind-protect (mm-display-external part method)
-             (set-buffer-modified-p nil)))))
+         (mh-flet
+          ((mm-handle-set-external-undisplayer
+            (handle function)
+            (mh-handle-set-external-undisplayer folder handle function)))
+          (unwind-protect (mm-display-external part method)
+            (set-buffer-modified-p nil)))))
    nil))
 
 ;;;###mh-autoload
@@ -523,47 +525,48 @@ parsed and then displayed."
   (let ((handles ())
         (folder mh-show-folder-buffer)
         (raw-message-data (buffer-string)))
-    (flet ((mm-handle-set-external-undisplayer
-            (handle function)
-            (mh-handle-set-external-undisplayer folder handle function)))
-      (goto-char (point-min))
-      (unless (search-forward "\n\n" nil t)
-        (goto-char (point-max))
-        (insert "\n\n"))
-
-      (condition-case err
-          (progn
-            ;; If needed dissect the current buffer
-            (if pre-dissected-handles
-                (setq handles pre-dissected-handles)
-              (if (setq handles (mm-dissect-buffer nil))
-                  (mh-mm-uu-dissect-text-parts handles)
-                (setq handles (mm-uu-dissect)))
-              (setf (mh-mime-handles (mh-buffer-data))
-                    (mh-mm-merge-handles handles
-                                         (mh-mime-handles (mh-buffer-data))))
-              (unless handles
-                (mh-decode-message-body)))
-
-            (cond ((and handles
-                        (or (not (stringp (car handles)))
-                            (cdr handles)))
-                   ;; Go to start of message body
-                   (goto-char (point-min))
-                   (or (search-forward "\n\n" nil t)
-                       (goto-char (point-max)))
-
-                   ;; Delete the body
-                   (delete-region (point) (point-max))
-
-                   ;; Display the MIME handles
-                   (mh-mime-display-part handles))
-                  (t
-                   (mh-signature-highlight))))
-        (error
-         (message "Could not display body: %s" (error-message-string err))
-         (delete-region (point-min) (point-max))
-         (insert raw-message-data))))))
+    (mh-flet
+     ((mm-handle-set-external-undisplayer
+       (handle function)
+       (mh-handle-set-external-undisplayer folder handle function)))
+     (goto-char (point-min))
+     (unless (search-forward "\n\n" nil t)
+       (goto-char (point-max))
+       (insert "\n\n"))
+
+     (condition-case err
+         (progn
+           ;; If needed dissect the current buffer
+           (if pre-dissected-handles
+               (setq handles pre-dissected-handles)
+             (if (setq handles (mm-dissect-buffer nil))
+                 (mh-mm-uu-dissect-text-parts handles)
+               (setq handles (mm-uu-dissect)))
+             (setf (mh-mime-handles (mh-buffer-data))
+                   (mh-mm-merge-handles handles
+                                        (mh-mime-handles (mh-buffer-data))))
+             (unless handles
+               (mh-decode-message-body)))
+
+           (cond ((and handles
+                       (or (not (stringp (car handles)))
+                           (cdr handles)))
+                  ;; Go to start of message body
+                  (goto-char (point-min))
+                  (or (search-forward "\n\n" nil t)
+                      (goto-char (point-max)))
+
+                  ;; Delete the body
+                  (delete-region (point) (point-max))
+
+                  ;; Display the MIME handles
+                  (mh-mime-display-part handles))
+                 (t
+                  (mh-signature-highlight))))
+       (error
+        (message "Could not display body: %s" (error-message-string err))
+        (delete-region (point-min) (point-max))
+        (insert raw-message-data))))))
 
 (defun mh-decode-message-body ()
   "Decode message based on charset.
@@ -1046,13 +1049,14 @@ attachment, the attachment is hidden."
         (function (get-text-property (point) 'mh-callback))
         (buffer-read-only nil)
         (folder mh-show-folder-buffer))
-    (flet ((mm-handle-set-external-undisplayer
-            (handle function)
-            (mh-handle-set-external-undisplayer folder handle function)))
-      (when (and function (eolp))
-        (backward-char))
-      (unwind-protect (and function (funcall function data))
-        (set-buffer-modified-p nil)))))
+    (mh-flet
+     ((mm-handle-set-external-undisplayer
+       (handle function)
+       (mh-handle-set-external-undisplayer folder handle function)))
+     (when (and function (eolp))
+       (backward-char))
+     (unwind-protect (and function (funcall function data))
+       (set-buffer-modified-p nil)))))
 
 (defun mh-push-button (event)
   "Click MIME button for EVENT.
@@ -1066,9 +1070,11 @@ to click the MIME button."
           (mm-inline-media-tests mh-mm-inline-media-tests)
           (data (get-text-property (point) 'mh-data))
           (function (get-text-property (point) 'mh-callback)))
-      (flet ((mm-handle-set-external-undisplayer (handle func)
-               (mh-handle-set-external-undisplayer folder handle func)))
-        (and function (funcall function data))))))
+      (mh-flet
+       ((mm-handle-set-external-undisplayer
+         (handle func)
+         (mh-handle-set-external-undisplayer folder handle func)))
+       (and function (funcall function data))))))
 
 (defun mh-handle-set-external-undisplayer (folder handle function)
   "Replacement for `mm-handle-set-external-undisplayer'.
@@ -1160,10 +1166,11 @@ this ;-)"
 (defun mh-display-emphasis ()
   "Display graphical emphasis."
   (when (and mh-graphical-emphasis-flag (mh-small-show-buffer-p))
-    (flet ((article-goto-body ()))      ; shadow this function to do nothing
-      (save-excursion
-        (goto-char (point-min))
-        (article-emphasize)))))
+    (mh-flet
+     ((article-goto-body ()))      ; shadow this function to do nothing
+     (save-excursion
+       (goto-char (point-min))
+       (article-emphasize)))))
 
 (defun mh-small-show-buffer-p ()
   "Check if show buffer is small.
@@ -1708,7 +1715,7 @@ buffer, while END defaults to the end of the buffer."
 (defun mh-minibuffer-read-type (filename &optional default)
   "Return the content type associated with the given FILENAME.
 If the \"file\" command exists and recognizes the given file,
-then its value is returned\; otherwise, the user is prompted for
+then its value is returned; otherwise, the user is prompted for
 a type (see `mailcap-mime-types').
 Optional argument DEFAULT is returned if a type isn't entered."
   (mailcap-parse-mimetypes)
@@ -1749,21 +1756,21 @@ Returns nil if file command not on system."
           (kill-buffer tmp-buffer)))))))
 
 (defvar mh-file-mime-type-substitutions
-  '(("application/msword" "\.xls" "application/ms-excel")
-    ("application/msword" "\.ppt" "application/ms-powerpoint")
-    ("text/plain" "\.vcf" "text/x-vcard")
-    ("text/rtf" "\.rtf" "application/rtf")
-    ("application/x-zip" "\.sxc" "application/vnd.sun.xml.calc")
-    ("application/x-zip" "\.sxd" "application/vnd.sun.xml.draw")
-    ("application/x-zip" "\.sxi" "application/vnd.sun.xml.impress")
-    ("application/x-zip" "\.sxw" "application/vnd.sun.xml.writer")
-    ("application/x-zip" "\.odg" "application/vnd.oasis.opendocument.graphics")
-    ("application/x-zip" "\.odi" "application/vnd.oasis.opendocument.image")
-    ("application/x-zip" "\.odp"
+  '(("application/msword" "\\.xls" "application/ms-excel")
+    ("application/msword" "\\.ppt" "application/ms-powerpoint")
+    ("text/plain" "\\.vcf" "text/x-vcard")
+    ("text/rtf" "\\.rtf" "application/rtf")
+    ("application/x-zip" "\\.sxc" "application/vnd.sun.xml.calc")
+    ("application/x-zip" "\\.sxd" "application/vnd.sun.xml.draw")
+    ("application/x-zip" "\\.sxi" "application/vnd.sun.xml.impress")
+    ("application/x-zip" "\\.sxw" "application/vnd.sun.xml.writer")
+    ("application/x-zip" "\\.odg" "application/vnd.oasis.opendocument.graphics")
+    ("application/x-zip" "\\.odi" "application/vnd.oasis.opendocument.image")
+    ("application/x-zip" "\\.odp"
      "application/vnd.oasis.opendocument.presentation")
-    ("application/x-zip" "\.ods"
+    ("application/x-zip" "\\.ods"
      "application/vnd.oasis.opendocument.spreadsheet")
-    ("application/x-zip" "\.odt" "application/vnd.oasis.opendocument.text"))
+    ("application/x-zip" "\\.odt" "application/vnd.oasis.opendocument.text"))
   "Substitutions to make for Content-Type returned from file command.
 The first element is the Content-Type returned by the file command.
 The second element is a regexp matching the file name, usually the
@@ -1794,7 +1801,7 @@ initialized. Always use the command `mh-have-file-command'.")
 
 ;;;###mh-autoload
 (defun mh-have-file-command ()
-  "Return t if 'file' command is on the system.
+  "Return t if `file' command is on the system.
 'file -i' is used to get MIME type of composition insertion."
   (when (eq mh-have-file-command 'undefined)
     (setq mh-have-file-command