+(defun mm-inline-message (handle)
+ (let ((b (point))
+ (bolp (bolp))
+ (charset (mail-content-type-get
+ (mm-handle-type handle) 'charset))
+ gnus-displaying-mime handles)
+ (when (and charset
+ (stringp charset))
+ (setq charset (intern (downcase charset)))
+ (when (eq charset 'us-ascii)
+ (setq charset nil)))
+ (save-excursion
+ (save-restriction
+ (narrow-to-region b b)
+ (mm-insert-part handle)
+ (let (gnus-article-mime-handles
+ ;; disable prepare hook
+ gnus-article-prepare-hook
+ (gnus-newsgroup-charset
+ (unless (eq charset 'gnus-decoded) ;; mm-uu might set it.
+ (or charset gnus-newsgroup-charset))))
+ (let ((gnus-original-article-buffer (mm-handle-buffer handle)))
+ (run-hooks 'gnus-article-decode-hook))
+ (gnus-article-prepare-display)
+ (setq handles gnus-article-mime-handles))
+ (goto-char (point-min))
+ (unless bolp
+ (insert "\n"))
+ (goto-char (point-max))
+ (unless (bolp)
+ (insert "\n"))
+ (insert "----------\n\n")
+ (when handles
+ (setq gnus-article-mime-handles
+ (mm-merge-handles gnus-article-mime-handles handles)))
+ (mm-handle-set-undisplayer
+ handle
+ `(lambda ()
+ (let ((inhibit-read-only t))
+ (if (fboundp 'remove-specifier)
+ ;; This is only valid on XEmacs.
+ (dolist (prop '(background background-pixmap foreground))
+ (remove-specifier
+ (face-property 'default prop) (current-buffer))))
+ (delete-region ,(point-min-marker) ,(point-max-marker)))))))))
+
+;; Shut up byte-compiler.
+(defvar font-lock-mode-hook)
+(defun mm-display-inline-fontify (handle &optional mode)
+ "Insert HANDLE inline fontifying with MODE.
+If MODE is not set, try to find mode automatically."
+ (let ((charset (mail-content-type-get (mm-handle-type handle) 'charset))
+ text coding-system)
+ (unless (eq charset 'gnus-decoded)
+ (mm-with-unibyte-buffer
+ (mm-insert-part handle)
+ (mm-decompress-buffer
+ (mm-handle-filename handle)
+ t t)
+ (unless charset
+ (setq coding-system (mm-find-buffer-file-coding-system)))
+ (setq text (buffer-string))))
+ ;; XEmacs @#$@ version of font-lock refuses to fully turn itself
+ ;; on for buffers whose name begins with " ". That's why we use
+ ;; `with-current-buffer'/`generate-new-buffer' rather than
+ ;; `with-temp-buffer'.
+ (with-current-buffer (generate-new-buffer "*fontification*")
+ (buffer-disable-undo)
+ (mm-enable-multibyte)
+ (insert (cond ((eq charset 'gnus-decoded)
+ (with-current-buffer (mm-handle-buffer handle)
+ (buffer-string)))
+ (coding-system
+ (mm-decode-coding-string text coding-system))
+ (charset
+ (mm-decode-string text charset))
+ (t
+ text)))
+ (require 'font-lock)
+ ;; I find font-lock a bit too verbose.
+ (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)
+ (setq buffer-file-name (mm-handle-filename handle))
+ (set (make-local-variable 'enable-local-variables) nil)
+ (with-demoted-errors
+ (if mode
+ (funcall mode)
+ (let ((auto-mode-alist
+ (delq (rassq 'doc-view-mode-maybe auto-mode-alist)
+ (copy-sequence auto-mode-alist))))
+ (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)
+ (eq major-mode 'fundamental-mode))
+ (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.
+ (when (featurep 'xemacs)
+ (map-extents (lambda (ext ignored)
+ (set-extent-property ext 'duplicable t)
+ nil)
+ nil nil nil nil nil 'text-prop))
+ (setq text (buffer-string))
+ ;; Set buffer unmodified to avoid confirmation when killing the
+ ;; buffer.
+ (set-buffer-modified-p nil)
+ (kill-buffer (current-buffer)))
+ (mm-insert-inline handle text)))
+
+;; Shouldn't these functions check whether the user even wants to use
+;; font-lock? At least under XEmacs, this fontification is pretty
+;; much unconditional. Also, it would be nice to change for the size
+;; of the fontified region.
+
+(defun mm-display-patch-inline (handle)
+ (mm-display-inline-fontify handle 'diff-mode))
+
+(defun mm-display-elisp-inline (handle)
+ (mm-display-inline-fontify handle 'emacs-lisp-mode))
+
+(defun mm-display-dns-inline (handle)
+ (mm-display-inline-fontify handle 'dns-mode))
+
+(defun mm-display-org-inline (handle)
+ "Show an Org mode text from HANDLE inline."
+ (mm-display-inline-fontify handle 'org-mode))
+
+(defun mm-display-shell-script-inline (handle)
+ "Show a shell script from HANDLE inline."
+ (mm-display-inline-fontify handle 'shell-script-mode))
+
+(defun mm-display-javascript-inline (handle)
+ "Show JavsScript code from HANDLE inline."
+ (mm-display-inline-fontify handle 'javascript-mode))
+
+;; 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")
+
+;; 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")
+
+(defun mm-view-pkcs7-get-type (handle)
+ (mm-with-unibyte-buffer
+ (mm-insert-part handle)
+ (cond ((looking-at mm-pkcs7-enveloped-magic)
+ 'enveloped)
+ ((looking-at mm-pkcs7-signed-magic)
+ 'signed)
+ (t
+ (error "Could not identify PKCS#7 type")))))
+
+(defun mm-view-pkcs7 (handle &optional from)
+ (case (mm-view-pkcs7-get-type handle)
+ (enveloped (mm-view-pkcs7-decrypt handle from))
+ (signed (mm-view-pkcs7-verify handle))
+ (otherwise (error "Unknown or unimplemented PKCS#7 type"))))
+
+(defun mm-view-pkcs7-verify (handle)
+ (let ((verified nil))
+ (with-temp-buffer
+ (insert "MIME-Version: 1.0\n")
+ (mm-insert-headers "application/pkcs7-mime" "base64" "smime.p7m")
+ (insert-buffer-substring (mm-handle-buffer handle))
+ (setq verified (smime-verify-region (point-min) (point-max))))
+ (goto-char (point-min))
+ (mm-insert-part handle)
+ (if (search-forward "Content-Type: " nil t)
+ (delete-region (point-min) (match-beginning 0)))
+ (goto-char (point-max))
+ (if (re-search-backward "--\r?\n?" nil t)
+ (delete-region (match-end 0) (point-max)))
+ (unless verified
+ (insert-buffer-substring smime-details-buffer)))
+ (goto-char (point-min))
+ (while (search-forward "\r\n" nil t)
+ (replace-match "\n"))
+ t)
+
+(defun mm-view-pkcs7-decrypt (handle &optional from)
+ (insert-buffer-substring (mm-handle-buffer handle))
+ (goto-char (point-min))
+ (if (eq mml-smime-use 'epg)
+ ;; Use EPG/gpgsm
+ (let ((part (base64-decode-string (buffer-string))))
+ (erase-buffer)
+ (insert (epg-decrypt-string (epg-make-context 'CMS) part)))
+ ;; Use openssl
+ (insert "MIME-Version: 1.0\n")
+ (mm-insert-headers "application/pkcs7-mime" "base64" "smime.p7m")
+ (smime-decrypt-region
+ (point-min) (point-max)
+ (if (= (length smime-keys) 1)
+ (cadar smime-keys)
+ (smime-get-key-by-email
+ (gnus-completing-read
+ "Decipher using key"
+ smime-keys nil nil nil (car-safe (car-safe smime-keys)))))
+ from))
+ (goto-char (point-min))
+ (while (search-forward "\r\n" nil t)
+ (replace-match "\n"))
+ (goto-char (point-min)))
+