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.
38 (defalias-maybe 'Meadow-version 'ignore))
40 (defvar xemacs-betaname)
41 (defvar xemacs-codename)
42 (defvar enable-multibyte-characters)
47 (defalias 'wl-draft-editor-mode 'mime-edit-mode)
49 (defalias 'wl-draft-decode-message-in-buffer
50 'mime-edit-decode-message-in-buffer)
52 (defun wl-draft-yank-current-message-entity ()
53 "Yank currently displayed message entity.
54 By setting following-method as yank-content."
55 (let ((wl-draft-buffer (current-buffer))
56 (mime-view-following-method-alist
57 (list (cons 'wl-original-message-mode
58 (function wl-draft-yank-to-draft-buffer))))
59 (mime-preview-following-method-alist
60 (list (cons 'wl-original-message-mode
61 (function wl-draft-yank-to-draft-buffer)))))
62 (if (get-buffer (wl-current-message-buffer))
65 (set-buffer (wl-current-message-buffer))
67 (mime-preview-follow-current-entity))))))
69 (defalias 'wl-draft-enclose-digest-region 'mime-edit-enclose-digest-region)
71 (defun wl-draft-preview-message ()
74 (let* (recipients-message
75 (config-exec-flag wl-draft-config-exec-flag)
76 (mime-display-header-hook 'wl-highlight-headers)
77 mime-view-ignored-field-list ; all header.
78 (mime-edit-translate-buffer-hook
83 (let ((wl-draft-config-exec-flag config-exec-flag))
84 (run-hooks 'wl-draft-send-hook)
85 (setq recipients-message
87 (concat "Recipients: "
90 (wl-draft-deduce-address-list
94 (goto-char (point-min))
98 (regexp-quote mail-header-separator)
104 (kill-buffer (current-buffer))
105 (signal (car err) (cdr err)))))))))
106 mime-edit-translate-buffer-hook)))
107 (mime-edit-preview-message)
108 (let ((buffer-read-only nil))
109 (when wl-highlight-body-too
111 (run-hooks 'wl-draft-preview-message-hook))
112 (message recipients-message)))
114 (defalias 'wl-draft-caesar-region 'mule-caesar-region)
116 (defalias 'wl-draft-insert-message 'mime-edit-insert-message)
118 (defalias 'wl-draft-insert-mail 'mime-edit-insert-mail)
122 (defun wl-message-decode-mode (outbuf inbuf)
123 (let ((mime-view-content-header-filter-hook 'wl-highlight-headers)
124 (mime-display-header-hook 'wl-highlight-headers))
125 (mime-view-mode nil nil nil inbuf outbuf)))
127 (defun wl-message-decode-with-all-header (outbuf inbuf)
128 (let ((mime-view-ignored-field-regexp "^:$")
129 (mime-view-content-header-filter-hook 'wl-highlight-headers)
130 (mime-display-header-hook 'wl-highlight-headers)
131 mime-view-ignored-field-list)
132 (mime-view-mode nil nil nil inbuf outbuf)))
134 (defun wl-message-delete-mime-out-buf ()
135 (let (mime-out-buf mime-out-win)
136 (if (setq mime-out-buf (get-buffer mime-echo-buffer-name))
137 (if (setq mime-out-win (get-buffer-window mime-out-buf))
138 (delete-window mime-out-win)))))
140 (defun wl-message-request-partial (folder number)
142 (elmo-message-fetch (wl-folder-get-elmo-folder folder)
144 (elmo-make-fetch-strategy 'entire)
148 (mime-parse-buffer nil)))
150 (defalias 'wl-message-read 'mime-preview-scroll-up-entity)
151 (defalias 'wl-message-next-content 'mime-preview-move-to-next)
152 (defalias 'wl-message-prev-content 'mime-preview-move-to-previous)
153 (defalias 'wl-message-play-content 'mime-preview-play-current-entity)
154 (defalias 'wl-message-extract-content 'mime-preview-extract-current-entity)
155 (defalias 'wl-message-quit 'mime-preview-quit)
156 (defalias 'wl-message-button-dispatcher-internal
157 'mime-button-dispatcher)
160 (defun wl-summary-burst-subr (message-entity target number)
161 ;; returns new number.
162 (let (content-type entity)
163 (setq content-type (mime-entity-content-type message-entity))
164 (cond ((eq (cdr (assq 'type content-type)) 'multipart)
165 (dolist (entity (mime-entity-children message-entity))
166 (setq number (wl-summary-burst-subr
170 ((and (eq (cdr (assq 'type content-type)) 'message)
171 (eq (cdr (assq 'subtype content-type)) 'rfc822))
172 (message (format "Bursting...%s" (setq number (+ 1 number))))
174 (car (mime-entity-children message-entity)))
176 (insert (mime-entity-body message-entity))
177 (elmo-folder-append-buffer
179 (mime-entity-fetch-field entity "Message-ID")))))
182 (defun wl-summary-burst ()
185 (let ((raw-buf (wl-summary-get-original-buffer))
186 (view-buf wl-message-buffer)
187 children message-entity content-type target)
189 (setq target wl-summary-buffer-elmo-folder)
190 (while (not (elmo-folder-writable-p target))
192 (wl-summary-read-folder wl-default-folder "to extract to")))
193 (wl-summary-set-message-buffer-or-redisplay)
194 (with-current-buffer view-buf
195 (setq message-entity (get-text-property (point-min) 'mime-view-entity)))
197 (message "Bursting...")
198 (with-current-buffer raw-buf
199 (wl-summary-burst-subr message-entity target 0))
200 (message "Bursting...done"))
201 (if (elmo-folder-plugged-p target)
202 (elmo-folder-check target)))
203 (wl-summary-sync-update)))
205 ;; internal variable.
206 (defvar wl-mime-save-dir nil "Last saved directory.")
207 ;;; Yet another save method.
208 (defun wl-mime-save-content (entity situation)
209 (let ((filename (read-file-name "Save to file: "
211 (or (mime-entity-safe-filename entity)
215 (while (file-directory-p filename)
216 (setq filename (read-file-name "Please set filename (not directory): "
218 (if (file-exists-p filename)
219 (or (yes-or-no-p (format "File %s exists. Save anyway? " filename))
220 (error "Not saved")))
221 (setq wl-mime-save-dir (file-name-directory filename))
222 (mime-write-entity-content entity filename)))
224 ;;; Yet another combine method.
225 (defun wl-mime-combine-message/partial-pieces (entity situation)
226 "Internal method for wl to combine message/partial messages automatically."
228 (let* ((msgdb (save-excursion
229 (set-buffer wl-message-buffer-cur-summary-buffer)
230 (wl-summary-buffer-msgdb)))
231 (mime-display-header-hook 'wl-highlight-headers)
232 (folder wl-message-buffer-cur-folder)
233 (id (or (cdr (assoc "id" situation)) ""))
234 (mother (current-buffer))
235 (summary-buf wl-message-buffer-cur-summary-buffer)
237 (root-dir (expand-file-name
238 (concat "m-prts-" (user-login-name))
239 temporary-file-directory))
241 (setq root-dir (concat root-dir "/" (replace-as-filename id)))
242 (setq full-file (concat root-dir "/FULL"))
243 (if (or (file-exists-p full-file)
244 (not (y-or-n-p "Merge partials? ")))
245 (with-current-buffer mother
246 (mime-store-message/partial-piece entity situation)
247 (setq wl-message-buffer-cur-summary-buffer summary-buf)
248 (make-variable-buffer-local 'mime-preview-over-to-next-method-alist)
249 (setq mime-preview-over-to-next-method-alist
250 (cons (cons 'mime-show-message-mode 'wl-message-exit)
251 mime-preview-over-to-next-method-alist))
252 (make-variable-buffer-local 'mime-preview-over-to-previous-method-alist)
253 (setq mime-preview-over-to-previous-method-alist
254 (cons (cons 'mime-show-message-mode 'wl-message-exit)
255 mime-preview-over-to-previous-method-alist)))
258 (decode-mime-charset-string
259 (mime-entity-read-field entity 'Subject)
260 wl-summary-buffer-mime-charset)))
261 (if (string-match "[0-9\n]+" subject-id)
262 (setq subject-id (substring subject-id 0 (match-beginning 0))))
263 (setq overviews (elmo-msgdb-get-overview msgdb))
267 (regexp-quote subject-id)
268 (elmo-msgdb-overview-entity-get-subject (car overviews)))
270 ;; request message at the cursor in Subject buffer.
271 (wl-message-request-partial
273 (elmo-msgdb-overview-entity-get-number
275 (situation (mime-entity-situation message))
276 (the-id (or (cdr (assoc "id" situation)) "")))
277 (when (string= (downcase the-id)
279 (with-current-buffer mother
280 (mime-store-message/partial-piece message situation))
281 (if (file-exists-p full-file)
283 (setq overviews (cdr overviews)))
284 (message "Not all partials found.")))))
286 (defun wl-mime-display-text/plain (entity situation)
288 (mime-display-text/plain entity situation)
289 (wl-highlight-message beg (point-max) t t)))
291 (defun wl-mime-display-header (entity situation)
292 (let ((elmo-message-ignored-field-list
293 (if wl-message-buffer-all-header-flag
295 wl-message-ignored-field-list))
296 (elmo-message-visible-field-list wl-message-visible-field-list)
297 (elmo-message-sorted-field-list wl-message-sort-field-list))
298 (elmo-mime-insert-header entity situation)
299 (wl-highlight-headers)))
302 (defun wl-mime-setup ()
303 (set-alist 'mime-preview-quitting-method-alist
304 'wl-original-message-mode 'wl-message-exit)
305 (set-alist 'mime-view-over-to-previous-method-alist
306 'wl-original-message-mode 'wl-message-exit)
307 (set-alist 'mime-view-over-to-next-method-alist
308 'wl-original-message-mode 'wl-message-exit)
309 (set-alist 'mime-preview-over-to-previous-method-alist
310 'wl-original-message-mode 'wl-message-exit)
311 (set-alist 'mime-preview-over-to-next-method-alist
312 'wl-original-message-mode 'wl-message-exit)
313 (add-hook 'wl-summary-redisplay-hook 'wl-message-delete-mime-out-buf)
314 (add-hook 'wl-message-exit-hook 'wl-message-delete-mime-out-buf)
316 (ctree-set-calist-strictly
317 'mime-preview-condition
318 '((type . text) (subtype . plain)
320 (body-presentation-method . wl-mime-display-text/plain)
321 (major-mode . wl-original-message-mode)))
323 (ctree-set-calist-strictly
324 'mime-acting-condition
325 '((type . message) (subtype . partial)
326 (method . wl-mime-combine-message/partial-pieces)
327 (request-partial-message-method . wl-message-request-partial)
328 (major-mode . wl-original-message-mode)))
330 (ctree-set-calist-strictly
331 'mime-acting-condition
333 (major-mode . wl-original-message-mode)
334 (method . wl-mime-save-content)))
335 (set-alist 'mime-preview-following-method-alist
336 'wl-original-message-mode
337 (function wl-message-follow-current-entity))
338 (set-alist 'mime-view-following-method-alist
339 'wl-original-message-mode
340 (function wl-message-follow-current-entity))
341 (set-alist 'mime-edit-message-inserter-alist
342 'wl-draft-mode (function wl-draft-insert-current-message))
343 (set-alist 'mime-edit-mail-inserter-alist
344 'wl-draft-mode (function wl-draft-insert-get-message))
345 (set-alist 'mime-edit-split-message-sender-alist
347 (cdr (assq 'mail-mode mime-edit-split-message-sender-alist)))
348 (set-alist 'mime-raw-representation-type-alist
349 'wl-original-message-mode 'binary)
350 ;; Sort and highlight header fields.
351 (or wl-message-ignored-field-list
352 (setq wl-message-ignored-field-list
353 mime-view-ignored-field-list))
354 (or wl-message-visible-field-list
355 (setq wl-message-visible-field-list
356 mime-view-visible-field-list))
357 (set-alist 'mime-header-presentation-method-alist
358 'wl-original-message-mode
359 'wl-mime-display-header)
360 ;; To avoid overriding wl-draft-mode-map.
361 (when (boundp 'mime-setup-signature-key-alist)
362 (unless (assq 'wl-draft-mode mime-setup-signature-key-alist)
363 (setq mime-setup-signature-key-alist
364 (cons '(wl-draft-mode . "\C-c\C-w")
365 mime-setup-signature-key-alist)))))
368 (product-provide (provide 'wl-mime) (require 'wl-version))
370 ;;; wl-mime.el ends here