* mm-view.el (mm-w3m-mode-ignored-keys): New variable.
[gnus] / lisp / mm-view.el
1 ;;; mm-view.el --- functions for viewing MIME objects
2 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
3
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; This file is part of GNU Emacs.
6
7 ;; GNU Emacs is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 2, or (at your option)
10 ;; any later version.
11
12 ;; GNU Emacs is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 ;; GNU General Public License for more details.
16
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
19 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 ;; Boston, MA 02111-1307, USA.
21
22 ;;; Commentary:
23
24 ;;; Code:
25
26 (eval-when-compile (require 'cl))
27 (require 'mail-parse)
28 (require 'mailcap)
29 (require 'mm-bodies)
30 (require 'mm-decode)
31
32 (eval-and-compile
33   (autoload 'gnus-article-prepare-display "gnus-art")
34   (autoload 'vcard-parse-string "vcard")
35   (autoload 'vcard-format-string "vcard")
36   (autoload 'fill-flowed "flow-fill")
37   (autoload 'html2text "html2text")
38   (unless (fboundp 'diff-mode)
39     (autoload 'diff-mode "diff-mode" "" t nil)))
40
41 (defvar mm-text-html-renderer-alist
42   '((w3  . mm-inline-text-html-render-with-w3)
43     (w3m . mm-inline-text-html-render-with-w3m)
44     (links mm-inline-render-with-file
45            mm-links-remove-leading-blank
46            "links" "-dump" file)
47     (lynx  mm-inline-render-with-stdin nil
48            "lynx" "-dump" "-force_html" "-stdin")
49     (html2text  mm-inline-render-with-function html2text))
50   "The attributes of renderer types for text/html.")
51
52 (defvar mm-text-html-washer-alist
53   '((w3  . gnus-article-wash-html-with-w3)
54     (w3m . gnus-article-wash-html-with-w3m)
55     (links mm-inline-wash-with-file
56            mm-links-remove-leading-blank
57            "links" "-dump" file)
58     (lynx  mm-inline-wash-with-stdin nil
59            "lynx" "-dump" "-force_html" "-stdin")
60     (html2text  html2text))
61   "The attributes of washer types for text/html.")
62
63 ;;; Internal variables.
64
65 ;;;
66 ;;; Functions for displaying various formats inline
67 ;;;
68
69 (defun mm-inline-image-emacs (handle)
70   (let ((b (point-marker))
71         buffer-read-only)
72     (insert "\n")
73     (put-image (mm-get-image handle) b)
74     (mm-handle-set-undisplayer
75      handle
76      `(lambda () (remove-images ,b (1+ ,b))))))
77
78 (defun mm-inline-image-xemacs (handle)
79   (insert "\n")
80   (forward-char -1)
81   (let ((b (point))
82         (annot (make-annotation (mm-get-image handle) nil 'text))
83         buffer-read-only)
84     (mm-handle-set-undisplayer
85      handle
86      `(lambda ()
87         (let (buffer-read-only)
88           (delete-annotation ,annot)
89           (delete-region ,(set-marker (make-marker) b)
90                          ,(set-marker (make-marker) (point))))))
91     (set-extent-property annot 'mm t)
92     (set-extent-property annot 'duplicable t)))
93
94 (eval-and-compile
95   (if (featurep 'xemacs)
96       (defalias 'mm-inline-image 'mm-inline-image-xemacs)
97     (defalias 'mm-inline-image 'mm-inline-image-emacs)))
98
99 (defvar mm-w3-setup nil)
100 (defun mm-setup-w3 ()
101   (unless mm-w3-setup
102     (require 'w3)
103     (w3-do-setup)
104     (require 'url)
105     (require 'w3-vars)
106     (require 'url-vars)
107     (setq mm-w3-setup t)))
108
109 (defun mm-inline-text-html-render-with-w3 (handle)
110   (mm-setup-w3)
111   (let ((text (mm-get-part handle))
112         (b (point))
113         (url-standalone-mode t)
114         (url-gateway-unplugged t)
115         (w3-honor-stylesheets nil)
116         (url-current-object
117          (url-generic-parse-url (format "cid:%s" (mm-handle-id handle))))
118         (width (window-width))
119         (charset (mail-content-type-get
120                   (mm-handle-type handle) 'charset)))
121     (save-excursion
122       (insert text)
123       (save-restriction
124         (narrow-to-region b (point))
125         (goto-char (point-min))
126         (if (or (and (boundp 'w3-meta-content-type-charset-regexp)
127                      (re-search-forward
128                       w3-meta-content-type-charset-regexp nil t))
129                 (and (boundp 'w3-meta-charset-content-type-regexp)
130                      (re-search-forward
131                       w3-meta-charset-content-type-regexp nil t)))
132             (setq charset
133                   (or (let ((bsubstr (buffer-substring-no-properties
134                                       (match-beginning 2)
135                                       (match-end 2))))
136                         (if (fboundp 'w3-coding-system-for-mime-charset)
137                             (w3-coding-system-for-mime-charset bsubstr)
138                           (mm-charset-to-coding-system bsubstr)))
139                       charset)))
140         (delete-region (point-min) (point-max))
141         (insert (mm-decode-string text charset))
142         (save-window-excursion
143           (save-restriction
144             (let ((w3-strict-width width)
145                   ;; Don't let w3 set the global version of
146                   ;; this variable.
147                   (fill-column fill-column))
148               (if (or debug-on-error debug-on-quit)
149                   (w3-region (point-min) (point-max))
150                 (condition-case ()
151                     (w3-region (point-min) (point-max))
152                   (error
153                    (delete-region (point-min) (point-max))
154                    (let ((b (point))
155                          (charset (mail-content-type-get
156                                    (mm-handle-type handle) 'charset)))
157                      (if (or (eq charset 'gnus-decoded)
158                              (eq mail-parse-charset 'gnus-decoded))
159                        (save-restriction
160                          (narrow-to-region (point) (point))
161                          (mm-insert-part handle)
162                          (goto-char (point-max)))
163                        (insert (mm-decode-string (mm-get-part handle)
164                                                  charset))))
165                    (message
166                     "Error while rendering html; showing as text/plain")))))))
167         (mm-handle-set-undisplayer
168          handle
169          `(lambda ()
170             (let (buffer-read-only)
171               (if (functionp 'remove-specifier)
172                   (mapcar (lambda (prop)
173                             (remove-specifier
174                              (face-property 'default prop)
175                              (current-buffer)))
176                           '(background background-pixmap foreground)))
177               (delete-region ,(point-min-marker)
178                              ,(point-max-marker)))))))))
179
180 (defvar mm-w3m-mode-map nil
181   "Local keymap for inlined text/html part rendered by emacs-w3m.  It will
182 be different from `w3m-mode-map' to use in the article buffer.")
183
184 (defvar mm-w3m-mode-command-alist
185   '((backward-char)
186     (describe-mode)
187     (forward-char)
188     (goto-line)
189     (next-line)
190     (previous-line)
191     (w3m-antenna)
192     (w3m-antenna-add-current-url)
193     (w3m-bookmark-add-current-url)
194     (w3m-bookmark-add-this-url)
195     (w3m-bookmark-view)
196     (w3m-close-window)
197     (w3m-copy-buffer)
198     (w3m-delete-buffer)
199     (w3m-dtree)
200     (w3m-edit-current-url)
201     (w3m-edit-this-url)
202     (w3m-gohome)
203     (w3m-goto-url)
204     (w3m-goto-url-new-session)
205     (w3m-history)
206     (w3m-history-restore-position)
207     (w3m-history-store-position)
208     (w3m-namazu)
209     (w3m-next-buffer)
210     (w3m-previous-buffer)
211     (w3m-quit)
212     (w3m-redisplay-with-charset)
213     (w3m-reload-this-page)
214     (w3m-scroll-down-or-previous-url)
215     (w3m-scroll-up-or-next-url)
216     (w3m-search)
217     (w3m-select-buffer)
218     (w3m-switch-buffer)
219     (w3m-view-header)
220     (w3m-view-parent-page)
221     (w3m-view-previous-page)
222     (w3m-view-source)
223     (w3m-weather))
224   "Alist of commands to use for emacs-w3m in the article buffer.  Each
225 element looks like (FROM-COMMAND . TO-COMMAND); FROM-COMMAND should be
226 registered in `w3m-mode-map' which will be substituted by TO-COMMAND
227 in `mm-w3m-mode-map'.  If TO-COMMAND is nil, an article command key
228 will not be substituted.")
229
230 (defvar mm-w3m-mode-dont-bind-keys (list [up] [right] [left] [down])
231   "List of keys which should not be bound for the emacs-w3m commands.")
232
233 (defvar mm-w3m-mode-ignored-keys (list [down-mouse-2])
234   "List of keys which should ignore.")
235
236 (defvar mm-w3m-setup nil
237   "Whether gnus-article-mode has been setup to use emacs-w3m.")
238
239 (defun mm-setup-w3m ()
240   "Setup gnus-article-mode to use emacs-w3m."
241   (unless mm-w3m-setup
242     (require 'w3m)
243     (unless mm-w3m-mode-map
244       (setq mm-w3m-mode-map (copy-keymap w3m-mode-map))
245       (dolist (def mm-w3m-mode-command-alist)
246         (condition-case nil
247             (substitute-key-definition (car def) (cdr def) mm-w3m-mode-map)
248           (error)))
249       (dolist (key mm-w3m-mode-dont-bind-keys)
250         (condition-case nil
251             (define-key mm-w3m-mode-map key nil)
252           (error)))
253       (dolist (key mm-w3m-mode-ignored-keys)
254         (condition-case nil
255             (define-key mm-w3m-mode-map key 'ignore)
256           (error))))
257     (unless (assq 'gnus-article-mode w3m-cid-retrieve-function-alist)
258       (push (cons 'gnus-article-mode 'mm-w3m-cid-retrieve)
259             w3m-cid-retrieve-function-alist))
260     (setq mm-w3m-setup t)))
261
262 (defun mm-w3m-cid-retrieve (url &rest args)
263   "Insert a content pointed by URL if it has the cid: scheme."
264   (when (string-match "\\`cid:" url)
265     (setq url (concat "<" (substring url (match-end 0)) ">"))
266     (catch 'found-handle
267       (dolist (handle (with-current-buffer w3m-current-buffer
268                         gnus-article-mime-handles))
269         (when (and (listp handle)
270                    (equal url (mm-handle-id handle)))
271           (mm-insert-part handle)
272           (throw 'found-handle (mm-handle-media-type handle)))))))
273
274 (defun mm-inline-text-html-render-with-w3m (handle)
275   "Render a text/html part using emacs-w3m."
276   (mm-setup-w3m)
277   (let ((text (mm-get-part handle))
278         (b (point))
279         (charset (mail-content-type-get (mm-handle-type handle) 'charset)))
280     (save-excursion
281       (insert text)
282       (save-restriction
283         (narrow-to-region b (point))
284         (goto-char (point-min))
285         (when (re-search-forward w3m-meta-content-type-charset-regexp nil t)
286           (setq charset (or (w3m-charset-to-coding-system (match-string 2))
287                             charset)))
288         (when charset
289           (delete-region (point-min) (point-max))
290           (insert (mm-decode-string text charset)))
291         (let ((w3m-safe-url-regexp mm-w3m-safe-url-regexp)
292               (w3m-display-inline-images mm-inline-text-html-with-images)
293               w3m-force-redisplay)
294           (w3m-region (point-min) (point-max)))
295         (when mm-inline-text-html-with-w3m-keymap
296           (add-text-properties
297            (point-min) (point-max)
298            (append '(mm-inline-text-html-with-w3m t)
299                    (gnus-local-map-property mm-w3m-mode-map)))))
300       (mm-handle-set-undisplayer
301        handle
302        `(lambda ()
303           (let (buffer-read-only)
304             (if (functionp 'remove-specifier)
305                 (mapcar (lambda (prop)
306                           (remove-specifier
307                            (face-property 'default prop)
308                            (current-buffer)))
309                         '(background background-pixmap foreground)))
310             (delete-region ,(point-min-marker)
311                            ,(point-max-marker))))))))
312
313 (defun mm-links-remove-leading-blank ()
314   ;; Delete the annoying three spaces preceding each line of links
315   ;; output.
316   (goto-char (point-min))
317   (while (re-search-forward "^   " nil t)
318     (delete-region (match-beginning 0) (match-end 0))))
319
320 (defun mm-inline-wash-with-file (post-func cmd &rest args)
321   (let ((file (mm-make-temp-file
322                (expand-file-name "mm" mm-tmp-directory))))
323     (let ((coding-system-for-write 'binary))
324       (write-region (point-min) (point-max) file nil 'silent))
325     (delete-region (point-min) (point-max))
326     (unwind-protect
327         (apply 'call-process cmd nil t nil (mapcar 'eval args))
328       (delete-file file))
329     (and post-func (funcall post-func))))
330
331 (defun mm-inline-wash-with-stdin (post-func cmd &rest args)
332   (let ((coding-system-for-write 'binary))
333     (apply 'call-process-region (point-min) (point-max)
334            cmd t t nil args))
335   (and post-func (funcall post-func)))
336
337 (defun mm-inline-render-with-file (handle post-func cmd &rest args)
338   (let ((source (mm-get-part handle)))
339     (mm-insert-inline
340      handle
341      (mm-with-unibyte-buffer
342        (insert source)
343        (apply 'mm-inline-wash-with-file post-func cmd args)
344        (buffer-string)))))
345
346 (defun mm-inline-render-with-stdin (handle post-func cmd &rest args)
347   (let ((source (mm-get-part handle)))
348     (mm-insert-inline
349      handle
350      (mm-with-unibyte-buffer
351        (insert source)
352        (apply 'mm-inline-wash-with-stdin post-func cmd args)
353        (buffer-string)))))
354
355 (defun mm-inline-render-with-function (handle func &rest args)
356   (let ((source (mm-get-part handle)))
357     (mm-insert-inline
358      handle
359      (mm-with-unibyte-buffer
360        (insert source)
361        (apply func args)
362        (buffer-string)))))
363
364 (defun mm-inline-text-html (handle)
365   (let* ((func (or mm-inline-text-html-renderer mm-text-html-renderer))
366          (entry (assq func mm-text-html-renderer-alist))
367          buffer-read-only)
368     (if entry
369         (setq func (cdr entry)))
370     (cond
371      ((gnus-functionp func)
372       (funcall func handle))
373      (t
374       (apply (car func) handle (cdr func))))))
375
376 (defun mm-inline-text-vcard (handle)
377   (let (buffer-read-only)
378     (mm-insert-inline
379      handle
380      (concat "\n-- \n"
381              (ignore-errors
382                (if (fboundp 'vcard-pretty-print)
383                    (vcard-pretty-print (mm-get-part handle))
384                  (vcard-format-string
385                   (vcard-parse-string (mm-get-part handle)
386                                       'vcard-standard-filter))))))))
387
388 (defun mm-inline-text (handle)
389   (let ((b (point))
390         (type (mm-handle-media-subtype handle))
391         (charset (mail-content-type-get
392                   (mm-handle-type handle) 'charset))
393         buffer-read-only)
394     (if (or (eq charset 'gnus-decoded)
395             ;; This is probably not entirely correct, but
396             ;; makes rfc822 parts with embedded multiparts work.
397             (eq mail-parse-charset 'gnus-decoded))
398         (save-restriction
399           (narrow-to-region (point) (point))
400           (mm-insert-part handle)
401           (goto-char (point-max)))
402       (insert (mm-decode-string (mm-get-part handle) charset)))
403     (when (and (equal type "plain")
404                (equal (cdr (assoc 'format (mm-handle-type handle)))
405                       "flowed"))
406       (save-restriction
407         (narrow-to-region b (point))
408         (goto-char b)
409         (fill-flowed)
410         (goto-char (point-max))))
411     (save-restriction
412       (narrow-to-region b (point))
413       (set-text-properties (point-min) (point-max) nil)
414       (when (or (equal type "enriched")
415                 (equal type "richtext"))
416         (enriched-decode (point-min) (point-max)))
417       (mm-handle-set-undisplayer
418        handle
419        `(lambda ()
420           (let (buffer-read-only)
421             (delete-region ,(point-min-marker)
422                            ,(point-max-marker))))))))
423
424 (defun mm-insert-inline (handle text)
425   "Insert TEXT inline from HANDLE."
426   (let ((b (point)))
427     (insert text)
428     (mm-handle-set-undisplayer
429      handle
430      `(lambda ()
431         (let (buffer-read-only)
432           (delete-region ,(set-marker (make-marker) b)
433                          ,(set-marker (make-marker) (point))))))))
434
435 (defun mm-inline-audio (handle)
436   (message "Not implemented"))
437
438 (defun mm-view-sound-file ()
439   (message "Not implemented"))
440
441 (defun mm-w3-prepare-buffer ()
442   (require 'w3)
443   (let ((url-standalone-mode t)
444         (url-gateway-unplugged t)
445         (w3-honor-stylesheets nil))
446     (w3-prepare-buffer)))
447
448 (defun mm-view-message ()
449   (mm-enable-multibyte)
450   (let (handles)
451     (let (gnus-article-mime-handles)
452       ;; Double decode problem may happen.  See mm-inline-message.
453       (run-hooks 'gnus-article-decode-hook)
454       (gnus-article-prepare-display)
455       (setq handles gnus-article-mime-handles))
456     (when handles
457       (setq gnus-article-mime-handles
458             (mm-merge-handles gnus-article-mime-handles handles))))
459   (fundamental-mode)
460   (goto-char (point-min)))
461
462 (defun mm-inline-message (handle)
463   (let ((b (point))
464         (bolp (bolp))
465         (charset (mail-content-type-get
466                   (mm-handle-type handle) 'charset))
467         gnus-displaying-mime handles)
468     (when (and charset
469                (stringp charset))
470       (setq charset (intern (downcase charset)))
471       (when (eq charset 'us-ascii)
472         (setq charset nil)))
473     (save-excursion
474       (save-restriction
475         (narrow-to-region b b)
476         (mm-insert-part handle)
477         (let (gnus-article-mime-handles
478               ;; disable prepare hook
479               gnus-article-prepare-hook
480               (gnus-newsgroup-charset
481                (or charset gnus-newsgroup-charset)))
482           (run-hooks 'gnus-article-decode-hook)
483           (gnus-article-prepare-display)
484           (setq handles gnus-article-mime-handles))
485         (goto-char (point-min))
486         (unless bolp
487           (insert "\n"))
488         (goto-char (point-max))
489         (unless (bolp)
490           (insert "\n"))
491         (insert "----------\n\n")
492         (when handles
493           (setq gnus-article-mime-handles
494                 (mm-merge-handles gnus-article-mime-handles handles)))
495         (mm-handle-set-undisplayer
496          handle
497          `(lambda ()
498             (let (buffer-read-only)
499               (if (fboundp 'remove-specifier)
500                   ;; This is only valid on XEmacs.
501                   (mapcar (lambda (prop)
502                             (remove-specifier
503                              (face-property 'default prop) (current-buffer)))
504                           '(background background-pixmap foreground)))
505               (delete-region ,(point-min-marker) ,(point-max-marker)))))))))
506
507 (defun mm-display-inline-fontify (handle mode)
508   (let (text)
509     ;; XEmacs @#$@ version of font-lock refuses to fully turn itself
510     ;; on for buffers whose name begins with " ".  That's why we use
511     ;; save-current-buffer/get-buffer-create rather than
512     ;; with-temp-buffer.
513     (save-current-buffer
514       (set-buffer (generate-new-buffer "*fontification*"))
515       (unwind-protect
516           (progn
517             (buffer-disable-undo)
518             (mm-insert-part handle)
519             (funcall mode)
520             (require 'font-lock)
521             (let ((font-lock-verbose nil))
522               ;; I find font-lock a bit too verbose.
523               (font-lock-fontify-buffer))
524             ;; By default, XEmacs font-lock uses non-duplicable text
525             ;; properties.  This code forces all the text properties
526             ;; to be copied along with the text.
527             (when (fboundp 'extent-list)
528               (map-extents (lambda (ext ignored)
529                              (set-extent-property ext 'duplicable t)
530                              nil)
531                            nil nil nil nil nil 'text-prop))
532             (setq text (buffer-string)))
533         (kill-buffer (current-buffer))))
534     (mm-insert-inline handle text)))
535
536 ;; Shouldn't these functions check whether the user even wants to use
537 ;; font-lock?  At least under XEmacs, this fontification is pretty
538 ;; much unconditional.  Also, it would be nice to change for the size
539 ;; of the fontified region.
540
541 (defun mm-display-patch-inline (handle)
542   (mm-display-inline-fontify handle 'diff-mode))
543
544 (defun mm-display-elisp-inline (handle)
545   (mm-display-inline-fontify handle 'emacs-lisp-mode))
546
547 ;;      id-signedData OBJECT IDENTIFIER ::= { iso(1) member-body(2)
548 ;;          us(840) rsadsi(113549) pkcs(1) pkcs7(7) 2 }
549 (defvar mm-pkcs7-signed-magic
550   (mm-string-as-unibyte
551    (apply 'concat
552           (mapcar 'char-to-string
553                   (list ?\x30 ?\x5c ?\x28 ?\x80 ?\x5c ?\x7c ?\x81 ?\x2e ?\x5c
554                         ?\x7c ?\x82 ?\x2e ?\x2e ?\x5c ?\x7c ?\x83 ?\x2e ?\x2e
555                         ?\x2e ?\x5c ?\x29 ?\x06 ?\x09 ?\x5c ?\x2a ?\x86 ?\x48
556                         ?\x86 ?\xf7 ?\x0d ?\x01 ?\x07 ?\x02)))))
557
558 ;;      id-envelopedData OBJECT IDENTIFIER ::= { iso(1) member-body(2)
559 ;;          us(840) rsadsi(113549) pkcs(1) pkcs7(7) 3 }
560 (defvar mm-pkcs7-enveloped-magic
561   (mm-string-as-unibyte
562    (apply 'concat
563           (mapcar 'char-to-string
564                   (list ?\x30 ?\x5c ?\x28 ?\x80 ?\x5c ?\x7c ?\x81 ?\x2e ?\x5c
565                         ?\x7c ?\x82 ?\x2e ?\x2e ?\x5c ?\x7c ?\x83 ?\x2e ?\x2e
566                         ?\x2e ?\x5c ?\x29 ?\x06 ?\x09 ?\x5c ?\x2a ?\x86 ?\x48
567                         ?\x86 ?\xf7 ?\x0d ?\x01 ?\x07 ?\x03)))))
568
569 (defun mm-view-pkcs7-get-type (handle)
570   (mm-with-unibyte-buffer
571     (mm-insert-part handle)
572     (cond ((looking-at mm-pkcs7-enveloped-magic)
573            'enveloped)
574           ((looking-at mm-pkcs7-signed-magic)
575            'signed)
576           (t
577            (error "Could not identify PKCS#7 type")))))
578
579 (defun mm-view-pkcs7 (handle)
580   (case (mm-view-pkcs7-get-type handle)
581     (enveloped (mm-view-pkcs7-decrypt handle))
582     (signed (mm-view-pkcs7-verify handle))
583     (otherwise (error "Unknown or unimplemented PKCS#7 type"))))
584
585 (defun mm-view-pkcs7-verify (handle)
586   ;; A bogus implementation of PKCS#7. FIXME::
587   (mm-insert-part handle)
588   (goto-char (point-min))
589   (if (search-forward "Content-Type: " nil t)
590       (delete-region (point-min) (match-beginning 0)))
591   (goto-char (point-max))
592   (if (re-search-backward "--\r?\n?" nil t)
593       (delete-region (match-end 0) (point-max)))
594   (goto-char (point-min))
595   (while (search-forward "\r\n" nil t)
596     (replace-match "\n"))
597   (message "Verify signed PKCS#7 message is unimplemented.")
598   (sit-for 1)
599   t)
600
601 (defun mm-view-pkcs7-decrypt (handle)
602   (insert-buffer (mm-handle-buffer handle))
603   (goto-char (point-min))
604   (insert "MIME-Version: 1.0\n")
605   (mm-insert-headers "application/pkcs7-mime" "base64" "smime.p7m")
606   (smime-decrypt-region
607    (point-min) (point-max)
608    (if (= (length smime-keys) 1)
609        (cadar smime-keys)
610      (smime-get-key-by-email
611       (completing-read
612        (concat "Decipher using which key? "
613                (if smime-keys (concat "(default " (caar smime-keys) ") ")
614                  ""))
615        smime-keys nil nil nil nil (car-safe (car-safe smime-keys))))))
616   (goto-char (point-min))
617   (while (search-forward "\r\n" nil t)
618     (replace-match "\n"))
619   (goto-char (point-min)))
620
621 (provide 'mm-view)
622
623 ;;; mm-view.el ends here