* wl-mime.el (wl-message-decrypt-pgp-nonmime): New function.
[elisp/wanderlust.git] / wl / wl-mime.el
1 ;;; wl-mime.el --- SEMI implementations of MIME processing on Wanderlust.
2
3 ;; Copyright (C) 1998,1999,2000 Yuuichi Teranishi <teranisi@gohome.org>
4
5 ;; Author: Yuuichi Teranishi <teranisi@gohome.org>
6 ;; Keywords: mail, net news
7
8 ;; This file is part of Wanderlust (Yet Another Message Interface on Emacsen).
9
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14 ;;
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19 ;;
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24 ;;
25
26 ;;; Commentary:
27 ;;
28
29 ;;; Code:
30 ;;
31
32 (require 'mime-view)
33 (require 'mime-edit)
34 (require 'mime-play)
35 (require 'elmo)
36
37 (eval-when-compile
38   (defalias-maybe 'pgg-decrypt-region 'ignore)
39   (defalias-maybe 'pgg-display-output-buffer 'ignore)
40   (defalias-maybe 'pgg-verify-region 'ignore))
41
42 ;;; Draft
43
44 (defalias 'wl-draft-editor-mode 'mime-edit-mode)
45
46 (defalias 'wl-draft-decode-message-in-buffer
47   'mime-edit-decode-message-in-buffer)
48
49 (defun wl-draft-yank-current-message-entity ()
50   "Yank currently displayed message entity.
51 By setting following-method as yank-content.
52
53 If region is active, yank region contents instead. \(this feature is available
54 if and only if `transient-mark-mode' \(GNU Emacs\) or `zmacs-regions' \(XEmacs\)
55 has Non-nil value\)"
56   (let ((wl-draft-buffer (current-buffer))
57         (mime-view-following-method-alist
58          (list (cons 'wl-original-message-mode
59                      (function wl-draft-yank-to-draft-buffer))))
60         (mime-preview-following-method-alist
61          (list (cons 'wl-original-message-mode
62                      (function wl-draft-yank-to-draft-buffer)))))
63     (if (get-buffer (wl-current-message-buffer))
64         (save-excursion
65           (set-buffer (wl-current-message-buffer))
66           (save-restriction
67             (widen)
68             (if (wl-region-exists-p)
69                 (wl-mime-preview-follow-current-region)
70               (mime-preview-follow-current-entity)))))))
71
72 ;; modified mime-preview-follow-current-entity from mime-view.el
73 (defun wl-mime-preview-follow-current-region ()
74   "Write follow message to current region.
75 It calls following-method selected from variable
76 `mime-preview-following-method-alist'."
77   (interactive)
78   (let ((r-beg (region-beginning))
79         (r-end (region-end))
80         (entity (get-text-property (point-min)
81                                    'mime-view-entity)))
82     (let* ((mode (mime-preview-original-major-mode 'recursive))
83            (new-name
84             (format "%s-active-region" (buffer-name)))
85            new-buf
86            (the-buf (current-buffer))
87            fields)
88       (save-excursion
89         (set-buffer (setq new-buf (get-buffer-create new-name)))
90         (erase-buffer)
91         (insert ?\n)
92         (insert-buffer-substring the-buf r-beg r-end)
93         (goto-char (point-min))
94         (let ((current-entity
95                (if (and (eq (mime-entity-media-type entity) 'message)
96                         (eq (mime-entity-media-subtype entity) 'rfc822))
97                    (car (mime-entity-children entity))
98                  entity)))
99           (while (and current-entity
100                       (if (and (eq (mime-entity-media-type
101                                     current-entity) 'message)
102                                (eq (mime-entity-media-subtype
103                                     current-entity) 'rfc822))
104                           nil
105                         (mime-insert-header current-entity fields)
106                         t))
107             (setq fields (std11-collect-field-names)
108                   current-entity (mime-entity-parent current-entity))
109             ))
110         (let ((rest mime-view-following-required-fields-list)
111               field-name ret)
112           (while rest
113             (setq field-name (car rest))
114             (or (std11-field-body field-name)
115                 (progn
116                   (save-excursion
117                     (set-buffer the-buf)
118                     (let ((entity (when mime-mother-buffer
119                                     (set-buffer mime-mother-buffer)
120                                     (get-text-property (point)
121                                                        'mime-view-entity))))
122                       (while (and entity
123                                   (null (setq ret (mime-entity-fetch-field
124                                                    entity field-name))))
125                         (setq entity (mime-entity-parent entity)))))
126                   (if ret
127                       (insert (concat field-name ": " ret "\n"))
128                     )))
129             (setq rest (cdr rest))
130             ))
131         )
132       (let ((f (cdr (assq mode mime-preview-following-method-alist))))
133         (if (functionp f)
134             (funcall f new-buf)
135           (message
136            (format
137             "Sorry, following method for %s is not implemented yet."
138             mode))
139           ))
140       )))
141
142 (defalias 'wl-draft-enclose-digest-region 'mime-edit-enclose-digest-region)
143
144 (defun wl-draft-preview-message ()
145   "Preview editing message."
146   (interactive)
147   (let* (recipients-message
148          (current-point (point))
149          (config-exec-flag wl-draft-config-exec-flag)
150          (parent-folder wl-draft-parent-folder)
151          (mime-display-header-hook 'wl-highlight-headers)
152          (mime-header-encode-method-alist
153           (append
154            '((wl-draft-eword-encode-address-list
155               .  (To Cc Bcc Resent-To Resent-Cc Bcc Resent-Bcc)))
156            (if (boundp 'mime-header-encode-method-alist)
157                (symbol-value 'mime-header-encode-method-alist))))
158          mime-view-ignored-field-list   ; all header.
159          (mime-edit-translate-buffer-hook
160           (append
161            (list
162             (function
163              (lambda ()
164                (let ((wl-draft-config-exec-flag config-exec-flag)
165                      (wl-draft-parent-folder parent-folder))
166                  (goto-char current-point)
167                  (run-hooks 'wl-draft-send-hook)
168                  (setq recipients-message
169                        (condition-case err
170                            (concat "Recipients: "
171                                    (mapconcat
172                                     'identity
173                                     (wl-draft-deduce-address-list
174                                      (current-buffer)
175                                      (point-min)
176                                      (save-excursion
177                                        (goto-char (point-min))
178                                        (re-search-forward
179                                         (concat
180                                          "^"
181                                          (regexp-quote mail-header-separator)
182                                          "$")
183                                         nil t)
184                                        (point)))
185                                     ", "))
186                          (error
187                           (kill-buffer (current-buffer))
188                           (signal (car err) (cdr err)))))))))
189            mime-edit-translate-buffer-hook)))
190     (mime-edit-preview-message)
191     (let ((buffer-read-only nil))
192       (when wl-highlight-body-too
193         (wl-highlight-body))
194       (run-hooks 'wl-draft-preview-message-hook))
195     (message recipients-message)))
196
197 (defalias 'wl-draft-caesar-region  'mule-caesar-region)
198
199 (defalias 'wl-draft-insert-message 'mime-edit-insert-message)
200
201 (defalias 'wl-draft-insert-mail 'mime-edit-insert-mail)
202
203 ;;; Message
204
205 (defun wl-message-decode-mode (outbuf inbuf)
206   (let ((mime-view-content-header-filter-hook 'wl-highlight-headers)
207         (mime-display-header-hook 'wl-highlight-headers))
208     (mime-view-mode nil nil nil inbuf outbuf)))
209
210 (defun wl-message-decode-with-all-header (outbuf inbuf)
211   (let ((mime-view-ignored-field-regexp "^:$")
212         (mime-view-content-header-filter-hook 'wl-highlight-headers)
213         (mime-display-header-hook 'wl-highlight-headers)
214         mime-view-ignored-field-list)
215     (mime-view-mode nil nil nil inbuf outbuf)))
216
217 (defun wl-message-delete-mime-out-buf ()
218   (let (mime-out-buf mime-out-win)
219     (if (setq mime-out-buf (get-buffer mime-echo-buffer-name))
220         (if (setq mime-out-win (get-buffer-window mime-out-buf))
221             (delete-window mime-out-win)))))
222
223 (defun wl-message-request-partial (folder number)
224   (elmo-set-work-buf
225    (elmo-message-fetch (wl-folder-get-elmo-folder folder)
226                        number
227                        (elmo-make-fetch-strategy 'entire)
228                        nil
229                        (current-buffer)
230                        'unread)
231    (mime-parse-buffer nil)))
232
233 (defalias 'wl-message-read              'mime-preview-scroll-up-entity)
234 (defalias 'wl-message-next-content      'mime-preview-move-to-next)
235 (defalias 'wl-message-prev-content      'mime-preview-move-to-previous)
236 (defalias 'wl-message-play-content      'mime-preview-play-current-entity)
237 (defalias 'wl-message-extract-content   'mime-preview-extract-current-entity)
238 (defalias 'wl-message-quit              'mime-preview-quit)
239 (defalias 'wl-message-button-dispatcher-internal
240   'mime-button-dispatcher)
241
242 (defsubst wl-mime-node-id-to-string (node-id)
243   (if (consp node-id)
244       (mapconcat (function (lambda (num) (format "%s" (1+ num))))
245                  (reverse node-id)
246                  ".")
247     "0"))
248
249 (defun wl-message-delete-current-part ()
250   "Delete a part under the cursor from the multipart message."
251   (interactive)
252   (save-restriction
253     (widen)
254     (let* ((entity (get-text-property (point) 'mime-view-entity))
255            (node-id (mime-entity-node-id entity))
256            (header-start (mime-buffer-entity-header-start-internal entity))
257            (body-end (mime-buffer-entity-body-end-internal entity))
258            (folder (wl-folder-get-elmo-folder wl-message-buffer-cur-folder))
259            (number wl-message-buffer-cur-number)
260            (msgid (elmo-message-field folder number 'message-id))
261            (orig-buf wl-message-buffer-original-buffer))
262       (if (eq (luna-class-name entity) 'mime-elmo-imap-entity)
263           (error "Please fetch the entire message (by typing 'C-u .') and try again"))
264       (with-current-buffer orig-buf
265         (unless (string-equal
266                  (buffer-string)
267                  (elmo-message-fetch folder number
268                                      (elmo-make-fetch-strategy 'entire)))
269           (error "Buffer content differs from actual message")))
270       (when (and (elmo-folder-writable-p folder)
271                  (buffer-live-p orig-buf)
272                  node-id
273                  (yes-or-no-p
274                   (format "Do you really want to delete part %s? "
275                           (wl-mime-node-id-to-string node-id))))
276         (with-temp-buffer
277           (insert-buffer orig-buf)
278           (delete-region header-start body-end)
279           (goto-char header-start)
280           (insert "Content-Type: text/plain; charset=US-ASCII\n\n")
281           (insert "** This part has been removed by Wanderlust **\n\n")
282           (elmo-folder-append-buffer folder t))
283
284         (elmo-folder-append-messages
285          (wl-folder-get-elmo-folder wl-trash-folder)
286          folder (list number) nil)
287         (elmo-folder-delete-messages folder (list number))
288
289         (when (file-exists-p (elmo-cache-get-path msgid))
290           (delete-file (elmo-cache-get-path msgid)))
291
292         (mime-preview-quit)
293         (wl-summary-toggle-disp-msg 'off)
294         (wl-summary-sync nil "update")))))
295
296 (defun wl-message-decrypt-pgp-nonmime ()
297   "Decrypt PGP encrypted region"
298   (interactive)
299   (require 'pgg)
300   (save-excursion
301     (beginning-of-line)
302     (if (or (re-search-forward "^-+END PGP MESSAGE-+$" nil t)
303             (re-search-backward "^-+END PGP MESSAGE-+$" nil t))
304         (let (beg end status)
305           (setq end (match-end 0))
306           (if (setq beg (re-search-backward "^-+BEGIN PGP MESSAGE-+$" nil t))
307               (let ((inhibit-read-only t))
308                 (setq status (pgg-decrypt-region beg end))
309                 (pgg-display-output-buffer beg end status))
310             (message "Cannot find pgp encrypted region")))
311       (message "Cannot find pgp encrypted region"))))
312
313 (defun wl-message-verify-pgp-nonmime ()
314   "Verify PGP signed region"
315   (interactive)
316   (require 'pgg)
317   (save-excursion
318     (beginning-of-line)
319     (if (or (re-search-forward "^-+END PGP SIGNATURE-+$" nil t)
320             (re-search-backward "^-+END PGP SIGNATURE-+$" nil t))
321         (let (beg end status)
322           (setq end (match-end 0))
323           (if (setq beg (re-search-backward "^-+BEGIN PGP SIGNED MESSAGE-+$" nil t))
324               (progn
325                 (save-excursion
326                   (mime-show-echo-buffer)
327                   (set-buffer mime-echo-buffer-name)
328                   (set-window-start
329                    (get-buffer-window mime-echo-buffer-name)
330                    (point-max)))
331                 (setq status (pgg-verify-region beg end nil 'fetch))
332                 (set-buffer mime-echo-buffer-name)
333                 (insert-buffer-substring
334                  (if status pgg-output-buffer pgg-errors-buffer)))
335             (message "Cannot find pgp signed region")))
336       (message "Cannot find pgp signed region"))))
337
338 ;; XXX: encrypted multipart isn't represented as multipart
339 (defun wl-mime-preview-application/pgp (parent-entity entity situation)
340   (require 'pgg)
341   (goto-char (point-max))
342   (let ((p (point))
343         raw-buf to-buf representation-type child-entity)
344     (goto-char p)
345     (save-restriction
346       (narrow-to-region p p)
347       (setq to-buf (current-buffer))
348       (with-temp-buffer
349         (setq raw-buf (current-buffer))
350         (mime-insert-entity entity)
351         (cond ((progn
352                  (goto-char (point-min))
353                  (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE-+$" nil t))
354                (pgg-verify-region (match-beginning 0)(point-max) nil 'fetch)
355                (goto-char (point-min))
356                (delete-region
357                 (point-min)
358                 (and
359                  (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE-+\n\n")
360                  (match-end 0)))
361                (delete-region
362                 (and (re-search-forward "^-+BEGIN PGP SIGNATURE-+")
363                      (match-beginning 0))
364                 (point-max))
365                (goto-char (point-min))
366                (while (re-search-forward "^- -" nil t)
367                  (replace-match "-"))
368                (setq representation-type (if (mime-entity-cooked-p entity)
369                                              'cooked)))
370               ((progn
371                  (goto-char (point-min))
372                  (re-search-forward "^-+BEGIN PGP MESSAGE-+$" nil t))
373                (pgg-decrypt-region (point-min)(point-max))
374                (delete-region (point-min) (point-max))
375                (insert-buffer pgg-output-buffer)
376                (setq representation-type 'elmo-buffer)))
377         (setq child-entity (mime-parse-message
378                             (mm-expand-class-name representation-type)
379                             nil
380                             parent-entity
381                             (mime-entity-node-id-internal parent-entity)))
382         (mime-display-entity
383          child-entity
384          nil
385          `((header . visible)
386            (body . visible)
387            (entity-button . invisible))
388          to-buf)))))
389
390 (defun wl-mime-preview-application/pgp-encrypted (entity situation)
391   (let* ((entity-node-id (mime-entity-node-id entity))
392          (mother (mime-entity-parent entity))
393          (knum (car entity-node-id))
394          (onum (if (> knum 0)
395                    (1- knum)
396                  (1+ knum)))
397          (orig-entity (nth onum (mime-entity-children mother))))
398     (wl-mime-preview-application/pgp entity orig-entity situation)))
399
400 ;;; Summary
401 (defun wl-summary-burst-subr (message-entity target number)
402   ;; returns new number.
403   (let (content-type entity)
404     (setq content-type (mime-entity-content-type message-entity))
405     (cond ((eq (cdr (assq 'type content-type)) 'multipart)
406            (dolist (entity (mime-entity-children message-entity))
407              (setq number (wl-summary-burst-subr
408                            entity
409                            target
410                            number))))
411           ((and (eq (cdr (assq 'type content-type)) 'message)
412                 (eq (cdr (assq 'subtype content-type)) 'rfc822))
413            (message "Bursting...%s" (setq number (+ 1 number)))
414            (setq entity
415                  (car (mime-entity-children message-entity)))
416            (with-temp-buffer
417              (insert (mime-entity-body message-entity))
418              (elmo-folder-append-buffer
419               target
420               (mime-entity-fetch-field entity "Message-ID")))))
421     number))
422
423 (defun wl-summary-burst (&optional arg)
424   "De-capsulate embedded messages in MIME format.
425 With ARG, ask destination folder."
426   (interactive "P")
427   (let ((raw-buf (wl-summary-get-original-buffer))
428         (view-buf wl-message-buffer)
429         children message-entity content-type target)
430     (save-excursion
431       (setq target wl-summary-buffer-elmo-folder)
432       (when (or arg (not (elmo-folder-writable-p target)))
433         (let ((fld (wl-summary-read-folder wl-default-folder "to extract to")))
434           (setq target (wl-folder-get-elmo-folder fld))))
435       (wl-summary-set-message-buffer-or-redisplay)
436       (with-current-buffer view-buf
437         (setq message-entity (get-text-property (point-min) 'mime-view-entity)))
438       (when message-entity
439         (message "Bursting...")
440         (with-current-buffer raw-buf
441           (wl-summary-burst-subr message-entity target 0))
442         (message "Bursting...done"))
443       (if (elmo-folder-plugged-p target)
444           (elmo-folder-check target)))
445     (wl-summary-sync-update)))
446
447 ;; internal variable.
448 (defvar wl-mime-save-directory nil "Last saved directory.")
449 ;;; Yet another save method.
450 (defun wl-mime-save-content (entity situation)
451   (let ((filename (read-file-name "Save to file: "
452                                   (expand-file-name
453                                    (or (mime-entity-safe-filename entity)
454                                        ".")
455                                    (or wl-mime-save-directory
456                                        wl-temporary-file-directory)))))
457     (while (file-directory-p filename)
458       (setq filename (read-file-name "Please set filename (not directory): "
459                                      filename)))
460     (if (and (file-exists-p filename)
461              (not (yes-or-no-p (format "File %s exists. Save anyway? "
462                                        filename))))
463         (message "Not saved")
464       (setq wl-mime-save-directory (file-name-directory filename))
465       (mime-write-entity-content entity filename))))
466
467 ;;; Yet another combine method.
468 (defun wl-mime-combine-message/partial-pieces (entity situation)
469   "Internal method for wl to combine message/partial messages automatically."
470   (interactive)
471   (let* ((msgdb (save-excursion
472                   (set-buffer wl-message-buffer-cur-summary-buffer)
473                   (wl-summary-buffer-msgdb)))
474          (mime-display-header-hook 'wl-highlight-headers)
475          (folder wl-message-buffer-cur-folder)
476          (id (or (cdr (assoc "id" situation)) ""))
477          (mother (current-buffer))
478          (summary-buf wl-message-buffer-cur-summary-buffer)
479          subject-id overviews
480          (root-dir (expand-file-name
481                     (concat "m-prts-" (user-login-name))
482                     temporary-file-directory))
483          full-file point)
484     (setq root-dir (concat root-dir "/" (replace-as-filename id)))
485     (setq full-file (concat root-dir "/FULL"))
486     (if (or (file-exists-p full-file)
487             (not (y-or-n-p "Merge partials? ")))
488         (with-current-buffer mother
489           (mime-store-message/partial-piece entity situation)
490           (setq wl-message-buffer-cur-summary-buffer summary-buf)
491           (make-variable-buffer-local 'mime-preview-over-to-next-method-alist)
492           (setq mime-preview-over-to-next-method-alist
493                 (cons (cons 'mime-show-message-mode 'wl-message-exit)
494                       mime-preview-over-to-next-method-alist))
495           (make-variable-buffer-local 'mime-preview-over-to-previous-method-alist)
496           (setq mime-preview-over-to-previous-method-alist
497                 (cons (cons 'mime-show-message-mode 'wl-message-exit)
498                       mime-preview-over-to-previous-method-alist)))
499       (setq subject-id
500             (eword-decode-string
501              (decode-mime-charset-string
502               (mime-entity-read-field entity 'Subject)
503               wl-summary-buffer-mime-charset)))
504       (if (string-match "[0-9\n]+" subject-id)
505           (setq subject-id (substring subject-id 0 (match-beginning 0))))
506       (setq overviews (elmo-msgdb-get-overview msgdb))
507       (catch 'tag
508         (while overviews
509           (when (string-match
510                  (regexp-quote subject-id)
511                  (elmo-msgdb-overview-entity-get-subject (car overviews)))
512             (let* ((message
513                     ;; request message at the cursor in Subject buffer.
514                     (wl-message-request-partial
515                      folder
516                      (elmo-msgdb-overview-entity-get-number
517                       (car overviews))))
518                    (situation (mime-entity-situation message))
519                    (the-id (or (cdr (assoc "id" situation)) "")))
520               (when (string= (downcase the-id)
521                              (downcase id))
522                 (with-current-buffer mother
523                   (mime-store-message/partial-piece message situation))
524                 (if (file-exists-p full-file)
525                     (throw 'tag nil)))))
526           (setq overviews (cdr overviews)))
527         (message "Not all partials found.")))))
528
529 (defun wl-mime-display-text/plain (entity situation)
530   (let ((beg (point)))
531     (mime-display-text/plain entity situation)
532     (wl-highlight-message beg (point-max) t t)))
533
534 (defun wl-mime-display-header (entity situation)
535   (let ((elmo-message-ignored-field-list
536          (if wl-message-buffer-all-header-flag
537              nil
538            wl-message-ignored-field-list))
539         (elmo-message-visible-field-list wl-message-visible-field-list)
540         (elmo-message-sorted-field-list wl-message-sort-field-list))
541     (elmo-mime-insert-header entity situation)
542     (wl-highlight-headers)))
543
544 (defun wl-mime-decrypt-application/pgp-encrypted (entity situation)
545   (let ((summary-buffer wl-message-buffer-cur-summary-buffer)
546         (original-buffer wl-message-buffer-original-buffer))
547     (mime-decrypt-application/pgp-encrypted entity situation)
548     (setq wl-message-buffer-cur-summary-buffer summary-buffer)
549     (setq wl-message-buffer-original-buffer original-buffer)))
550    
551
552 ;;; Setup methods.
553 (defun wl-mime-setup ()
554   (set-alist 'mime-preview-quitting-method-alist
555              'wl-original-message-mode 'wl-message-exit)
556   (set-alist 'mime-view-over-to-previous-method-alist
557              'wl-original-message-mode 'wl-message-exit)
558   (set-alist 'mime-view-over-to-next-method-alist
559              'wl-original-message-mode 'wl-message-exit)
560   (set-alist 'mime-preview-over-to-previous-method-alist
561              'wl-original-message-mode 'wl-message-exit)
562   (set-alist 'mime-preview-over-to-next-method-alist
563              'wl-original-message-mode 'wl-message-exit)
564   (add-hook 'wl-summary-redisplay-hook 'wl-message-delete-mime-out-buf)
565   (add-hook 'wl-message-exit-hook 'wl-message-delete-mime-out-buf)
566
567   (ctree-set-calist-strictly
568    'mime-preview-condition
569    '((type . text) (subtype . plain)
570      (body . visible)
571      (body-presentation-method . wl-mime-display-text/plain)
572      (major-mode . wl-original-message-mode)))
573
574   (ctree-set-calist-strictly
575    'mime-preview-condition
576    '((type . application)(subtype . pgp-encrypted)
577      (encoding . t)
578      (body . invisible)
579      (body-presentation-method . wl-mime-preview-application/pgp-encrypted)
580      (major-mode . wl-original-message-mode)))
581
582   (ctree-set-calist-strictly
583    'mime-acting-condition
584    '((type . message) (subtype . partial)
585      (method .  wl-mime-combine-message/partial-pieces)
586      (request-partial-message-method . wl-message-request-partial)
587      (major-mode . wl-original-message-mode)))
588
589   (ctree-set-calist-strictly
590    'mime-acting-condition
591    '((type . application) (subtype . pgp-encrypted)
592      (method . wl-mime-decrypt-application/pgp-encrypted)
593      (major-mode . wl-original-message-mode)))
594
595   (ctree-set-calist-strictly
596    'mime-acting-condition
597    '((mode . "extract")
598      (major-mode . wl-original-message-mode)
599      (method . wl-mime-save-content)))
600   (set-alist 'mime-preview-following-method-alist
601              'wl-original-message-mode
602              (function wl-message-follow-current-entity))
603   (set-alist 'mime-view-following-method-alist
604              'wl-original-message-mode
605              (function wl-message-follow-current-entity))
606   (set-alist 'mime-edit-message-inserter-alist
607              'wl-draft-mode (function wl-draft-insert-current-message))
608   (set-alist 'mime-edit-mail-inserter-alist
609              'wl-draft-mode (function wl-draft-insert-get-message))
610   (set-alist 'mime-edit-split-message-sender-alist
611              'wl-draft-mode
612              (cdr (assq 'mail-mode mime-edit-split-message-sender-alist)))
613   (set-alist 'mime-raw-representation-type-alist
614              'wl-original-message-mode 'binary)
615   ;; Sort and highlight header fields.
616   (or wl-message-ignored-field-list
617       (setq wl-message-ignored-field-list
618             mime-view-ignored-field-list))
619   (or wl-message-visible-field-list
620       (setq wl-message-visible-field-list
621             mime-view-visible-field-list))
622   (set-alist 'mime-header-presentation-method-alist
623              'wl-original-message-mode
624              'wl-mime-display-header)
625   ;; To avoid overriding wl-draft-mode-map.
626   (when (boundp 'mime-setup-signature-key-alist)
627     (unless (assq 'wl-draft-mode mime-setup-signature-key-alist)
628       (setq mime-setup-signature-key-alist
629             (cons '(wl-draft-mode . "\C-c\C-w")
630                   mime-setup-signature-key-alist)))))
631
632 (require 'product)
633 (product-provide (provide 'wl-mime) (require 'wl-version))
634
635 ;;; wl-mime.el ends here