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
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.
32 (autoload 'mime/editor-mode "tm-edit" nil t)
33 (autoload 'mime/edit-again "tm-edit" nil t)
35 (eval-when-compile (require 'tm-edit))
37 (defalias 'wl-draft-editor-mode 'mime/editor-mode)
39 (defun wl-draft-decode-message-in-buffer (&optional default-content-type)
40 (when default-content-type
41 (insert "Content-type: " default-content-type "\n")
43 (mime-editor::edit-again 'code-conversion))
45 (defun wl-draft-yank-current-message-entity ()
46 "Yank currently displayed message entity.
47 By setting following-method as yank-content."
48 (let ((wl-draft-buffer (current-buffer))
49 (mime-viewer/following-method-alist
50 (list (cons 'wl-message-original-mode
51 (function wl-draft-yank-to-draft-buffer)))))
52 (if (get-buffer (wl-current-message-buffer))
55 (set-buffer (wl-current-message-buffer))
56 (setq mime::preview/mother-buffer nil)
58 (mime-viewer/follow-content))))))
60 (defmacro wl-draft-enclose-digest-region (beg end)
61 (` (mime-editor/enclose-region "digest" (, beg) (, end))))
63 (defun wl-draft-preview-message ()
65 (let ((mime-viewer/content-header-filter-hook 'wl-highlight-headers)
66 (mime-viewer/ignored-field-regexp "^:$")
67 (mime-editor/translate-buffer-hook
69 (list 'wl-draft-config-exec)
70 mime-editor/translate-buffer-hook)))
71 (mime-editor/preview-message)
72 (let ((buffer-read-only nil))
73 (let ((buffer-read-only nil))
74 (when wl-highlight-body-too
76 (run-hooks 'wl-draft-preview-message-hook)))))
78 (defmacro wl-draft-caesar-region (beg end)
79 (` (tm:caesar-region)))
81 (defalias 'wl-draft-insert-message 'mime-editor/insert-message)
83 (defalias 'wl-draft-insert-mail 'mime-editor/insert-mail)
87 (defun wl-message-decode-mode (outbuf inbuf)
88 (let ((mime-viewer/content-header-filter-hook 'wl-highlight-headers))
89 (mime/viewer-mode nil nil nil inbuf outbuf)))
91 (defun wl-message-decode-with-all-header (outbuf inbuf)
92 (let ((mime-viewer/ignored-field-regexp "^:$")
93 (mime-viewer/content-header-filter-hook 'wl-highlight-headers))
94 (mime/viewer-mode nil nil nil inbuf outbuf)))
96 (defun wl-message-delete-mime-out-buf ()
97 (let (mime-out-buf mime-out-win)
98 (if (setq mime-out-buf (get-buffer mime/output-buffer-name))
99 (if (setq mime-out-win (get-buffer-window mime-out-buf))
100 (delete-window mime-out-win)))))
102 (defun wl-message-request-partial (folder number)
104 (elmo-read-msg-no-cache folder number (current-buffer))
105 (mime/parse-message nil nil)))
107 (defalias 'wl-message-read 'mime-viewer/scroll-up-content)
108 (defalias 'wl-message-next-content 'mime-viewer/next-content)
109 (defalias 'wl-message-prev-content 'mime-viewer/previous-content)
110 (defalias 'wl-message-play-content 'mime-viewer/play-content)
111 (defalias 'wl-message-extract-content 'mime-viewer/extract-content)
112 (defalias 'wl-message-quit 'mime-viewer/quit)
113 (defalias 'wl-message-button-dispatcher-internal
114 '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