Fix last change
[gnus] / lisp / mm-view.el
index 18ee3b5..ecfa2ac 100644 (file)
@@ -1,6 +1,6 @@
 ;;; mm-view.el --- functions for viewing MIME objects
 
-;; Copyright (C) 1998-201 Free Software Foundation, Inc.
+;; Copyright (C) 1998-2014 Free Software Foundation, Inc.
 
 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
 ;; This file is part of GNU Emacs.
@@ -22,9 +22,6 @@
 
 ;;; Code:
 
-;; For Emacs <22.2 and XEmacs.
-(eval-and-compile
-  (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
 (eval-when-compile (require 'cl))
 (require 'mail-parse)
 (require 'mailcap)
@@ -51,7 +48,6 @@
 
 (defvar mm-text-html-renderer-alist
   '((shr . mm-shr)
-    (w3 . mm-inline-text-html-render-with-w3)
     (w3m . mm-inline-text-html-render-with-w3m)
     (w3m-standalone . mm-inline-text-html-render-with-w3m-standalone)
     (gnus-w3m . gnus-article-html)
                                 (- (nth 3 edges) (nth 1 edges)))))))
          image))
      b)
-    (insert "\n\n")
+    (insert "\n")
     (mm-handle-set-undisplayer
      handle
      `(lambda ()
        (let ((b ,b)
              (inhibit-read-only t))
          (remove-images b b)
-         (delete-region b (+ b 2)))))))
+         (delete-region b (1+ b)))))))
 
 (defun mm-inline-image-xemacs (handle)
   (when (featurep 'xemacs)
-    (insert "\n\n")
-    (forward-char -2)
+    (insert "\n")
+    (forward-char -1)
     (let ((annot (make-annotation (mm-get-image handle) nil 'text))
        (inhibit-read-only t))
       (mm-handle-set-undisplayer
          (let ((b ,(point-marker))
              (inhibit-read-only t))
            (delete-annotation ,annot)
-           (delete-region (- b 2) b))))
+           (delete-region (1- b) b))))
       (set-extent-property annot 'mm t)
       (set-extent-property annot 'duplicable t))))
 
       (defalias 'mm-inline-image 'mm-inline-image-xemacs)
     (defalias 'mm-inline-image 'mm-inline-image-emacs)))
 
-;; External.
-(declare-function w3-do-setup       "ext:w3"         ())
-(declare-function w3-region         "ext:w3-display" (st nd))
-(declare-function w3-prepare-buffer "ext:w3-display" (&rest args))
-
-(defvar mm-w3-setup nil)
-(defun mm-setup-w3 ()
-  (unless mm-w3-setup
-    (require 'w3)
-    (w3-do-setup)
-    (require 'url)
-    (require 'w3-vars)
-    (require 'url-vars)
-    (setq mm-w3-setup t)))
-
-(defun mm-inline-text-html-render-with-w3 (handle)
-  (mm-setup-w3)
-  (let ((text (mm-get-part handle))
-       (b (point))
-       (url-standalone-mode t)
-       (url-gateway-unplugged t)
-       (w3-honor-stylesheets nil)
-       (url-current-object
-        (url-generic-parse-url (format "cid:%s" (mm-handle-id handle))))
-       (width (window-width))
-       (charset (mail-content-type-get
-                 (mm-handle-type handle) 'charset)))
-    (save-excursion
-      (insert (if charset (mm-decode-string text charset) text))
-      (save-restriction
-       (narrow-to-region b (point))
-       (unless charset
-         (goto-char (point-min))
-         (when (or (and (boundp 'w3-meta-content-type-charset-regexp)
-                        (re-search-forward
-                         w3-meta-content-type-charset-regexp nil t))
-                   (and (boundp 'w3-meta-charset-content-type-regexp)
-                        (re-search-forward
-                         w3-meta-charset-content-type-regexp nil t)))
-           (setq charset
-                 (let ((bsubstr (buffer-substring-no-properties
-                                 (match-beginning 2)
-                                 (match-end 2))))
-                   (if (fboundp 'w3-coding-system-for-mime-charset)
-                       (w3-coding-system-for-mime-charset bsubstr)
-                     (mm-charset-to-coding-system bsubstr))))
-           (delete-region (point-min) (point-max))
-           (insert (mm-decode-string text charset))))
-       (save-window-excursion
-         (save-restriction
-           (let ((w3-strict-width width)
-                 ;; Don't let w3 set the global version of
-                 ;; this variable.
-                 (fill-column fill-column))
-             (if (or debug-on-error debug-on-quit)
-                 (w3-region (point-min) (point-max))
-               (condition-case ()
-                   (w3-region (point-min) (point-max))
-                 (error
-                  (delete-region (point-min) (point-max))
-                  (let ((b (point))
-                        (charset (mail-content-type-get
-                                  (mm-handle-type handle) 'charset)))
-                    (if (or (eq charset 'gnus-decoded)
-                            (eq mail-parse-charset 'gnus-decoded))
-                      (save-restriction
-                        (narrow-to-region (point) (point))
-                        (mm-insert-part handle)
-                        (goto-char (point-max)))
-                      (insert (mm-decode-string (mm-get-part handle)
-                                                charset))))
-                  (message
-                   "Error while rendering html; showing as text/plain")))))))
-       (mm-handle-set-undisplayer
-        handle
-        `(lambda ()
-           (let ((inhibit-read-only t))
-             ,@(if (functionp 'remove-specifier)
-                    '((dolist (prop '(background background-pixmap foreground))
-                        (remove-specifier
-                         (face-property 'default prop)
-                         (current-buffer)))))
-             (delete-region ,(point-min-marker)
-                            ,(point-max-marker)))))))))
-
 (defvar mm-w3m-setup nil
   "Whether gnus-article-mode has been setup to use emacs-w3m.")
 
         handle
         `(lambda ()
            (let ((inhibit-read-only t))
-             (delete-region ,(point-min-marker)
+             (delete-region ,(copy-marker (point-min) t)
                             ,(point-max-marker)))))))))
 
 (defvar mm-w3m-standalone-supports-m17n-p (if (featurep 'mule) 'undecided)
                                                'charset)
                         (symbol-name mail-parse-charset)))
            cs)
-       (unless (and charset
-                    (setq cs (mm-charset-to-coding-system charset))
-                    (not (eq cs 'ascii)))
+       (if (and charset
+                (setq cs (mm-charset-to-coding-system charset nil t))
+                (not (eq cs 'ascii)))
+           (setq charset (format "%s" (mm-coding-system-to-mime-charset cs)))
          ;; The default.
          (setq charset "iso-8859-1"
                cs 'iso-8859-1))
        (buffer-string)))))
 
 (defun mm-inline-text-html (handle)
-  (let* ((func mm-text-html-renderer)
-        (entry (assq func mm-text-html-renderer-alist))
-        (inhibit-read-only t))
-    (if entry
-       (setq func (cdr entry)))
-    (cond
-     ((functionp func)
-      (funcall func handle))
-     (t
-      (apply (car func) handle (cdr func))))))
+  (if (stringp (car handle))
+      (mapcar 'mm-inline-text-html (cdr handle))
+    (let* ((func mm-text-html-renderer)
+          (entry (assq func mm-text-html-renderer-alist))
+          (inhibit-read-only t))
+      (if entry
+         (setq func (cdr entry)))
+      (cond
+       ((functionp func)
+       (funcall func handle))
+       (t
+       (apply (car func) handle (cdr func)))))))
 
 (defun mm-inline-text-vcard (handle)
   (let ((inhibit-read-only t))
        handle
        `(lambda ()
           (let ((inhibit-read-only t))
-           (delete-region ,(point-min-marker)
+           (delete-region ,(copy-marker (point-min) t)
                           ,(point-max-marker))))))))
 
 (defun mm-insert-inline (handle text)
      handle
      `(lambda ()
        (let ((inhibit-read-only t))
-         (delete-region ,(copy-marker b)
-                        ,(copy-marker (point))))))))
+         (delete-region ,(copy-marker b t)
+                        ,(point-marker)))))))
 
 (defun mm-inline-audio (handle)
   (message "Not implemented"))
 
-(defun mm-view-sound-file ()
-  (message "Not implemented"))
-
-(defun mm-w3-prepare-buffer ()
-  (require 'w3)
-  (let ((url-standalone-mode t)
-       (url-gateway-unplugged t)
-       (w3-honor-stylesheets nil))
-    (w3-prepare-buffer)))
-
 (defun mm-view-message ()
   (mm-enable-multibyte)
   (let (handles)
@@ -600,11 +504,11 @@ If MODE is not set, try to find mode automatically."
                     text)))
       (require 'font-lock)
       ;; I find font-lock a bit too verbose.
-      (let ((font-lock-verbose nil))
+      (let ((font-lock-verbose nil)
+           (font-lock-support-mode nil))
        ;; Disable support modes, e.g., jit-lock, lazy-lock, etc.
        ;; Note: XEmacs people use `font-lock-mode-hook' to run those modes.
        (set (make-local-variable 'font-lock-mode-hook) nil)
-       (set (make-local-variable 'font-lock-support-mode) nil)
         (setq buffer-file-name (mm-handle-filename handle))
         (set (make-local-variable 'enable-local-variables) nil)
        (with-demoted-errors
@@ -616,9 +520,11 @@ If MODE is not set, try to find mode automatically."
              (set-auto-mode)))
          ;; The mode function might have already turned on font-lock.
          ;; Do not fontify if the guess mode is fundamental.
-         (unless (or (symbol-value 'font-lock-mode)
+         (unless (or font-lock-mode
                      (eq major-mode 'fundamental-mode))
-           (font-lock-fontify-buffer))))
+            (if (fboundp 'font-lock-ensure)
+                (font-lock-ensure)
+              (font-lock-fontify-buffer)))))
       ;; By default, XEmacs font-lock uses non-duplicable text
       ;; properties.  This code forces all the text properties
       ;; to be copied along with the text.
@@ -663,14 +569,26 @@ If MODE is not set, try to find mode automatically."
 ;;      id-signedData OBJECT IDENTIFIER ::= { iso(1) member-body(2)
 ;;          us(840) rsadsi(113549) pkcs(1) pkcs7(7) 2 }
 (defvar mm-pkcs7-signed-magic
-  "\x30\x5c\x28\x80\x5c\x7c\x81\x2e\x5c\x7c\x82\x2e\x2e\x5c\x7c\x83\x2e\x2e\
-\x2e\x5c\x29\x06\x09\x5c\x2a\x86\x48\x86\xf7\x0d\x01\x07\x02")
+  (concat
+    "0"
+    "\\(\\(\x80\\)"
+    "\\|\\(\x81\\(.\\|\n\\)\\{1\\}\\)"
+    "\\|\\(\x82\\(.\\|\n\\)\\{2\\}\\)"
+    "\\|\\(\x83\\(.\\|\n\\)\\{3\\}\\)"
+    "\\)"
+    "\x06\x09\\*\x86H\x86\xf7\x0d\x01\x07\x02"))
 
 ;;      id-envelopedData OBJECT IDENTIFIER ::= { iso(1) member-body(2)
 ;;          us(840) rsadsi(113549) pkcs(1) pkcs7(7) 3 }
 (defvar mm-pkcs7-enveloped-magic
-  "\x30\x5c\x28\x80\x5c\x7c\x81\x2e\x5c\x7c\x82\x2e\x2e\x5c\x7c\x83\x2e\x2e\
-\x2e\x5c\x29\x06\x09\x5c\x2a\x86\x48\x86\xf7\x0d\x01\x07\x03")
+  (concat
+    "0"
+    "\\(\\(\x80\\)"
+    "\\|\\(\x81\\(.\\|\n\\)\\{1\\}\\)"
+    "\\|\\(\x82\\(.\\|\n\\)\\{2\\}\\)"
+    "\\|\\(\x83\\(.\\|\n\\)\\{3\\}\\)"
+    "\\)"
+    "\x06\x09\\*\x86H\x86\xf7\x0d\x01\x07\x03"))
 
 (defun mm-view-pkcs7-get-type (handle)
   (mm-with-unibyte-buffer