1 ;;; wl-mime.el -- tm implementations of MIME processing on Wanderlust.
3 ;; Copyright 1998,1999,2000 Yuuichi Teranishi <teranisi@gohome.org>
5 ;; Author: Yuuichi Teranishi <teranisi@gohome.org>
6 ;; Keywords: mail, net news
7 ;; Time-stamp: <00/04/20 13:45:03 teranisi>
9 ;; This file is part of Wanderlust (Yet Another Message Interface on Emacsen).
11 ;; This program is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; This program is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
33 (autoload 'mime/editor-mode "tm-edit" nil t)
34 (autoload 'mime/edit-again "tm-edit" nil t)
36 (eval-when-compile (require 'tm-edit))
38 (defalias 'wl-draft-editor-mode 'mime/editor-mode)
40 (defun wl-draft-decode-message-in-buffer (&optional default-content-type)
41 (when default-content-type
42 (insert "Content-type: " default-content-type "\n")
44 (mime-editor::edit-again 'code-conversion))
46 (defun wl-draft-yank-current-message-entity ()
47 "Yank currently displayed message entity.
48 By setting following-method as yank-content."
49 (let ((wl-draft-buffer (current-buffer))
50 (mime-viewer/following-method-alist
51 (list (cons 'wl-message-original-mode
52 (function wl-draft-yank-to-draft-buffer)))))
53 (if (get-buffer (wl-current-message-buffer))
56 (set-buffer (wl-current-message-buffer))
57 (setq mime::preview/mother-buffer nil)
59 (mime-viewer/follow-content))))))
61 (defmacro wl-draft-enclose-digest-region (beg end)
62 (` (mime-editor/enclose-region "digest" (, beg) (, end))))
64 (defun wl-draft-preview-message ()
66 (let ((mime-viewer/content-header-filter-hook 'wl-highlight-headers)
67 (mime-viewer/ignored-field-regexp "^:$")
68 (mime-editor/translate-buffer-hook
70 (list 'wl-draft-config-exec)
71 mime-editor/translate-buffer-hook)))
72 (mime-editor/preview-message)
73 (let ((buffer-read-only nil))
74 (let ((buffer-read-only nil))
75 (when wl-highlight-body-too
77 (run-hooks 'wl-draft-preview-message-hook)))))
79 (defmacro wl-draft-caesar-region (beg end)
80 (` (tm:caesar-region)))
82 (defalias 'wl-draft-insert-message 'mime-editor/insert-message)
84 (defalias 'wl-draft-insert-mail 'mime-editor/insert-mail)
88 (defun wl-message-decode-mode (outbuf inbuf)
89 (let ((mime-viewer/content-header-filter-hook 'wl-highlight-headers))
90 (mime/viewer-mode nil nil nil inbuf outbuf)))
92 (defun wl-message-decode-with-all-header (outbuf inbuf)
93 (let ((mime-viewer/ignored-field-regexp "^:$")
94 (mime-viewer/content-header-filter-hook 'wl-highlight-headers))
95 (mime/viewer-mode nil nil nil inbuf outbuf)))
97 (defun wl-message-delete-mime-out-buf ()
98 (let (mime-out-buf mime-out-win)
99 (if (setq mime-out-buf (get-buffer mime/output-buffer-name))
100 (if (setq mime-out-win (get-buffer-window mime-out-buf))
101 (delete-window mime-out-win)))))
103 (defun wl-message-request-partial (folder number)
105 (elmo-read-msg-no-cache folder number (current-buffer))
106 (mime/parse-message nil nil)))
108 (defalias 'wl-message-read 'mime-viewer/scroll-up-content)
109 (defalias 'wl-message-next-content 'mime-viewer/next-content)
110 (defalias 'wl-message-prev-content 'mime-viewer/previous-content)
111 (defalias 'wl-message-play-content 'mime-viewer/play-content)
112 (defalias 'wl-message-extract-content 'mime-viewer/extract-content)
113 (defalias 'wl-message-quit 'mime-viewer/quit)
114 (defalias 'wl-message-button-dispatcher 'tm:button-dispatcher)
117 (defun wl-summary-burst-subr (children target number)
118 ;; returns new number.
119 (let (content-type message-entity granch)
121 (setq content-type (mime::content-info/type (car children)))
122 (if (string-match "multipart" content-type)
123 (setq number (wl-summary-burst-subr
124 (mime::content-info/children (car children))
127 (when (string= "message/rfc822" (downcase content-type))
128 (message (format "Bursting...%s" (setq number (+ 1 number))))
130 (car (mime::content-info/children (car children))))
132 (narrow-to-region (mime::content-info/point-min message-entity)
133 (mime::content-info/point-max message-entity))
134 (elmo-append-msg target
135 (buffer-substring (point-min) (point-max))
136 (std11-field-body "Message-ID")))))
137 (setq children (cdr children)))))
139 (defun wl-summary-burst ()
141 (let ((raw-buf (wl-message-get-original-buffer))
143 children message-entity content-type)
145 (setq target wl-summary-buffer-folder-name)
146 (while (not (elmo-folder-writable-p target))
148 (wl-summary-read-folder wl-default-folder "to extract to ")))
149 (wl-summary-set-message-buffer-or-redisplay)
151 (setq children (mime::content-info/children mime::article/content-info))
152 (message "Bursting...")
154 (wl-summary-burst-subr children target 0))
155 (message "Bursting...done."))
156 (if (elmo-folder-plugged-p target)
157 (elmo-commit target))
158 (wl-summary-sync-update3)))
160 ;; internal variable.
161 (defvar wl-mime-save-dir nil "Last saved directory.")
162 ;;; Yet another save method.
163 (defun wl-mime-save-content (beg end cal)
167 (narrow-to-region beg end)
168 (mime-article/get-filename cal)))
169 (encoding (cdr (assq 'encoding cal)))
170 (filename (read-file-name "Save to file: "
176 (while (file-directory-p filename)
177 (setq filename (read-file-name "Please set filename (not directory): "
179 (if (file-exists-p filename)
180 (or (yes-or-no-p (format "File %s exists. Save anyway? " filename))
181 (error "Not saved")))
182 (setq wl-mime-save-dir (file-name-directory filename))
183 (setq tmp-buf (generate-new-buffer (file-name-nondirectory filename)))
184 (re-search-forward "\n\n")
185 (append-to-buffer tmp-buf (match-end 0) end)
188 (mime-decode-region (point-min)(point-max) encoding)
189 (as-binary-output-file (write-file filename))
190 (kill-buffer tmp-buf))))
192 ;;; Yet another combine method.
193 (defun wl-mime-combine-message/partial-pieces (beg end cal)
196 (msgdb (save-excursion
197 (set-buffer wl-message-buffer-cur-summary-buffer)
198 (setq folder wl-summary-buffer-folder-name)
199 wl-summary-buffer-msgdb))
200 (mime-viewer/content-header-filter-hook 'wl-highlight-headers)
201 (id (cdr (assoc "id" cal)))
202 (mother mime::article/preview-buffer)
203 (target (cdr (assq 'major-mode cal)))
204 (article-buffer (buffer-name (current-buffer)))
205 (subject-buf (eval (cdr (assq 'summary-buffer-exp cal))))
207 (root-dir (expand-file-name
208 (concat "m-prts-" (user-login-name)) mime/tmp-dir))
210 (setq root-dir (concat root-dir "/" (replace-as-filename id)))
211 (setq full-file (concat root-dir "/FULL"))
213 (error "%s is not supported. Sorry." target))
214 (if (or (file-exists-p full-file)
215 (not (y-or-n-p "Merge partials?")))
216 (mime-article/decode-message/partial beg end cal)
217 (message "Merging...")
218 (let (cinfo the-id parameters)
221 (decode-mime-charset-string
222 (std11-field-body "Subject")
223 wl-summary-buffer-mime-charset)))
224 (if (string-match "[0-9\n]+" subject-id)
225 (setq subject-id (substring subject-id 0 (match-beginning 0))))
226 (setq overviews (elmo-msgdb-get-overview msgdb))
230 (regexp-quote subject-id)
231 (elmo-msgdb-overview-entity-get-subject
234 (wl-message-request-partial
236 (elmo-msgdb-overview-entity-get-number (car overviews))))
237 (setq parameters (mime::content-info/parameters cinfo))
238 (setq the-id (assoc-value "id" parameters))
239 (if (string= the-id id)
241 (set-buffer elmo-work-buf-name)
242 (setq mime::article/preview-buffer
243 (get-buffer wl-message-buf-name))
244 (mime-article/decode-message/partial
245 (point-min)(point-max) parameters)
246 (if (file-exists-p full-file)
248 (setq overviews (cdr overviews)))
249 (message "Not all partials found."))))))
251 (defun wl-mime-setup ()
253 (set-alist 'mime-viewer/quitting-method-alist
254 'wl-message-original-mode 'wl-message-exit)
255 (set-alist 'mime-viewer/over-to-previous-method-alist
256 'wl-message-original-mode 'wl-message-exit)
257 (set-alist 'mime-viewer/over-to-next-method-alist
258 'wl-message-original-mode 'wl-message-exit)
259 (add-hook 'wl-summary-redisplay-hook 'wl-message-delete-mime-out-buf)
260 (add-hook 'wl-message-exit-hook 'wl-message-delete-mime-out-buf)
261 (set-atype 'mime/content-decoding-condition
262 '((type . "message/partial")
263 (method . wl-message-combine-message/partial-pieces)
264 (major-mode . wl-message-original-mode)
265 (summary-buffer-exp . wl-summary-buffer-name)))
266 (set-atype 'mime/content-decoding-condition
268 (method . wl-mime-save-content)
269 (major-mode . wl-message-original-mode))
271 '((method "tm-file" nil 'file 'type 'encoding 'mode 'name)
274 (set-alist 'mime-viewer/following-method-alist
275 'wl-message-original-mode
276 (function wl-message-follow-current-entity))
278 (set-alist 'mime-editor/message-inserter-alist
279 'wl-draft-mode (function wl-draft-insert-current-message))
280 (set-alist 'mime-editor/mail-inserter-alist
281 'wl-draft-mode (function wl-draft-insert-get-message))
282 (set-alist 'mime-editor/split-message-sender-alist
284 (cdr (assq 'mail-mode
285 mime-editor/split-message-sender-alist)))
286 (setq mime-viewer/code-converter-alist
288 (list (cons 'wl-message-original-mode 'mime-charset/decode-buffer))
289 mime-viewer/code-converter-alist))
290 (defvar-maybe mime::preview/mother-buffer nil))
294 ;;; tm-wl.el ends here