1 ;;; mm-view.el --- functions for viewing MIME objects
3 ;; Copyright (C) 1998-2011 Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; This file is part of GNU Emacs.
8 ;; GNU Emacs is free software: you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; GNU Emacs is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;; For Emacs <22.2 and XEmacs.
27 (unless (fboundp 'declare-function
) (defmacro declare-function
(&rest r
))))
28 (eval-when-compile (require 'cl
))
36 (autoload 'gnus-completing-read
"gnus-util")
37 (autoload 'gnus-window-inside-pixel-edges
"gnus-ems")
38 (autoload 'gnus-article-prepare-display
"gnus-art")
39 (autoload 'vcard-parse-string
"vcard")
40 (autoload 'vcard-format-string
"vcard")
41 (autoload 'fill-flowed
"flow-fill")
42 (autoload 'html2text
"html2text" nil t
)
44 (defvar gnus-article-mime-handles
)
45 (defvar gnus-newsgroup-charset
)
47 (defvar w3m-cid-retrieve-function-alist
)
48 (defvar w3m-current-buffer
)
49 (defvar w3m-display-inline-images
)
50 (defvar w3m-minor-mode-map
)
52 (defvar mm-text-html-renderer-alist
54 (w3 . mm-inline-text-html-render-with-w3
)
55 (w3m . mm-inline-text-html-render-with-w3m
)
56 (w3m-standalone . mm-inline-text-html-render-with-w3m-standalone
)
57 (gnus-w3m . gnus-article-html
)
58 (links mm-inline-render-with-file
59 mm-links-remove-leading-blank
61 (lynx mm-inline-render-with-stdin nil
62 "lynx" "-dump" "-force_html" "-stdin" "-nolist")
63 (html2text mm-inline-render-with-function html2text
))
64 "The attributes of renderer types for text/html.")
66 (defcustom mm-fill-flowed t
67 "If non-nil a format=flowed article will be displayed flowed."
72 (defcustom mm-inline-large-images-proportion
0.9
73 "Maximum proportion of large image resized when
74 `mm-inline-large-images' is set to resize."
79 ;;; Internal variables.
82 ;;; Functions for displaying various formats inline
85 (autoload 'gnus-rescale-image
"gnus-util")
87 (defun mm-inline-image-emacs (handle)
88 (let ((b (point-marker))
89 (inhibit-read-only t
))
91 (let ((image (mm-get-image handle
)))
92 (if (eq mm-inline-large-images
'resize
)
93 (gnus-rescale-image image
94 (let ((edges (gnus-window-inside-pixel-edges
95 (get-buffer-window (current-buffer)))))
96 (cons (truncate (* mm-inline-large-images-proportion
97 (- (nth 2 edges
) (nth 0 edges
))))
98 (truncate (* mm-inline-large-images-proportion
99 (- (nth 3 edges
) (nth 1 edges
)))))))
103 (mm-handle-set-undisplayer
107 (inhibit-read-only t
))
109 (delete-region b
(+ b
2)))))))
111 (defun mm-inline-image-xemacs (handle)
112 (when (featurep 'xemacs
)
115 (let ((annot (make-annotation (mm-get-image handle
) nil
'text
))
116 (inhibit-read-only t
))
117 (mm-handle-set-undisplayer
120 (let ((b ,(point-marker))
121 (inhibit-read-only t
))
122 (delete-annotation ,annot
)
123 (delete-region (- b
2) b
))))
124 (set-extent-property annot
'mm t
)
125 (set-extent-property annot
'duplicable t
))))
128 (if (featurep 'xemacs
)
129 (defalias 'mm-inline-image
'mm-inline-image-xemacs
)
130 (defalias 'mm-inline-image
'mm-inline-image-emacs
)))
133 (declare-function w3-do-setup
"ext:w3" ())
134 (declare-function w3-region
"ext:w3-display" (st nd
))
135 (declare-function w3-prepare-buffer
"ext:w3-display" (&rest args
))
137 (defvar mm-w3-setup nil
)
138 (defun mm-setup-w3 ()
145 (setq mm-w3-setup t
)))
147 (defun mm-inline-text-html-render-with-w3 (handle)
149 (let ((text (mm-get-part handle
))
151 (url-standalone-mode t
)
152 (url-gateway-unplugged t
)
153 (w3-honor-stylesheets nil
)
155 (url-generic-parse-url (format "cid:%s" (mm-handle-id handle
))))
156 (width (window-width))
157 (charset (mail-content-type-get
158 (mm-handle-type handle
) 'charset
)))
160 (insert (if charset
(mm-decode-string text charset
) text
))
162 (narrow-to-region b
(point))
164 (goto-char (point-min))
165 (when (or (and (boundp 'w3-meta-content-type-charset-regexp
)
167 w3-meta-content-type-charset-regexp nil t
))
168 (and (boundp 'w3-meta-charset-content-type-regexp
)
170 w3-meta-charset-content-type-regexp nil t
)))
172 (let ((bsubstr (buffer-substring-no-properties
175 (if (fboundp 'w3-coding-system-for-mime-charset
)
176 (w3-coding-system-for-mime-charset bsubstr
)
177 (mm-charset-to-coding-system bsubstr
))))
178 (delete-region (point-min) (point-max))
179 (insert (mm-decode-string text charset
))))
180 (save-window-excursion
182 (let ((w3-strict-width width
)
183 ;; Don't let w3 set the global version of
185 (fill-column fill-column
))
186 (if (or debug-on-error debug-on-quit
)
187 (w3-region (point-min) (point-max))
189 (w3-region (point-min) (point-max))
191 (delete-region (point-min) (point-max))
193 (charset (mail-content-type-get
194 (mm-handle-type handle
) 'charset
)))
195 (if (or (eq charset
'gnus-decoded
)
196 (eq mail-parse-charset
'gnus-decoded
))
198 (narrow-to-region (point) (point))
199 (mm-insert-part handle
)
200 (goto-char (point-max)))
201 (insert (mm-decode-string (mm-get-part handle
)
204 "Error while rendering html; showing as text/plain")))))))
205 (mm-handle-set-undisplayer
208 (let ((inhibit-read-only t
))
209 ,@(if (functionp 'remove-specifier
)
210 '((dolist (prop '(background background-pixmap foreground
))
212 (face-property 'default prop
)
214 (delete-region ,(point-min-marker)
215 ,(point-max-marker)))))))))
217 (defvar mm-w3m-setup nil
218 "Whether gnus-article-mode has been setup to use emacs-w3m.")
221 (declare-function w3m-detect-meta-charset
"ext:w3m" ())
222 (declare-function w3m-region
"ext:w3m" (start end
&optional url charset
))
224 (defun mm-setup-w3m ()
225 "Setup gnus-article-mode to use emacs-w3m."
228 (unless (assq 'gnus-article-mode w3m-cid-retrieve-function-alist
)
229 (push (cons 'gnus-article-mode
'mm-w3m-cid-retrieve
)
230 w3m-cid-retrieve-function-alist
))
231 (setq mm-w3m-setup t
))
232 (setq w3m-display-inline-images mm-inline-text-html-with-images
))
234 (defun mm-w3m-cid-retrieve-1 (url handle
)
235 (dolist (elem handle
)
237 (when (equal url
(mm-handle-id elem
))
238 (mm-insert-part elem
)
239 (throw 'found-handle
(mm-handle-media-type elem
)))
240 (when (and (stringp (car elem
))
241 (equal "multipart" (mm-handle-media-supertype elem
)))
242 (mm-w3m-cid-retrieve-1 url elem
)))))
244 (defun mm-w3m-cid-retrieve (url &rest args
)
245 "Insert a content pointed by URL if it has the cid: scheme."
246 (when (string-match "\\`cid:" url
)
247 (or (catch 'found-handle
248 (mm-w3m-cid-retrieve-1
249 (setq url
(concat "<" (substring url
(match-end 0)) ">"))
250 (with-current-buffer w3m-current-buffer
251 gnus-article-mime-handles
)))
254 (message "Failed to find \"Content-ID: %s\"" url
)))))
256 (defun mm-inline-text-html-render-with-w3m (handle)
257 "Render a text/html part using emacs-w3m."
259 (let ((text (mm-get-part handle
))
261 (charset (or (mail-content-type-get (mm-handle-type handle
) 'charset
)
262 mail-parse-charset
)))
264 (insert (if charset
(mm-decode-string text charset
) text
))
266 (narrow-to-region b
(point))
268 (goto-char (point-min))
269 (when (setq charset
(w3m-detect-meta-charset))
270 (delete-region (point-min) (point-max))
271 (insert (mm-decode-string text charset
))))
272 (let ((w3m-safe-url-regexp mm-w3m-safe-url-regexp
)
274 (w3m-region (point-min) (point-max) nil charset
))
275 ;; Put the mark meaning this part was rendered by emacs-w3m.
276 (put-text-property (point-min) (point-max)
277 'mm-inline-text-html-with-w3m t
)
278 (when (and mm-inline-text-html-with-w3m-keymap
279 (boundp 'w3m-minor-mode-map
)
281 (if (and (boundp 'w3m-link-map
)
283 (let* ((start (point-min))
285 (on (get-text-property start
'w3m-href-anchor
))
286 (map (copy-keymap w3m-link-map
))
288 (set-keymap-parent map w3m-minor-mode-map
)
292 (setq next
(or (text-property-any start end
293 'w3m-href-anchor nil
)
295 (put-text-property start next
'keymap map
))
296 (setq next
(or (text-property-not-all start end
297 'w3m-href-anchor nil
)
299 (put-text-property start next
'keymap w3m-minor-mode-map
))
302 (put-text-property (point-min) (point-max)
303 'keymap w3m-minor-mode-map
)))
304 (mm-handle-set-undisplayer
307 (let ((inhibit-read-only t
))
308 (delete-region ,(point-min-marker)
309 ,(point-max-marker)))))))))
311 (defvar mm-w3m-standalone-supports-m17n-p
(if (featurep 'mule
) 'undecided
)
312 "*T means the w3m command supports the m17n feature.")
314 (defun mm-w3m-standalone-supports-m17n-p ()
315 "Say whether the w3m command supports the m17n feature."
316 (cond ((eq mm-w3m-standalone-supports-m17n-p t
) t
)
317 ((eq mm-w3m-standalone-supports-m17n-p nil
) nil
)
318 ((not (featurep 'mule
)) (setq mm-w3m-standalone-supports-m17n-p nil
))
320 (let ((coding-system-for-write 'iso-2022-jp
)
321 (coding-system-for-read 'iso-2022-jp
)
322 (str (mm-decode-coding-string "\
323 \e$B#D#o#e#s!!#w#3#m!!#s#u#p#p#o#r#t!!#m#1#7#n!)\e(B" 'iso-2022-jp
)))
324 (mm-with-multibyte-buffer
327 (point-min) (point-max) "w3m" t t nil
"-dump"
328 "-T" "text/html" "-I" "iso-2022-jp" "-O" "iso-2022-jp")
329 (goto-char (point-min))
330 (search-forward str nil t
)))
332 (setq mm-w3m-standalone-supports-m17n-p t
))
334 ;;(message "You had better upgrade your w3m command")
335 (setq mm-w3m-standalone-supports-m17n-p nil
))))
337 (defun mm-inline-text-html-render-with-w3m-standalone (handle)
338 "Render a text/html part using w3m."
339 (if (mm-w3m-standalone-supports-m17n-p)
340 (let ((source (mm-get-part handle
))
341 (charset (or (mail-content-type-get (mm-handle-type handle
)
343 (symbol-name mail-parse-charset
)))
346 (setq cs
(mm-charset-to-coding-system charset
))
347 (not (eq cs
'ascii
)))
349 (setq charset
"iso-8859-1"
353 (mm-with-unibyte-buffer
355 (mm-enable-multibyte)
356 (let ((coding-system-for-write 'binary
)
357 (coding-system-for-read cs
))
359 (point-min) (point-max)
360 "w3m" t t nil
"-dump" "-T" "text/html"
361 "-I" charset
"-O" charset
))
363 (mm-inline-render-with-stdin handle nil
"w3m" "-dump" "-T" "text/html")))
365 (defun mm-links-remove-leading-blank ()
366 ;; Delete the annoying three spaces preceding each line of links
368 (goto-char (point-min))
369 (while (re-search-forward "^ " nil t
)
370 (delete-region (match-beginning 0) (match-end 0))))
372 (defun mm-inline-wash-with-file (post-func cmd
&rest args
)
373 (let ((file (mm-make-temp-file
374 (expand-file-name "mm" mm-tmp-directory
))))
375 (let ((coding-system-for-write 'binary
))
376 (write-region (point-min) (point-max) file nil
'silent
))
377 (delete-region (point-min) (point-max))
379 (apply 'call-process cmd nil t nil
(mapcar 'eval args
))
381 (and post-func
(funcall post-func
))))
383 (defun mm-inline-wash-with-stdin (post-func cmd
&rest args
)
384 (let ((coding-system-for-write 'binary
))
385 (apply 'call-process-region
(point-min) (point-max)
387 (and post-func
(funcall post-func
)))
389 (defun mm-inline-render-with-file (handle post-func cmd
&rest args
)
390 (let ((source (mm-get-part handle
)))
393 (mm-with-unibyte-buffer
395 (apply 'mm-inline-wash-with-file post-func cmd args
)
398 (defun mm-inline-render-with-stdin (handle post-func cmd
&rest args
)
399 (let ((source (mm-get-part handle
)))
402 (mm-with-unibyte-buffer
404 (apply 'mm-inline-wash-with-stdin post-func cmd args
)
407 (defun mm-inline-render-with-function (handle func
&rest args
)
408 (let ((source (mm-get-part handle
))
409 (charset (or (mail-content-type-get (mm-handle-type handle
) 'charset
)
410 mail-parse-charset
)))
413 (mm-with-multibyte-buffer
415 (mm-decode-string source charset
)
420 (defun mm-inline-text-html (handle)
421 (let* ((func mm-text-html-renderer
)
422 (entry (assq func mm-text-html-renderer-alist
))
423 (inhibit-read-only t
))
425 (setq func
(cdr entry
)))
428 (funcall func handle
))
430 (apply (car func
) handle
(cdr func
))))))
432 (defun mm-inline-text-vcard (handle)
433 (let ((inhibit-read-only t
))
438 (if (fboundp 'vcard-pretty-print
)
439 (vcard-pretty-print (mm-get-part handle
))
441 (vcard-parse-string (mm-get-part handle
)
442 'vcard-standard-filter
))))))))
444 (defun mm-inline-text (handle)
446 (type (mm-handle-media-subtype handle
))
447 (charset (mail-content-type-get
448 (mm-handle-type handle
) 'charset
))
449 (inhibit-read-only t
))
450 (if (or (eq charset
'gnus-decoded
)
451 ;; This is probably not entirely correct, but
452 ;; makes rfc822 parts with embedded multiparts work.
453 (eq mail-parse-charset
'gnus-decoded
))
455 (narrow-to-region (point) (point))
456 (mm-insert-part handle
)
457 (goto-char (point-max)))
458 (mm-display-inline-fontify handle
))
459 (when (and mm-fill-flowed
461 (equal (cdr (assoc 'format
(mm-handle-type handle
)))
464 (narrow-to-region b
(point))
466 (fill-flowed nil
(equal (cdr (assoc 'delsp
(mm-handle-type handle
)))
468 (goto-char (point-max))))
470 (narrow-to-region b
(point))
471 (when (member type
'("enriched" "richtext"))
472 (set-text-properties (point-min) (point-max) nil
)
474 (enriched-decode (point-min) (point-max))))
475 (mm-handle-set-undisplayer
478 (let ((inhibit-read-only t
))
479 (delete-region ,(point-min-marker)
480 ,(point-max-marker))))))))
482 (defun mm-insert-inline (handle text
)
483 "Insert TEXT inline from HANDLE."
488 (mm-handle-set-undisplayer
491 (let ((inhibit-read-only t
))
492 (delete-region ,(copy-marker b
)
493 ,(copy-marker (point))))))))
495 (defun mm-inline-audio (handle)
496 (message "Not implemented"))
498 (defun mm-view-sound-file ()
499 (message "Not implemented"))
501 (defun mm-w3-prepare-buffer ()
503 (let ((url-standalone-mode t
)
504 (url-gateway-unplugged t
)
505 (w3-honor-stylesheets nil
))
506 (w3-prepare-buffer)))
508 (defun mm-view-message ()
509 (mm-enable-multibyte)
511 (let (gnus-article-mime-handles)
512 ;; Double decode problem may happen. See mm-inline-message.
513 (run-hooks 'gnus-article-decode-hook
)
514 (gnus-article-prepare-display)
515 (setq handles gnus-article-mime-handles
))
517 (setq gnus-article-mime-handles
518 (mm-merge-handles gnus-article-mime-handles handles
))))
520 (goto-char (point-min)))
522 (defun mm-inline-message (handle)
525 (charset (mail-content-type-get
526 (mm-handle-type handle
) 'charset
))
527 gnus-displaying-mime handles
)
530 (setq charset
(intern (downcase charset
)))
531 (when (eq charset
'us-ascii
)
535 (narrow-to-region b b
)
536 (mm-insert-part handle
)
537 (let (gnus-article-mime-handles
538 ;; disable prepare hook
539 gnus-article-prepare-hook
540 (gnus-newsgroup-charset
541 (unless (eq charset
'gnus-decoded
) ;; mm-uu might set it.
542 (or charset gnus-newsgroup-charset
))))
543 (let ((gnus-original-article-buffer (mm-handle-buffer handle
)))
544 (run-hooks 'gnus-article-decode-hook
))
545 (gnus-article-prepare-display)
546 (setq handles gnus-article-mime-handles
))
547 (goto-char (point-min))
550 (goto-char (point-max))
553 (insert "----------\n\n")
555 (setq gnus-article-mime-handles
556 (mm-merge-handles gnus-article-mime-handles handles
)))
557 (mm-handle-set-undisplayer
560 (let ((inhibit-read-only t
))
561 (if (fboundp 'remove-specifier
)
562 ;; This is only valid on XEmacs.
563 (dolist (prop '(background background-pixmap foreground
))
565 (face-property 'default prop
) (current-buffer))))
566 (delete-region ,(point-min-marker) ,(point-max-marker)))))))))
568 (defun mm-display-inline-fontify (handle &optional mode
)
569 "Insert HANDLE inline fontifying with MODE.
570 If MODE is not set, try to find mode automatically."
571 (let ((charset (mail-content-type-get (mm-handle-type handle
) 'charset
))
573 (unless (eq charset
'gnus-decoded
)
574 (mm-with-unibyte-buffer
575 (mm-insert-part handle
)
576 (mm-decompress-buffer
577 (mm-handle-filename handle
)
580 (setq coding-system
(mm-find-buffer-file-coding-system)))
581 (setq text
(buffer-string))))
582 ;; XEmacs @#$@ version of font-lock refuses to fully turn itself
583 ;; on for buffers whose name begins with " ". That's why we use
584 ;; `with-current-buffer'/`generate-new-buffer' rather than
585 ;; `with-temp-buffer'.
586 (with-current-buffer (generate-new-buffer "*fontification*")
587 (buffer-disable-undo)
588 (mm-enable-multibyte)
589 (insert (cond ((eq charset
'gnus-decoded
)
590 (with-current-buffer (mm-handle-buffer handle
)
593 (mm-decode-coding-string text coding-system
))
595 (mm-decode-string text charset
))
599 (let ((font-lock-maximum-size nil
)
600 ;; Disable support modes, e.g., jit-lock, lazy-lock, etc.
601 (font-lock-mode-hook nil
)
602 (font-lock-support-mode nil
)
603 ;; I find font-lock a bit too verbose.
604 (font-lock-verbose nil
))
605 (setq buffer-file-name
(mm-handle-filename handle
))
606 (set (make-local-variable 'enable-local-variables
) nil
)
610 ;; The mode function might have already turned on font-lock.
611 ;; Do not fontify if the guess mode is fundamental.
612 (unless (or (symbol-value 'font-lock-mode
)
613 (eq major-mode
'fundamental-mode
))
614 (font-lock-fontify-buffer)))
615 ;; By default, XEmacs font-lock uses non-duplicable text
616 ;; properties. This code forces all the text properties
617 ;; to be copied along with the text.
618 (when (featurep 'xemacs
)
619 (map-extents (lambda (ext ignored
)
620 (set-extent-property ext
'duplicable t
)
622 nil nil nil nil nil
'text-prop
))
623 (setq text
(buffer-string))
624 ;; Set buffer unmodified to avoid confirmation when killing the
626 (set-buffer-modified-p nil
)
627 (kill-buffer (current-buffer)))
628 (mm-insert-inline handle text
)))
630 ;; Shouldn't these functions check whether the user even wants to use
631 ;; font-lock? At least under XEmacs, this fontification is pretty
632 ;; much unconditional. Also, it would be nice to change for the size
633 ;; of the fontified region.
635 (defun mm-display-patch-inline (handle)
636 (mm-display-inline-fontify handle
'diff-mode
))
638 (defun mm-display-elisp-inline (handle)
639 (mm-display-inline-fontify handle
'emacs-lisp-mode
))
641 (defun mm-display-dns-inline (handle)
642 (mm-display-inline-fontify handle
'dns-mode
))
644 (defun mm-display-org-inline (handle)
645 "Show an Org mode text from HANDLE inline."
646 (mm-display-inline-fontify handle
'org-mode
))
648 (defun mm-display-shell-script-inline (handle)
649 "Show a shell script from HANDLE inline."
650 (mm-display-inline-fontify handle
'shell-script-mode
))
652 (defun mm-display-javascript-inline (handle)
653 "Show JavsScript code from HANDLE inline."
654 (mm-display-inline-fontify handle
'javascript-mode
))
656 ;; id-signedData OBJECT IDENTIFIER ::= { iso(1) member-body(2)
657 ;; us(840) rsadsi(113549) pkcs(1) pkcs7(7) 2 }
658 (defvar mm-pkcs7-signed-magic
659 "\x30\x5c\x28\x80\x5c\x7c\x81\x2e\x5c\x7c\x82\x2e\x2e\x5c\x7c\x83\x2e\x2e\
660 \x2e\x5c\x29\x06\x09\x5c\x2a\x86\x48\x86\xf7\x0d\x01\x07\x02")
662 ;; id-envelopedData OBJECT IDENTIFIER ::= { iso(1) member-body(2)
663 ;; us(840) rsadsi(113549) pkcs(1) pkcs7(7) 3 }
664 (defvar mm-pkcs7-enveloped-magic
665 "\x30\x5c\x28\x80\x5c\x7c\x81\x2e\x5c\x7c\x82\x2e\x2e\x5c\x7c\x83\x2e\x2e\
666 \x2e\x5c\x29\x06\x09\x5c\x2a\x86\x48\x86\xf7\x0d\x01\x07\x03")
668 (defun mm-view-pkcs7-get-type (handle)
669 (mm-with-unibyte-buffer
670 (mm-insert-part handle
)
671 (cond ((looking-at mm-pkcs7-enveloped-magic
)
673 ((looking-at mm-pkcs7-signed-magic
)
676 (error "Could not identify PKCS#7 type")))))
678 (defun mm-view-pkcs7 (handle &optional from
)
679 (case (mm-view-pkcs7-get-type handle
)
680 (enveloped (mm-view-pkcs7-decrypt handle from
))
681 (signed (mm-view-pkcs7-verify handle
))
682 (otherwise (error "Unknown or unimplemented PKCS#7 type"))))
684 (defun mm-view-pkcs7-verify (handle)
685 (let ((verified nil
))
687 (insert "MIME-Version: 1.0\n")
688 (mm-insert-headers "application/pkcs7-mime" "base64" "smime.p7m")
689 (insert-buffer-substring (mm-handle-buffer handle
))
690 (setq verified
(smime-verify-region (point-min) (point-max))))
691 (goto-char (point-min))
692 (mm-insert-part handle
)
693 (if (search-forward "Content-Type: " nil t
)
694 (delete-region (point-min) (match-beginning 0)))
695 (goto-char (point-max))
696 (if (re-search-backward "--\r?\n?" nil t
)
697 (delete-region (match-end 0) (point-max)))
699 (insert-buffer-substring smime-details-buffer
)))
700 (goto-char (point-min))
701 (while (search-forward "\r\n" nil t
)
702 (replace-match "\n"))
705 (defun mm-view-pkcs7-decrypt (handle &optional from
)
706 (insert-buffer-substring (mm-handle-buffer handle
))
707 (goto-char (point-min))
708 (if (eq mml-smime-use
'epg
)
710 (let ((part (base64-decode-string (buffer-string))))
712 (insert (epg-decrypt-string (epg-make-context 'CMS
) part
)))
714 (insert "MIME-Version: 1.0\n")
715 (mm-insert-headers "application/pkcs7-mime" "base64" "smime.p7m")
716 (smime-decrypt-region
717 (point-min) (point-max)
718 (if (= (length smime-keys
) 1)
720 (smime-get-key-by-email
721 (gnus-completing-read
723 smime-keys nil nil nil
(car-safe (car-safe smime-keys
)))))
725 (goto-char (point-min))
726 (while (search-forward "\r\n" nil t
)
727 (replace-match "\n"))
728 (goto-char (point-min)))
732 ;;; mm-view.el ends here