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