elmo-mark branch is merged.
[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            "Sorry, following method for %s is not implemented yet."
137            mode)
138           ))
139       )))
140
141 (defalias 'wl-draft-enclose-digest-region 'mime-edit-enclose-digest-region)
142
143 (defun wl-draft-preview-message ()
144   "Preview editing message."
145   (interactive)
146   (let* (recipients-message
147          (current-point (point))
148          (config-exec-flag wl-draft-config-exec-flag)
149          (parent-folder wl-draft-parent-folder)
150          (mime-display-header-hook 'wl-highlight-headers)
151          (mime-header-encode-method-alist
152           (append
153            '((wl-draft-eword-encode-address-list
154               .  (To Cc Bcc Resent-To Resent-Cc Resent-Bcc From)))
155            (if (boundp 'mime-header-encode-method-alist)
156                (symbol-value 'mime-header-encode-method-alist))))
157          mime-view-ignored-field-list   ; all header.
158          (mime-edit-translate-buffer-hook
159           (append
160            (list
161             (function
162              (lambda ()
163                (let ((wl-draft-config-exec-flag config-exec-flag)
164                      (wl-draft-parent-folder parent-folder))
165                  (goto-char current-point)
166                  (run-hooks 'wl-draft-send-hook)
167                  (setq recipients-message
168                        (condition-case err
169                            (concat "Recipients: "
170                                    (mapconcat
171                                     'identity
172                                     (wl-draft-deduce-address-list
173                                      (current-buffer)
174                                      (point-min)
175                                      (save-excursion
176                                        (goto-char (point-min))
177                                        (re-search-forward
178                                         (concat
179                                          "^"
180                                          (regexp-quote mail-header-separator)
181                                          "$")
182                                         nil t)
183                                        (point)))
184                                     ", "))
185                          (error
186                           (kill-buffer (current-buffer))
187                           (signal (car err) (cdr err)))))))))
188            mime-edit-translate-buffer-hook)))
189     (mime-edit-preview-message)
190     (let ((buffer-read-only nil))
191       (when wl-highlight-body-too
192         (wl-highlight-body))
193       (run-hooks 'wl-draft-preview-message-hook))
194     (message "%s" recipients-message)))
195
196 (defalias 'wl-draft-caesar-region  'mule-caesar-region)
197
198 (defalias 'wl-draft-insert-message 'mime-edit-insert-message)
199
200 (defalias 'wl-draft-insert-mail 'mime-edit-insert-mail)
201
202 ;;; Message
203
204 (defun wl-message-decode-mode (outbuf inbuf)
205   (let ((mime-view-content-header-filter-hook 'wl-highlight-headers)
206         (mime-display-header-hook 'wl-highlight-headers))
207     (mime-view-mode nil nil nil inbuf outbuf)))
208
209 (defun wl-message-decode-with-all-header (outbuf inbuf)
210   (let ((mime-view-ignored-field-regexp "^:$")
211         (mime-view-content-header-filter-hook 'wl-highlight-headers)
212         (mime-display-header-hook 'wl-highlight-headers)
213         mime-view-ignored-field-list)
214     (mime-view-mode nil nil nil inbuf outbuf)))
215
216 (defun wl-message-delete-mime-out-buf ()
217   (let (mime-out-buf mime-out-win)
218     (if (setq mime-out-buf (get-buffer mime-echo-buffer-name))
219         (if (setq mime-out-win (get-buffer-window mime-out-buf))
220             (delete-window mime-out-win)))))
221
222 (defun wl-message-request-partial (folder number)
223   (elmo-set-work-buf
224    (elmo-message-fetch (wl-folder-get-elmo-folder folder)
225                        number
226                        (elmo-make-fetch-strategy 'entire)
227                        nil
228                        (current-buffer)
229                        'unread)
230    (mime-parse-buffer nil)))
231
232 (defalias 'wl-message-read              'mime-preview-scroll-up-entity)
233 (defalias 'wl-message-next-content      'mime-preview-move-to-next)
234 (defalias 'wl-message-prev-content      'mime-preview-move-to-previous)
235 (defalias 'wl-message-play-content      'mime-preview-play-current-entity)
236 (defalias 'wl-message-extract-content   'mime-preview-extract-current-entity)
237 (defalias 'wl-message-quit              'mime-preview-quit)
238 (defalias 'wl-message-button-dispatcher-internal
239   'mime-button-dispatcher)
240
241 (defsubst wl-mime-node-id-to-string (node-id)
242   (if (consp node-id)
243       (mapconcat (function (lambda (num) (format "%s" (1+ num))))
244                  (reverse node-id)
245                  ".")
246     "0"))
247
248 (defun wl-message-delete-current-part ()
249   "Delete a part under the cursor from the multipart message."
250   (interactive)
251   (save-restriction
252     (widen)
253     (let* ((entity (get-text-property (point) 'mime-view-entity))
254            (node-id (mime-entity-node-id entity))
255            (header-start (mime-buffer-entity-header-start-internal entity))
256            (body-end (mime-buffer-entity-body-end-internal entity))
257            (folder (wl-folder-get-elmo-folder wl-message-buffer-cur-folder))
258            (number wl-message-buffer-cur-number)
259            (msgid (elmo-message-field folder number 'message-id))
260            (orig-buf wl-message-buffer-original-buffer))
261       (if (eq (luna-class-name entity) 'mime-elmo-imap-entity)
262           (error "Please fetch the entire message (by typing 'C-u .') and try again"))
263       (with-current-buffer orig-buf
264         (unless (string-equal
265                  (buffer-string)
266                  (elmo-message-fetch folder number
267                                      (elmo-make-fetch-strategy 'entire)))
268           (error "Buffer content differs from actual message")))
269       (when (and (elmo-folder-writable-p folder)
270                  (buffer-live-p orig-buf)
271                  node-id
272                  (yes-or-no-p
273                   (format "Do you really want to delete part %s? "
274                           (wl-mime-node-id-to-string node-id))))
275         (when (with-temp-buffer
276                 (insert-buffer orig-buf)
277                 (delete-region header-start body-end)
278                 (goto-char header-start)
279                 (insert "Content-Type: text/plain; charset=US-ASCII\n\n")
280                 (insert "** This part has been removed by Wanderlust **\n\n")
281                 (elmo-folder-append-buffer folder))
282
283           (elmo-folder-move-messages
284            folder (list number)
285            (wl-folder-get-elmo-folder wl-trash-folder))
286           (when (and (elmo-cache-get-path msgid)
287                      (file-exists-p (elmo-cache-get-path msgid)))
288             (delete-file (elmo-cache-get-path msgid)))
289
290           (mime-preview-quit)
291           (wl-summary-delete-messages-on-buffer (list number))
292           (wl-summary-toggle-disp-msg 'off)
293           (setq wl-message-buffer nil)
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                     (buffer-file-coding-system wl-cs-autoconv))
309                 (setq status (pgg-decrypt-region beg end))
310                 (pgg-display-output-buffer beg end status))
311             (message "Cannot find pgp encrypted region")))
312       (message "Cannot find pgp encrypted region"))))
313
314 (defun wl-message-verify-pgp-nonmime ()
315   "Verify PGP signed region"
316   (interactive)
317   (require 'pgg)
318   (save-excursion
319     (beginning-of-line)
320     (if (and (or (re-search-forward "^-+END PGP SIGNATURE-+$" nil t)
321                  (re-search-backward "^-+END PGP SIGNATURE-+$" nil t))
322              (re-search-backward "^-+BEGIN PGP SIGNED MESSAGE-+$" nil t))
323         (let (status m-beg)
324           (let* ((beg (point))
325                  (situation (mime-preview-find-boundary-info))
326                  (p-end (aref situation 1))
327                  (entity (aref situation 2))
328                  (count 0))
329             (goto-char p-end)
330             (while (< beg (point))
331               (if (re-search-backward "^-+BEGIN PGP SIGNED MESSAGE-+$" nil t)
332                   (setq count (+ count 1))
333                 (debug)))
334             (with-temp-buffer
335               (set-buffer-multibyte nil)
336               (insert (mime-entity-body entity))
337               (goto-char (point-max))
338               (while (> count 0)
339                 (if (re-search-backward "^-+BEGIN PGP SIGNED MESSAGE-+$" nil t)
340                     (setq count (- count 1))
341                   (debug)))
342               (let ((r-beg (point))
343                     (r-end (re-search-forward "^-+END PGP SIGNATURE-+$" nil t)))
344                 (if r-end
345                     (setq status (pgg-verify-region r-beg r-end nil 'fetch))
346                   (debug)))))
347           (mime-show-echo-buffer)
348           (set-buffer mime-echo-buffer-name)
349           (set-window-start
350            (get-buffer-window mime-echo-buffer-name)
351            (point-max))
352           (setq m-beg (point))
353           (insert-buffer-substring
354            (if status pgg-output-buffer pgg-errors-buffer))
355           (decode-coding-region m-beg (point) wl-cs-autoconv))
356       (message "Cannot find pgp signed region"))))
357
358 ;; XXX: encrypted multipart isn't represented as multipart
359 (defun wl-mime-preview-application/pgp (parent-entity entity situation)
360   (require 'pgg)
361   (goto-char (point-max))
362   (let ((p (point))
363         raw-buf to-buf representation-type child-entity)
364     (goto-char p)
365     (save-restriction
366       (narrow-to-region p p)
367       (setq to-buf (current-buffer))
368       (with-temp-buffer
369         (setq raw-buf (current-buffer))
370         (mime-insert-entity entity)
371         (when (progn
372                 (goto-char (point-min))
373                 (re-search-forward "^-+BEGIN PGP MESSAGE-+$" nil t))
374           (pgg-decrypt-region (point-min)(point-max))
375           (delete-region (point-min) (point-max))
376           (insert-buffer pgg-output-buffer)
377           (setq representation-type 'elmo-buffer))
378         (setq child-entity (mime-parse-message
379                             (mm-expand-class-name representation-type)
380                             nil
381                             parent-entity
382                             (mime-entity-node-id-internal parent-entity)))
383         (mime-display-entity
384          child-entity
385          nil
386          `((header . visible)
387            (body . visible)
388            (entity-button . invisible))
389          to-buf)))))
390
391 (defun wl-mime-preview-application/pgp-encrypted (entity situation)
392   (let* ((entity-node-id (mime-entity-node-id entity))
393          (mother (mime-entity-parent entity))
394          (knum (car entity-node-id))
395          (onum (if (> knum 0)
396                    (1- knum)
397                  (1+ knum)))
398          (orig-entity (nth onum (mime-entity-children mother))))
399     (wl-mime-preview-application/pgp entity orig-entity situation)))
400
401 ;;; Summary
402 (defun wl-summary-burst-subr (message-entity target number)
403   ;; returns new number.
404   (let (content-type entity)
405     (setq content-type (mime-entity-content-type message-entity))
406     (cond ((eq (cdr (assq 'type content-type)) 'multipart)
407            (dolist (entity (mime-entity-children message-entity))
408              (setq number (wl-summary-burst-subr
409                            entity
410                            target
411                            number))))
412           ((and (eq (cdr (assq 'type content-type)) 'message)
413                 (eq (cdr (assq 'subtype content-type)) 'rfc822))
414            (message "Bursting...%s" (setq number (+ 1 number)))
415            (setq entity
416                  (car (mime-entity-children message-entity)))
417            (with-temp-buffer
418              (insert (mime-entity-body message-entity))
419              (elmo-folder-append-buffer target))))
420     number))
421
422 (defun wl-summary-burst (&optional arg)
423   "De-capsulate embedded messages in MIME format.
424 With ARG, ask destination folder."
425   (interactive "P")
426   (let ((raw-buf (wl-summary-get-original-buffer))
427         (view-buf wl-message-buffer)
428         children message-entity content-type target-name target)
429     (save-excursion
430       (setq target wl-summary-buffer-elmo-folder)
431       (when (or arg (not (elmo-folder-writable-p target)))
432         (setq target-name (wl-summary-read-folder wl-default-folder "to extract to"))
433         (setq target (wl-folder-get-elmo-folder target-name)))
434       (wl-summary-set-message-buffer-or-redisplay)
435       (with-current-buffer view-buf
436         (setq message-entity (get-text-property (point-min) 'mime-view-entity)))
437       (when message-entity
438         (message "Bursting...")
439         (with-current-buffer raw-buf
440           (wl-summary-burst-subr message-entity target 0))
441         (message "Bursting...done"))
442       (if (elmo-folder-plugged-p target)
443           (elmo-folder-check target)))
444     (when (or (not target-name)
445               (string= wl-summary-buffer-folder-name target-name))
446       (save-excursion (wl-summary-sync-update)))))
447
448 ;; internal variable.
449 (defvar wl-mime-save-directory nil "Last saved directory.")
450 ;;; Yet another save method.
451 (defun wl-mime-save-content (entity situation)
452   (let ((filename (read-file-name "Save to file: "
453                                   (expand-file-name
454                                    (or (mime-entity-safe-filename entity)
455                                        ".")
456                                    (or wl-mime-save-directory
457                                        wl-temporary-file-directory)))))
458     (while (file-directory-p filename)
459       (setq filename (read-file-name "Please set filename (not directory): "
460                                      filename)))
461     (if (and (file-exists-p filename)
462              (not (yes-or-no-p (format "File %s exists. Save anyway? "
463                                        filename))))
464         (message "Not saved")
465       (setq wl-mime-save-directory (file-name-directory filename))
466       (mime-write-entity-content entity filename))))
467
468 ;;; Yet another combine method.
469 (defun wl-mime-combine-message/partial-pieces (entity situation)
470   "Internal method for wl to combine message/partial messages automatically."
471   (interactive)
472   (let* ((folder (save-excursion
473                    (set-buffer wl-message-buffer-cur-summary-buffer)
474                    wl-summary-buffer-elmo-folder))
475          (mime-display-header-hook 'wl-highlight-headers)
476          (folder wl-message-buffer-cur-folder)
477          (id (or (cdr (assoc "id" situation)) ""))
478          (mother (current-buffer))
479          (summary-buf wl-message-buffer-cur-summary-buffer)
480          subject-id overviews
481          (root-dir (expand-file-name
482                     (concat "m-prts-" (user-login-name))
483                     temporary-file-directory))
484          full-file point)
485     (setq root-dir (concat root-dir "/" (replace-as-filename id)))
486     (setq full-file (concat root-dir "/FULL"))
487     (if (or (file-exists-p full-file)
488             (not (y-or-n-p "Merge partials? ")))
489         (with-current-buffer mother
490           (mime-store-message/partial-piece entity situation)
491           (setq wl-message-buffer-cur-summary-buffer summary-buf)
492           (make-variable-buffer-local 'mime-preview-over-to-next-method-alist)
493           (setq mime-preview-over-to-next-method-alist
494                 (cons (cons 'mime-show-message-mode 'wl-message-exit)
495                       mime-preview-over-to-next-method-alist))
496           (make-variable-buffer-local 'mime-preview-over-to-previous-method-alist)
497           (setq mime-preview-over-to-previous-method-alist
498                 (cons (cons 'mime-show-message-mode 'wl-message-exit)
499                       mime-preview-over-to-previous-method-alist)))
500       (setq subject-id
501             (eword-decode-string
502              (decode-mime-charset-string
503               (mime-entity-read-field entity 'Subject)
504               wl-summary-buffer-mime-charset)))
505       (if (string-match "[0-9\n]+" subject-id)
506           (setq subject-id (substring subject-id 0 (match-beginning 0))))
507       (catch 'tag
508         (elmo-folder-do-each-message-entity (entity folder)
509           (when (string-match
510                  (regexp-quote subject-id)
511                  (elmo-message-entity-field entity 'subject))
512             (let* ((message
513                     ;; request message at the cursor in Subject buffer.
514                     (wl-message-request-partial
515                      folder
516                      (elmo-message-entity-number entity)))
517                    (situation (mime-entity-situation message))
518                    (the-id (or (cdr (assoc "id" situation)) "")))
519               (when (string= (downcase the-id)
520                              (downcase id))
521                 (with-current-buffer mother
522                   (mime-store-message/partial-piece message situation))
523                 (if (file-exists-p full-file)
524                     (throw 'tag nil))))))
525         (message "Not all partials found.")))))
526
527 (defun wl-mime-display-text/plain (entity situation)
528   (let ((beg (point)))
529     (mime-display-text/plain entity situation)
530     (wl-highlight-message beg (point-max) t t)))
531
532 (defun wl-mime-display-header (entity situation)
533   (let ((elmo-message-ignored-field-list
534          (if wl-message-buffer-all-header-flag
535              nil
536            wl-message-ignored-field-list))
537         (elmo-message-visible-field-list wl-message-visible-field-list)
538         (elmo-message-sorted-field-list wl-message-sort-field-list))
539     (elmo-mime-insert-header entity situation)
540     (wl-highlight-headers)))
541
542 (defun wl-mime-decrypt-application/pgp-encrypted (entity situation)
543   (let ((summary-buffer wl-message-buffer-cur-summary-buffer)
544         (original-buffer wl-message-buffer-original-buffer))
545     (mime-decrypt-application/pgp-encrypted entity situation)
546     (setq wl-message-buffer-cur-summary-buffer summary-buffer)
547     (setq wl-message-buffer-original-buffer original-buffer)))
548    
549
550 ;;; Setup methods.
551 (defun wl-mime-setup ()
552   (set-alist 'mime-preview-quitting-method-alist
553              'wl-original-message-mode 'wl-message-exit)
554   (set-alist 'mime-view-over-to-previous-method-alist
555              'wl-original-message-mode 'wl-message-exit)
556   (set-alist 'mime-view-over-to-next-method-alist
557              'wl-original-message-mode 'wl-message-exit)
558   (set-alist 'mime-preview-over-to-previous-method-alist
559              'wl-original-message-mode 'wl-message-exit)
560   (set-alist 'mime-preview-over-to-next-method-alist
561              'wl-original-message-mode 'wl-message-exit)
562   (add-hook 'wl-summary-redisplay-hook 'wl-message-delete-mime-out-buf)
563   (add-hook 'wl-message-exit-hook 'wl-message-delete-mime-out-buf)
564
565   (ctree-set-calist-strictly
566    'mime-preview-condition
567    '((type . text) (subtype . plain)
568      (body . visible)
569      (body-presentation-method . wl-mime-display-text/plain)
570      (major-mode . wl-original-message-mode)))
571
572   (ctree-set-calist-strictly
573    'mime-preview-condition
574    '((type . application)(subtype . pgp-encrypted)
575      (encoding . t)
576      (body . invisible)
577      (body-presentation-method . wl-mime-preview-application/pgp-encrypted)
578      (major-mode . wl-original-message-mode)))
579
580   (ctree-set-calist-strictly
581    'mime-acting-condition
582    '((type . message) (subtype . partial)
583      (method .  wl-mime-combine-message/partial-pieces)
584      (request-partial-message-method . wl-message-request-partial)
585      (major-mode . wl-original-message-mode)))
586
587   (ctree-set-calist-strictly
588    'mime-acting-condition
589    '((type . application) (subtype . pgp-encrypted)
590      (method . wl-mime-decrypt-application/pgp-encrypted)
591      (major-mode . wl-original-message-mode)))
592
593   (ctree-set-calist-strictly
594    'mime-acting-condition
595    '((mode . "extract")
596      (major-mode . wl-original-message-mode)
597      (method . wl-mime-save-content)))
598   (set-alist 'mime-preview-following-method-alist
599              'wl-original-message-mode
600              (function wl-message-follow-current-entity))
601   (set-alist 'mime-view-following-method-alist
602              'wl-original-message-mode
603              (function wl-message-follow-current-entity))
604   (set-alist 'mime-edit-message-inserter-alist
605              'wl-draft-mode (function wl-draft-insert-current-message))
606   (set-alist 'mime-edit-mail-inserter-alist
607              'wl-draft-mode (function wl-draft-insert-get-message))
608   (set-alist 'mime-edit-split-message-sender-alist
609              'wl-draft-mode
610              (cdr (assq 'mail-mode mime-edit-split-message-sender-alist)))
611   (set-alist 'mime-raw-representation-type-alist
612              'wl-original-message-mode 'binary)
613   ;; Sort and highlight header fields.
614   (or wl-message-ignored-field-list
615       (setq wl-message-ignored-field-list
616             mime-view-ignored-field-list))
617   (or wl-message-visible-field-list
618       (setq wl-message-visible-field-list
619             mime-view-visible-field-list))
620   (set-alist 'mime-header-presentation-method-alist
621              'wl-original-message-mode
622              'wl-mime-display-header)
623   ;; To avoid overriding wl-draft-mode-map.
624   (when (boundp 'mime-setup-signature-key-alist)
625     (unless (assq 'wl-draft-mode mime-setup-signature-key-alist)
626       (setq mime-setup-signature-key-alist
627             (cons '(wl-draft-mode . "\C-c\C-w")
628                   mime-setup-signature-key-alist)))))
629
630 (require 'product)
631 (product-provide (provide 'wl-mime) (require 'wl-version))
632
633 ;;; wl-mime.el ends here