1 ;;; wl-mime.el --- SEMI implementations of MIME processing on Wanderlust.
3 ;; Copyright (C) 1998,1999,2000 Yuuichi Teranishi <teranisi@gohome.org>
5 ;; Author: Yuuichi Teranishi <teranisi@gohome.org>
6 ;; Keywords: mail, net news
8 ;; This file is part of Wanderlust (Yet Another Message Interface on Emacsen).
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)
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.
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.
35 (eval-when-compile (require 'mmbuffer
))
40 (eval-when-compile (require 'cl
))
44 (defalias 'wl-draft-editor-mode
'mime-edit-mode
)
46 (defalias 'wl-draft-decode-message-in-buffer
47 'mime-edit-decode-message-in-buffer
)
49 (defun wl-draft-yank-current-message-entity ()
50 "Yank currently displayed message entity.
51 By setting following-method as yank-content.
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\)
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)))
66 (set-buffer message-buffer
)
71 (wl-mime-preview-follow-current-region))
72 ((not (wl-message-mime-analysis-p
73 (wl-message-buffer-display-type)))
74 (wl-mime-preview-follow-no-mime
75 (wl-message-buffer-display-type)))
77 (mime-preview-follow-current-entity)))))
78 (error "No message."))))
80 ;; modified mime-preview-follow-current-entity from mime-view.el
81 (defun wl-mime-preview-follow-no-mime (display-type)
82 "Write follow message to current message, without mime.
83 It calls following-method selected from variable
84 `mime-preview-following-method-alist'."
86 (let* ((mode (mime-preview-original-major-mode 'recursive
))
87 (new-name (format "%s-no-mime" (buffer-name)))
89 (entity (get-text-property (point-min) 'elmo-as-is-entity
))
90 (the-buf (current-buffer))
93 (goto-char (point-min))
95 beg
(re-search-forward "^$" nil t
)
98 (set-buffer (setq new-buf
(get-buffer-create new-name
)))
100 (insert-buffer-substring the-buf beg end
)
101 (goto-char (point-min))
102 ;; Insert all headers.
103 (let ((elmo-mime-display-header-analysis
104 (wl-message-mime-analysis-p display-type
'header
)))
105 (elmo-mime-insert-sorted-header entity
))
106 (let ((f (cdr (assq mode mime-preview-following-method-alist
))))
110 "Sorry, following method for %s is not implemented yet."
113 ;; modified mime-preview-follow-current-entity from mime-view.el
114 (defun wl-mime-preview-follow-current-region ()
115 "Write follow message to current region.
116 It calls following-method selected from variable
117 `mime-preview-following-method-alist'."
119 (let ((r-beg (region-beginning))
121 (entity (get-text-property (point-min)
123 (let* ((mode (mime-preview-original-major-mode 'recursive
))
125 (format "%s-active-region" (buffer-name)))
127 (the-buf (current-buffer))
130 (set-buffer (setq new-buf
(get-buffer-create new-name
)))
133 (insert-buffer-substring the-buf r-beg r-end
)
134 (goto-char (point-min))
135 (let ((current-entity
137 (eq (mime-entity-media-type entity
) 'message
)
138 (eq (mime-entity-media-subtype entity
) 'rfc822
))
139 (car (mime-entity-children entity
))
141 (while (and current-entity
142 (if (and (eq (mime-entity-media-type
143 current-entity
) 'message
)
144 (eq (mime-entity-media-subtype
145 current-entity
) 'rfc822
))
147 (mime-insert-header current-entity fields
)
149 (setq fields
(std11-collect-field-names)
150 current-entity
(mime-entity-parent current-entity
))))
151 (let ((rest mime-view-following-required-fields-list
)
154 (setq field-name
(car rest
))
155 (or (std11-field-body field-name
)
159 (let ((entity (when mime-mother-buffer
160 (set-buffer mime-mother-buffer
)
161 (get-text-property (point)
162 'mime-view-entity
))))
164 (null (setq ret
(mime-entity-fetch-field
165 entity field-name
))))
166 (setq entity
(mime-entity-parent entity
)))))
168 (insert (concat field-name
": " ret
"\n")))))
169 (setq rest
(cdr rest
)))))
170 (let ((f (cdr (assq mode mime-preview-following-method-alist
))))
174 "Sorry, following method for %s is not implemented yet."
177 (defalias 'wl-draft-enclose-digest-region
'mime-edit-enclose-digest-region
)
179 (defun wl-draft-preview-attributes-list ()
180 (if (listp (car wl-draft-preview-attributes-list
))
182 (nconc (and (wl-message-mail-p)
184 (cdr (assq 'mail wl-draft-preview-attributes-list
))))
185 (and (wl-message-news-p)
187 (cdr (assq 'news wl-draft-preview-attributes-list
))))))
188 wl-draft-preview-attributes-list
))
190 (defun wl-draft-show-attributes-buffer (attribute-values)
191 (let* ((cur-win (selected-window))
193 (- (window-height cur-win
)
195 (- (window-height cur-win
)
198 (1+ wl-draft-preview-attributes-buffer-lines
))))))
199 (split-window cur-win
(if (> size
0) size window-min-height
))
200 (select-window (next-window))
201 (let ((pop-up-windows nil
))
202 (switch-to-buffer (get-buffer-create
203 wl-draft-preview-attributes-buffer-name
)))
205 (get-buffer wl-draft-preview-attributes-buffer-name
)
206 (setq buffer-read-only t
)
207 (let (buffer-read-only)
209 (dolist (pair attribute-values
)
210 (insert (capitalize (symbol-name (car pair
))) ": "
211 (format "%s" (or (cdr pair
) ""))
213 (goto-char (point-min))
214 (wl-highlight-headers)))
215 (select-window cur-win
)))
217 (defun wl-draft-hide-attributes-buffer ()
219 (when (setq window
(get-buffer-window
220 wl-draft-preview-attributes-buffer-name
))
221 (select-window window
)
223 (when (setq buffer
(get-buffer wl-draft-preview-attributes-buffer-name
))
224 (kill-buffer buffer
))))
226 (defun wl-draft-attribute-recipients ()
227 (let (wl-draft-remove-group-list-contents)
231 (wl-draft-deduce-address-list
235 (goto-char (point-min))
239 (regexp-quote mail-header-separator
)
243 (wl-draft-parse-mailbox-list wl-draft-mime-bcc-field-name
))
246 (defun wl-draft-attribute-envelope-from ()
248 (wl-address-header-extract-address wl-from
)))
250 (defun wl-draft-attribute-smtp-posting-server ()
251 (or wl-smtp-posting-server
252 (progn (require 'smtp
) smtp-server
)
255 (defun wl-draft-attribute-smtp-posting-port ()
256 (or wl-smtp-posting-port
257 (progn (require 'smtp
) smtp-service
)))
259 (defun wl-draft-attribute-newsgroups ()
260 (std11-field-body "Newsgroups"))
262 (defun wl-draft-nntp-attribute (attribute &optional alternatives
)
263 (let ((config (cdr (elmo-string-matched-assoc
264 (std11-field-body "newsgroups")
265 wl-nntp-posting-config-alist
)))
267 (when (stringp config
)
268 (setq config
(list (cons 'server config
))))
269 (if (setq entry
(assq attribute config
))
274 (if (setq value
(symbol-value (car alternatives
)))
275 (setq alternatives nil
)
276 (setq alternatives
(cdr alternatives
))))
279 (defun wl-draft-attribute-nntp-posting-server ()
280 (wl-draft-nntp-attribute
282 '(wl-nntp-posting-server elmo-nntp-default-server
)))
284 (defun wl-draft-attribute-nntp-posting-port ()
285 (wl-draft-nntp-attribute
287 '(wl-nntp-posting-port elmo-nntp-default-port
)))
289 (defun wl-draft-attribute-value (attr)
290 (let ((name (symbol-name attr
))
292 (cond ((and (setq fsymbol
(intern-soft
293 (format "wl-draft-attribute-%s" name
)))
296 ((and (setq symbol
(intern-soft (format "wl-%s" name
)))
298 (symbol-value symbol
))
300 (symbol-value attr
)))))
302 (defun wl-mime-quit-preview ()
303 "Quitting method for mime-view."
304 (let* ((temp (and (boundp 'mime-edit-temp-message-buffer
) ;; for SEMI <= 1.14.6
305 mime-edit-temp-message-buffer
))
306 (window (selected-window))
308 (mime-preview-kill-buffer)
310 (setq buf mime-edit-buffer
)
312 (select-window window
)
313 (switch-to-buffer buf
)))
315 (defun wl-draft-preview-message ()
316 "Preview editing message."
318 (let* (attribute-values
319 (orig-buffer (current-buffer))
320 (current-point (point))
321 (config-exec-flag wl-draft-config-exec-flag
)
322 (parent-folder wl-draft-parent-folder
)
323 (mime-display-header-hook 'wl-highlight-headers
)
324 (mime-header-encode-method-alist
326 '((wl-draft-eword-encode-address-list
327 .
(To Cc Bcc Resent-To Resent-Cc Resent-Bcc From
)))
328 (if (boundp 'mime-header-encode-method-alist
)
329 (symbol-value 'mime-header-encode-method-alist
))))
330 mime-view-ignored-field-list
; all header.
331 (mime-edit-translate-buffer-hook
334 (let ((wl-draft-config-exec-flag config-exec-flag
)
335 (wl-draft-parent-folder parent-folder
)
336 (copy-buffer (current-buffer)))
337 (wl-copy-local-variables
340 (with-current-buffer orig-buffer
341 (append wl-draft-config-variables
342 (wl-draft-clone-local-variables))))
343 (goto-char current-point
)
344 (run-hooks 'wl-draft-send-hook
)
346 (setq attribute-values
349 (cons attr
(wl-draft-attribute-value attr
)))
350 (if wl-draft-preview-attributes
351 (wl-draft-preview-attributes-list)
354 (kill-buffer (current-buffer))
355 (signal (car err
) (cdr err
))))))
356 mime-edit-translate-buffer-hook
)))
357 (mime-edit-preview-message)
358 (make-local-variable 'mime-preview-quitting-method-alist
)
359 (setq mime-preview-quitting-method-alist
360 '((mime-temp-message-mode . wl-mime-quit-preview
)))
361 (let ((buffer-read-only nil
))
362 (when wl-highlight-body-too
364 (run-hooks 'wl-draft-preview-message-hook
))
365 (make-local-hook 'kill-buffer-hook
)
366 (add-hook 'kill-buffer-hook
#'wl-draft-hide-attributes-buffer nil t
)
367 (if wl-draft-preview-attributes
368 (ignore-errors ; in case when the window is too small
369 (wl-draft-show-attributes-buffer attribute-values
))
370 (message (concat "Recipients: "
371 (cdr (assq 'recipients attribute-values
)))))))
373 (defalias 'wl-draft-caesar-region
'mule-caesar-region
)
375 (defalias 'wl-draft-insert-message
'mime-edit-insert-message
)
377 (defalias 'wl-draft-insert-mail
'mime-edit-insert-mail
)
381 (defun wl-message-decode-mode (outbuf inbuf
)
382 (let ((mime-view-content-header-filter-hook 'wl-highlight-headers
)
383 (mime-display-header-hook 'wl-highlight-headers
))
384 (mime-view-mode nil nil nil inbuf outbuf
)))
386 (defun wl-message-decode-with-all-header (outbuf inbuf
)
387 (let ((mime-view-ignored-field-regexp "^:$")
388 (mime-view-content-header-filter-hook 'wl-highlight-headers
)
389 (mime-display-header-hook 'wl-highlight-headers
)
390 mime-view-ignored-field-list
)
391 (mime-view-mode nil nil nil inbuf outbuf
)))
393 (defun wl-message-delete-popup-windows ()
394 (dolist (buffer wl-message-popup-buffers
)
395 (when (or (stringp buffer
)
396 (and (symbolp buffer
)
398 (setq buffer
(symbol-value buffer
))))
399 (let ((window (get-buffer-window buffer
)))
401 (delete-window window
))))))
403 (defun wl-message-request-partial (folder number
)
405 (elmo-message-fetch (wl-folder-get-elmo-folder folder
)
407 (elmo-make-fetch-strategy 'entire
)
409 (mime-parse-buffer nil
)))
411 (defalias 'wl-message-read
'mime-preview-scroll-up-entity
)
412 (defalias 'wl-message-next-content
'mime-preview-move-to-next
)
413 (defalias 'wl-message-prev-content
'mime-preview-move-to-previous
)
414 (defalias 'wl-message-play-content
'mime-preview-play-current-entity
)
415 (defalias 'wl-message-extract-content
'mime-preview-extract-current-entity
)
416 (defalias 'wl-message-quit
'mime-preview-quit
)
417 (defalias 'wl-message-button-dispatcher-internal
418 'mime-button-dispatcher
)
420 (defsubst wl-mime-node-id-to-string
(node-id)
422 (mapconcat (function (lambda (num) (format "%s" (1+ num
))))
427 (defun wl-message-delete-current-part ()
428 "Delete a part under the cursor from the multipart message."
432 (let* ((entity (get-text-property (point) 'mime-view-entity
))
433 (node-id (mime-entity-node-id entity
))
434 (filename (mime-entity-safe-filename entity
))
435 (header-start (mime-buffer-entity-header-start-internal entity
))
436 (body-end (mime-buffer-entity-body-end-internal entity
))
437 (folder (wl-folder-get-elmo-folder wl-message-buffer-cur-folder
))
438 (number wl-message-buffer-cur-number
)
439 (msgid (elmo-message-field folder number
'message-id
))
440 (orig-buf wl-message-buffer-original-buffer
))
441 (if (eq (luna-class-name entity
) 'mime-elmo-imap-entity
)
442 (error "Please fetch the entire message (by typing 'C-u .') and try again"))
443 (with-current-buffer orig-buf
444 (unless (string-equal
446 (elmo-message-fetch-string
448 (elmo-make-fetch-strategy 'entire
)))
449 (error "Buffer content differs from actual message")))
450 (when (and (elmo-folder-writable-p folder
)
451 (buffer-live-p orig-buf
)
454 (format "Do you really want to delete part %s? "
455 (wl-mime-node-id-to-string node-id
))))
456 (when (with-temp-buffer
457 (insert-buffer-substring orig-buf
)
458 (delete-region header-start body-end
)
459 (goto-char header-start
)
460 (insert "Content-Type: text/plain; charset=US-ASCII\n")
463 "Content-Disposition:"
464 (mime-encode-field-body
467 (concat " inline; filename=" (std11-wrap-as-quoted-string filename
))))
468 "Content-Disposition")
471 (insert "** This part has been removed by Wanderlust **\n\n")
472 (elmo-folder-append-buffer folder
))
474 (elmo-folder-move-messages
476 (wl-folder-get-elmo-folder wl-trash-folder
))
477 (when (and (elmo-cache-get-path msgid
)
478 (file-exists-p (elmo-cache-get-path msgid
)))
479 (delete-file (elmo-cache-get-path msgid
)))
482 (wl-summary-delete-messages-on-buffer (list number
))
483 (wl-summary-toggle-disp-msg 'off
)
484 (setq wl-message-buffer nil
)
485 (wl-summary-sync nil
"update"))))))
489 (defmacro wl-define-dummy-functions
(&rest symbols
)
490 `(dolist (symbol (quote ,symbols
))
491 (defalias symbol
'ignore
))))
494 ;; split eval-when-compile form for avoid error on `make compile-strict'
499 (wl-define-dummy-functions epg-make-context
502 epg-context-set-progress-callback
503 epg-context-result-for
504 epg-verify-result-to-string
509 (wl-define-dummy-functions pgg-decrypt-region
511 pgg-display-output-buffer
))))
513 (defun wl-epg-progress-callback (context what char current total reporter
)
514 (let ((label (elmo-progress-counter-label reporter
)))
516 (elmo-progress-notify label
:set current
:total total
))))
518 (defun wl-mime-pgp-decrypt-region-with-epg (beg end
&optional no-decode
)
520 (let ((context (epg-make-context)))
521 (elmo-with-progress-display (epg-decript nil reporter
)
523 (epg-context-set-progress-callback context
524 (cons #'wl-epg-progress-callback
527 (decode-coding-string
530 (buffer-substring beg end
))
531 (if no-decode
'raw-text wl-cs-autoconv
))
532 (delete-region beg end
)))))
533 last-coding-system-used
)
535 (defun wl-mime-pgp-verify-region-with-epg (beg end
&optional coding-system
)
537 (let ((context (epg-make-context)))
538 (elmo-with-progress-display (epg-verify nil reporter
)
540 (epg-context-set-progress-callback context
541 (cons #'wl-epg-progress-callback
545 (encode-coding-string
546 (buffer-substring beg end
)
548 (coding-system-change-eol-conversion coding-system
'dos
)
550 (when (epg-context-result-for context
'verify
)
551 (epa-display-info (epg-verify-result-to-string
552 (epg-context-result-for context
'verify
))))))
554 (defun wl-mime-pgp-decrypt-region-with-pgg (beg end
&optional no-decode
)
556 (let ((buffer-file-coding-system wl-cs-autoconv
)
558 (setq status
(pgg-decrypt-region beg end
))
561 (delete-region beg end
)
562 (insert-buffer-substring pgg-output-buffer
))
563 (pgg-display-output-buffer beg end status
))
565 (error "Decryption is failed"))
566 last-coding-system-used
))
568 (defun wl-mime-pgp-verify-region-with-pgg (beg end
&optional coding-system
)
570 (let ((message-buffer (current-buffer))
573 (insert-buffer-substring message-buffer beg end
)
575 (encode-coding-region (point-min) (point-max) coding-system
))
576 (setq success
(pgg-verify-region (point-min) (point-max) nil
'fetch
)))
577 (mime-show-echo-buffer)
578 (set-buffer mime-echo-buffer-name
)
580 (get-buffer-window mime-echo-buffer-name
)
582 (insert-buffer-substring
585 pgg-errors-buffer
))))
587 (defsubst wl-mime-pgp-decrypt-region
(beg end
&optional no-decode
)
588 (case wl-use-pgp-module
590 (wl-mime-pgp-decrypt-region-with-epg beg end no-decode
))
592 (wl-mime-pgp-decrypt-region-with-pgg beg end no-decode
))
594 (error "Don't support PGP decryption"))))
596 (defsubst wl-mime-pgp-verify-region
(beg end
&optional coding-system
)
597 (case wl-use-pgp-module
599 (wl-mime-pgp-verify-region-with-epg beg end coding-system
))
601 (wl-mime-pgp-verify-region-with-pgg beg end coding-system
))
603 (error "Don't support PGP decryption"))))
605 (defun wl-message-decrypt-pgp-nonmime ()
606 "Decrypt PGP encrypted region"
610 (let ((region (wl-find-region "^-+BEGIN PGP MESSAGE-+$"
611 "^-+END PGP MESSAGE-+$"))
612 (inhibit-read-only t
)
615 (error "Cannot find PGP encrypted region"))
617 (let ((props (text-properties-at (car region
))))
618 (narrow-to-region (car region
) (cdr region
))
619 (when (setq coding-system
620 (wl-mime-pgp-decrypt-region (point-min) (point-max)))
621 (setq props
(plist-put props
622 'wl-mime-decoded-coding-system
624 (set-text-properties (point-min) (point-max) props
))))))
626 (defun wl-message-verify-pgp-nonmime (&optional arg
)
627 "Verify PGP signed region.
628 With ARG, ask coding system and encode the region with it before verifying."
632 (let ((region (wl-find-region "^-+BEGIN PGP SIGNED MESSAGE-+$"
633 "^-+END PGP SIGNATURE-+$"))
636 (error "Cannot find PGP signed region"))
638 (or (get-text-property (car region
) 'wl-mime-decoded-coding-system
)
639 (let* ((situation (mime-preview-find-boundary-info))
640 (entity (aref situation
2)))
641 (mime-charset-to-coding-system
642 (mime-content-type-parameter
643 (mime-entity-content-type entity
)
645 buffer-file-coding-system
))
647 (setq coding-system
(read-coding-system
648 (format "Coding system (%S): " coding-system
)
650 (wl-mime-pgp-verify-region (car region
) (cdr region
) coding-system
))))
652 ;; XXX: encrypted multipart isn't represented as multipart
653 (defun wl-mime-preview-application/pgp
(parent-entity entity situation
)
654 (goto-char (point-max))
656 raw-buf to-buf representation-type child-entity
)
659 (narrow-to-region p p
)
660 (setq to-buf
(current-buffer))
662 (setq raw-buf
(current-buffer))
663 (mime-insert-entity entity
)
665 (goto-char (point-min))
666 (re-search-forward "^-+BEGIN PGP MESSAGE-+$" nil t
))
667 (wl-mime-pgp-decrypt-region (point-min) (point-max) 'no-decode
)
668 (setq representation-type
'elmo-buffer
))
669 (setq child-entity
(mime-parse-message
670 (mm-expand-class-name representation-type
)
673 (mime-entity-node-id-internal parent-entity
)))
679 (entity-button . invisible
))
682 (defun wl-mime-preview-application/pgp-encrypted
(entity situation
)
683 (let* ((entity-node-id (mime-entity-node-id entity
))
684 (mother (mime-entity-parent entity
))
685 (knum (car entity-node-id
))
689 (orig-entity (nth onum
(mime-entity-children mother
))))
690 (wl-mime-preview-application/pgp entity orig-entity situation
)))
693 (defun wl-summary-burst-subr (message-entity target number
)
694 ;; returns new number.
695 (let (content-type entity
)
696 (setq content-type
(mime-entity-content-type message-entity
))
697 (cond ((eq (cdr (assq 'type content-type
)) 'multipart
)
698 (dolist (entity (mime-entity-children message-entity
))
699 (setq number
(wl-summary-burst-subr
703 ((and (eq (cdr (assq 'type content-type
)) 'message
)
704 (eq (cdr (assq 'subtype content-type
)) 'rfc822
))
705 (message "Bursting...%s" (setq number
(+ 1 number
)))
707 (car (mime-entity-children message-entity
)))
709 (set-buffer-multibyte nil
)
710 (insert (mime-entity-body message-entity
))
711 (elmo-folder-append-buffer target
))))
714 (defun wl-summary-burst (&optional arg
)
715 "De-capsulate embedded messages in MIME format.
716 With ARG, ask destination folder."
718 (let ((raw-buf (wl-summary-get-original-buffer))
719 (view-buf wl-message-buffer
)
720 message-entity target
)
722 (when (and (null arg
)
723 (elmo-folder-writable-p wl-summary-buffer-elmo-folder
))
724 (setq target wl-summary-buffer-elmo-folder
))
726 (let ((name (wl-summary-read-folder wl-default-folder
728 (setq target
(wl-folder-get-elmo-folder name
))
729 (unless (elmo-folder-writable-p target
)
730 (message "%s is not writable" name
)
733 (wl-summary-set-message-buffer-or-redisplay)
734 (with-current-buffer view-buf
736 (get-text-property (point-min) 'mime-view-entity
)))
738 (message "Bursting...")
739 (with-current-buffer raw-buf
740 (wl-summary-burst-subr message-entity target
0))
741 (message "Bursting...done"))
742 (if (elmo-folder-plugged-p target
)
743 (elmo-folder-check target
)))
745 (string= wl-summary-buffer-folder-name
746 (elmo-folder-name-internal target
)))
747 (save-excursion (wl-summary-sync-update)))))
749 ;; internal variable.
750 (defvar wl-mime-save-directory nil
"Last saved directory.")
751 ;;; Yet another save method.
752 (defun wl-mime-save-content (entity situation
)
753 (let ((filename (expand-file-name
754 (read-file-name "Save to file: "
756 (or (mime-entity-safe-filename entity
)
758 (or wl-mime-save-directory
759 wl-temporary-file-directory
))))))
760 (while (file-directory-p filename
)
761 (setq filename
(read-file-name "Please set filename (not directory): "
763 (if (and (file-exists-p filename
)
764 (not (yes-or-no-p (format "File %s exists. Save anyway? "
766 (message "Not saved")
767 (setq wl-mime-save-directory
(file-name-directory filename
))
768 (mime-write-entity-content entity filename
))))
770 (defun wl-summary-extract-attachments-1 (message-entity directory number
)
771 ;; returns new number.
772 (let (children filename
)
774 ((setq children
(mime-entity-children message-entity
))
775 (dolist (entity children
)
777 (wl-summary-extract-attachments-1 entity directory number
))))
778 ((and (eq (mime-content-disposition-type
779 (mime-entity-content-disposition message-entity
))
781 (setq filename
(mime-entity-safe-filename message-entity
)))
782 (let ((full (expand-file-name filename directory
)))
783 (when (or (not (file-exists-p full
))
785 (format "File %s exists. Save anyway? " filename
)))
786 (message "Extracting...%s" (setq number
(+ 1 number
)))
787 (mime-write-entity-content message-entity full
)))))
790 (defun wl-summary-extract-attachments (directory)
791 "Extract attachment parts in MIME format into the DIRECTORY."
793 (let* ((default (or wl-mime-save-directory
794 wl-temporary-file-directory
))
795 (directory (read-directory-name "Extract to " default default t
)))
796 (list (if (> (length directory
) 0) directory default
))))
797 (unless (and (file-writable-p directory
)
798 (file-directory-p directory
))
799 (error "%s is not writable" directory
))
801 (wl-summary-set-message-buffer-or-redisplay)
802 (let ((entity (get-text-property (point-min) 'mime-view-entity
)))
804 (message "Extracting...")
805 (wl-summary-extract-attachments-1 entity directory
0)
806 (message "Extracting...done")))))
808 ;;; Yet another combine method.
809 (defun wl-mime-combine-message/partial-pieces
(entity situation
)
810 "Internal method for wl to combine message/partial messages automatically."
812 (let* ((folder (with-current-buffer wl-message-buffer-cur-summary-buffer
813 wl-summary-buffer-elmo-folder
))
814 (mime-display-header-hook 'wl-highlight-headers
)
815 (id (or (cdr (assoc "id" situation
)) ""))
816 (mother (current-buffer))
817 (summary-buf wl-message-buffer-cur-summary-buffer
)
819 (root-dir (expand-file-name
820 (concat "m-prts-" (user-login-name))
821 temporary-file-directory
))
823 (setq root-dir
(concat root-dir
"/" (replace-as-filename id
)))
824 (setq full-file
(concat root-dir
"/FULL"))
825 (if (or (file-exists-p full-file
)
826 (not (y-or-n-p "Merge partials? ")))
827 (with-current-buffer mother
828 (mime-store-message/partial-piece entity situation
)
829 (setq wl-message-buffer-cur-summary-buffer summary-buf
)
830 (make-local-variable 'mime-preview-over-to-next-method-alist
)
831 (setq mime-preview-over-to-next-method-alist
832 (cons (cons 'mime-show-message-mode
'wl-message-exit
)
833 mime-preview-over-to-next-method-alist
))
834 (make-local-variable 'mime-preview-over-to-previous-method-alist
)
835 (setq mime-preview-over-to-previous-method-alist
836 (cons (cons 'mime-show-message-mode
'wl-message-exit
)
837 mime-preview-over-to-previous-method-alist
)))
840 (decode-mime-charset-string
841 (mime-entity-read-field entity
'Subject
)
842 wl-summary-buffer-mime-charset
)))
843 (if (string-match "[0-9\n]+" subject-id
)
844 (setq subject-id
(substring subject-id
0 (match-beginning 0))))
846 (elmo-folder-do-each-message-entity (entity folder
)
848 (regexp-quote subject-id
)
849 (elmo-message-entity-field entity
'subject
))
851 ;; request message at the cursor in Subject buffer.
852 (wl-message-request-partial
853 (elmo-folder-name-internal folder
)
854 (elmo-message-entity-number entity
)))
855 (situation (mime-entity-situation message
))
856 (the-id (or (cdr (assoc "id" situation
)) "")))
857 (when (string= (downcase the-id
)
859 (with-current-buffer mother
860 (mime-store-message/partial-piece message situation
))
861 (if (file-exists-p full-file
)
862 (throw 'tag nil
))))))
863 (message "Not all partials found.")))))
865 (defun wl-mime-display-text/plain
(entity situation
)
867 (mime-display-text/plain entity situation
)
868 (wl-highlight-message beg
(point-max) t t
)))
870 (defun wl-mime-display-header (entity situation
)
871 (let ((elmo-message-ignored-field-list
872 (if wl-message-buffer-require-all-header
874 wl-message-ignored-field-list
))
875 (elmo-message-visible-field-list wl-message-visible-field-list
)
876 (elmo-message-sorted-field-list wl-message-sort-field-list
))
877 (elmo-mime-insert-header entity situation
)
878 (wl-highlight-headers)))
880 (defun wl-mime-decrypt-application/pgp-encrypted
(entity situation
)
881 (let ((summary-buffer wl-message-buffer-cur-summary-buffer
)
882 (original-buffer wl-message-buffer-original-buffer
))
883 (mime-decrypt-application/pgp-encrypted entity situation
)
884 (setq wl-message-buffer-cur-summary-buffer summary-buffer
)
885 (setq wl-message-buffer-original-buffer original-buffer
)))
889 (defun wl-mime-setup ()
890 (set-alist 'mime-preview-quitting-method-alist
891 'wl-original-message-mode
'wl-message-exit
)
892 (set-alist 'mime-view-over-to-previous-method-alist
893 'wl-original-message-mode
'wl-message-exit
)
894 (set-alist 'mime-view-over-to-next-method-alist
895 'wl-original-message-mode
'wl-message-exit
)
896 (set-alist 'mime-preview-over-to-previous-method-alist
897 'wl-original-message-mode
'wl-message-exit
)
898 (set-alist 'mime-preview-over-to-next-method-alist
899 'wl-original-message-mode
'wl-message-exit
)
900 (add-hook 'wl-summary-toggle-disp-off-hook
'wl-message-delete-popup-windows
)
901 (add-hook 'wl-summary-redisplay-hook
'wl-message-delete-popup-windows
)
902 (add-hook 'wl-message-exit-hook
'wl-message-delete-popup-windows
)
904 (ctree-set-calist-strictly
905 'mime-preview-condition
906 '((type . text
) (subtype . plain
)
908 (body-presentation-method . wl-mime-display-text
/plain
)
909 (major-mode . wl-original-message-mode
)))
911 (ctree-set-calist-strictly
912 'mime-preview-condition
913 '((type . application
)(subtype . pgp-encrypted
)
916 (body-presentation-method . wl-mime-preview-application
/pgp-encrypted
)
917 (major-mode . wl-original-message-mode
)))
919 (ctree-set-calist-strictly
920 'mime-acting-condition
921 '((type . message
) (subtype . partial
)
922 (method . wl-mime-combine-message
/partial-pieces
)
923 (request-partial-message-method . wl-message-request-partial
)
924 (major-mode . wl-original-message-mode
)))
926 (ctree-set-calist-strictly
927 'mime-acting-condition
928 '((type . application
) (subtype . pgp-encrypted
)
929 (method . wl-mime-decrypt-application
/pgp-encrypted
)
930 (major-mode . wl-original-message-mode
)))
932 (ctree-set-calist-strictly
933 'mime-acting-condition
935 (major-mode . wl-original-message-mode
)
936 (method . wl-mime-save-content
)))
937 (set-alist 'mime-preview-following-method-alist
938 'wl-original-message-mode
939 (function wl-message-follow-current-entity
))
940 (set-alist 'mime-view-following-method-alist
941 'wl-original-message-mode
942 (function wl-message-follow-current-entity
))
943 (set-alist 'mime-edit-message-inserter-alist
944 'wl-draft-mode
(function wl-draft-insert-current-message
))
945 (set-alist 'mime-edit-mail-inserter-alist
946 'wl-draft-mode
(function wl-draft-insert-get-message
))
947 (set-alist 'mime-edit-split-message-sender-alist
949 (cdr (assq 'mail-mode mime-edit-split-message-sender-alist
)))
950 (set-alist 'mime-raw-representation-type-alist
951 'wl-original-message-mode
'binary
)
952 ;; Sort and highlight header fields.
953 (or wl-message-ignored-field-list
954 (setq wl-message-ignored-field-list
955 mime-view-ignored-field-list
))
956 (or wl-message-visible-field-list
957 (setq wl-message-visible-field-list
958 mime-view-visible-field-list
))
959 (set-alist 'mime-header-presentation-method-alist
960 'wl-original-message-mode
961 'wl-mime-display-header
)
962 ;; To avoid overriding wl-draft-mode-map.
963 (when (boundp 'mime-setup-signature-key-alist
)
964 (unless (assq 'wl-draft-mode mime-setup-signature-key-alist
)
965 (setq mime-setup-signature-key-alist
966 (cons '(wl-draft-mode .
"\C-c\C-w")
967 mime-setup-signature-key-alist
)))))
970 (product-provide (provide 'wl-mime
) (require 'wl-version
))
972 ;;; wl-mime.el ends here