4
|
1 ;;; tm-mh-e.el --- MIME extension for mh-e
|
|
2
|
|
3 ;; Copyright (C) 1995,1996 Free Software Foundation, Inc.
|
|
4
|
|
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
|
|
6 ;; OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
|
|
7 ;; Maintainer: MORIOKA Tomohiko <morioka@jaist.ac.jp>
|
|
8 ;; Created: 1993/11/21 (obsolete mh-e-mime.el)
|
195
|
9 ;; Version: $Revision: 1.3 $
|
4
|
10 ;; Keywords: mail, MH, MIME, multimedia, encoded-word, multilingual
|
|
11
|
|
12 ;; This file is part of tm (Tools for MIME).
|
|
13
|
|
14 ;; This program is free software; you can redistribute it and/or
|
|
15 ;; modify it under the terms of the GNU General Public License as
|
|
16 ;; published by the Free Software Foundation; either version 2, or (at
|
|
17 ;; your option) any later version.
|
|
18
|
|
19 ;; This program is distributed in the hope that it will be useful, but
|
|
20 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
22 ;; General Public License for more details.
|
|
23
|
|
24 ;; You should have received a copy of the GNU General Public License
|
|
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
26 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
27 ;; Boston, MA 02111-1307, USA.
|
|
28
|
|
29 ;;; Code:
|
|
30
|
|
31 (require 'tl-str)
|
|
32 (require 'tl-misc)
|
|
33 (require 'mh-e)
|
|
34 (or (featurep 'mh-utils)
|
|
35 (require 'tm-mh-e3)
|
|
36 )
|
|
37 (require 'tm-view)
|
|
38
|
|
39 (or (fboundp 'mh-get-header-field)
|
|
40 (defalias 'mh-get-header-field 'mh-get-field)
|
|
41 )
|
|
42 (or (boundp 'mh-temp-buffer)
|
|
43 (defconst mh-temp-buffer " *mh-temp*")
|
|
44 )
|
|
45
|
|
46
|
|
47 ;;; @ version
|
|
48 ;;;
|
|
49
|
|
50 (defconst tm-mh-e/RCS-ID
|
195
|
51 "$Id: tm-mh-e.el,v 1.3 1997/09/27 16:57:47 steve Exp $")
|
4
|
52
|
|
53 (defconst tm-mh-e/version (get-version-string tm-mh-e/RCS-ID))
|
|
54
|
|
55
|
|
56 ;;; @ variable
|
|
57 ;;;
|
|
58
|
|
59 (defvar tm-mh-e/automatic-mime-preview t
|
|
60 "*If non-nil, show MIME processed message.")
|
|
61
|
|
62 (defvar tm-mh-e/decode-encoded-word t
|
|
63 "*If non-nil, decode encoded-word when it is not MIME preview mode.")
|
|
64
|
|
65
|
|
66 ;;; @ functions
|
|
67 ;;;
|
|
68
|
|
69 (defun mh-display-msg (msg-num folder &optional show-buffer mode)
|
|
70 (or mode
|
|
71 (setq mode tm-mh-e/automatic-mime-preview)
|
|
72 )
|
|
73 ;; Display message NUMBER of FOLDER.
|
|
74 ;; Sets the current buffer to the show buffer.
|
|
75 (set-buffer folder)
|
195
|
76 (or show-buffer
|
|
77 (setq show-buffer mh-show-buffer))
|
4
|
78 ;; Bind variables in folder buffer in case they are local
|
175
|
79 (let ((formfile mhl-formfile)
|
|
80 (clean-message-header mh-clean-message-header)
|
|
81 (invisible-headers mh-invisible-headers)
|
|
82 (visible-headers mh-visible-headers)
|
|
83 (msg-filename (mh-msg-filename msg-num))
|
|
84 )
|
4
|
85 (if (not (file-exists-p msg-filename))
|
|
86 (error "Message %d does not exist" msg-num))
|
|
87 (set-buffer show-buffer)
|
|
88 (cond ((not (equal msg-filename buffer-file-name))
|
|
89 ;; Buffer does not yet contain message.
|
175
|
90 (mh-unvisit-file)
|
4
|
91 (setq buffer-read-only nil)
|
|
92 (erase-buffer)
|
175
|
93 ;; Changing contents, so this hook needs to be reinitialized.
|
|
94 ;; pgp.el uses this.
|
|
95 (if (boundp 'write-contents-hooks) ;Emacs 19
|
|
96 (setq write-contents-hooks nil))
|
4
|
97 (if mode
|
|
98 (let* ((aname (concat "article-" folder))
|
|
99 (abuf (get-buffer aname))
|
|
100 )
|
|
101 (if abuf
|
|
102 (progn
|
|
103 (set-buffer abuf)
|
|
104 (setq buffer-read-only nil)
|
|
105 (erase-buffer)
|
|
106 )
|
|
107 (setq abuf (get-buffer-create aname))
|
|
108 (set-buffer abuf)
|
|
109 )
|
|
110 (as-binary-input-file
|
|
111 (insert-file-contents msg-filename)
|
|
112 ;; (goto-char (point-min))
|
|
113 (while (re-search-forward "\r$" nil t)
|
|
114 (replace-match "")
|
|
115 )
|
|
116 )
|
|
117 (set-buffer-modified-p nil)
|
|
118 (setq buffer-read-only t)
|
|
119 (setq buffer-file-name msg-filename)
|
|
120 (mh-show-mode)
|
|
121 (mime/viewer-mode nil nil nil
|
|
122 aname (concat "show-" folder))
|
|
123 (goto-char (point-min))
|
175
|
124 (let ( (buffer-read-only nil) )
|
|
125 (cond (clean-message-header
|
|
126 (mh-clean-msg-header (point-min)
|
|
127 invisible-headers
|
|
128 visible-headers)
|
|
129 (goto-char (point-min)))
|
|
130 (t
|
|
131 (mh-start-of-uncleaned-message))))
|
|
132 (goto-char (point-min))
|
4
|
133 )
|
175
|
134 (progn
|
|
135 (if formfile
|
4
|
136 (mh-exec-lib-cmd-output "mhl" "-nobell" "-noclear"
|
175
|
137 (if (stringp formfile)
|
|
138 (list "-form" formfile))
|
4
|
139 msg-filename)
|
|
140 (insert-file-contents msg-filename))
|
|
141 ;; end
|
|
142 (goto-char (point-min))
|
|
143 (cond (clean-message-header
|
|
144 (mh-clean-msg-header (point-min)
|
|
145 invisible-headers
|
|
146 visible-headers)
|
|
147 (goto-char (point-min)))
|
|
148 (t
|
|
149 (mh-start-of-uncleaned-message)))
|
|
150 (if tm-mh-e/decode-encoded-word
|
|
151 (mime/decode-message-header)
|
|
152 )
|
|
153 (set-buffer-modified-p nil)
|
|
154 (setq buffer-read-only t)
|
|
155 (setq buffer-file-name msg-filename)
|
|
156 (mh-show-mode)
|
|
157 ))
|
175
|
158 (set-buffer-modified-p nil)
|
4
|
159 (or (eq buffer-undo-list t) ;don't save undo info for prev msgs
|
|
160 (setq buffer-undo-list nil))
|
175
|
161 (set-buffer-auto-saved)
|
|
162 ;; the parts of set-visited-file-name we want to do (no locking)
|
4
|
163 (setq buffer-file-name msg-filename)
|
175
|
164 (setq buffer-backed-up nil)
|
|
165 (auto-save-mode 1)
|
4
|
166 (set-mark nil)
|
|
167 (setq mode-line-buffer-identification
|
|
168 (list (format mh-show-buffer-mode-line-buffer-id
|
|
169 folder msg-num)))
|
|
170 (set-buffer folder)
|
|
171 (setq mh-showing-with-headers nil)))))
|
|
172
|
|
173 (defun tm-mh-e/view-message (&optional msg)
|
|
174 "MIME decode and play this message."
|
|
175 (interactive)
|
|
176 (if (or (null tm-mh-e/automatic-mime-preview)
|
|
177 (null (get-buffer mh-show-buffer))
|
|
178 (save-excursion
|
|
179 (set-buffer mh-show-buffer)
|
|
180 (not (eq major-mode 'mime/viewer-mode))
|
|
181 ))
|
|
182 (let ((tm-mh-e/automatic-mime-preview t))
|
|
183 (mh-invalidate-show-buffer)
|
|
184 (mh-show-msg msg)
|
|
185 ))
|
|
186 (pop-to-buffer mh-show-buffer)
|
|
187 )
|
|
188
|
|
189 (defun tm-mh-e/toggle-decoding-mode (arg)
|
|
190 "Toggle MIME processing mode.
|
|
191 With arg, turn MIME processing on if arg is positive."
|
|
192 (interactive "P")
|
|
193 (setq tm-mh-e/automatic-mime-preview
|
|
194 (if (null arg)
|
|
195 (not tm-mh-e/automatic-mime-preview)
|
|
196 arg))
|
|
197 (save-excursion
|
|
198 (set-buffer mh-show-buffer)
|
|
199 (if (null tm-mh-e/automatic-mime-preview)
|
|
200 (if (and mime::preview/article-buffer
|
|
201 (get-buffer mime::preview/article-buffer))
|
|
202 (kill-buffer mime::preview/article-buffer)
|
|
203 )))
|
|
204 (mh-invalidate-show-buffer)
|
|
205 (mh-show (mh-get-msg-num t))
|
|
206 )
|
|
207
|
|
208 (defun tm-mh-e/show (&optional message)
|
|
209 (interactive)
|
|
210 (mh-invalidate-show-buffer)
|
|
211 (mh-show message)
|
|
212 )
|
|
213
|
|
214 (defun tm-mh-e/header-display ()
|
|
215 (interactive)
|
|
216 (mh-invalidate-show-buffer)
|
|
217 (let ((mime-viewer/ignored-field-regexp "^:$")
|
|
218 tm-mh-e/decode-encoded-word)
|
|
219 (mh-header-display)
|
|
220 ))
|
|
221
|
|
222 (defun tm-mh-e/raw-display ()
|
|
223 (interactive)
|
|
224 (mh-invalidate-show-buffer)
|
|
225 (let (tm-mh-e/automatic-mime-preview
|
|
226 tm-mh-e/decode-encoded-word)
|
|
227 (mh-header-display)
|
|
228 ))
|
|
229
|
|
230 (defun tm-mh-e/burst-multipart/digest ()
|
|
231 "Burst apart the current message, which should be a multipart/digest.
|
|
232 The message is replaced by its table of contents and the letters from the
|
|
233 digest are inserted into the folder after that message."
|
|
234 (interactive)
|
|
235 (let ((digest (mh-get-msg-num t)))
|
|
236 (mh-process-or-undo-commands mh-current-folder)
|
|
237 (mh-set-folder-modified-p t) ; lock folder while bursting
|
|
238 (message "Bursting digest...")
|
|
239 (mh-exec-cmd "mhn" "-store" mh-current-folder digest)
|
|
240 (mh-scan-folder mh-current-folder (format "%d-last" mh-first-msg-num))
|
|
241 (message "Bursting digest...done")
|
|
242 ))
|
|
243
|
|
244
|
|
245 ;;; @ for tm-view
|
|
246 ;;;
|
|
247
|
|
248 (fset 'tm-mh-e/decode-charset-buffer
|
|
249 (symbol-function 'mime-charset/decode-buffer))
|
|
250
|
|
251 (set-alist 'mime-viewer/code-converter-alist
|
|
252 'mh-show-mode
|
|
253 (function tm-mh-e/decode-charset-buffer))
|
|
254
|
|
255 (defun tm-mh-e/content-header-filter ()
|
|
256 (goto-char (point-min))
|
|
257 (mime-preview/cut-header)
|
|
258 (tm-mh-e/decode-charset-buffer default-mime-charset)
|
|
259 (mime/decode-message-header)
|
|
260 )
|
|
261
|
|
262 (set-alist 'mime-viewer/content-header-filter-alist
|
|
263 'mh-show-mode
|
|
264 (function tm-mh-e/content-header-filter))
|
|
265
|
|
266 (defun tm-mh-e/quitting-method ()
|
|
267 (let ((win (get-buffer-window
|
|
268 mime/output-buffer-name))
|
|
269 (buf (current-buffer))
|
|
270 )
|
|
271 (if win
|
|
272 (delete-window win)
|
|
273 )
|
|
274 (pop-to-buffer
|
|
275 (let ((name (buffer-name buf)))
|
|
276 (substring name 5)
|
|
277 ))
|
|
278 (if (not tm-mh-e/automatic-mime-preview)
|
|
279 (mh-invalidate-show-buffer)
|
|
280 )
|
|
281 (mh-show (mh-get-msg-num t))
|
|
282 ))
|
|
283
|
|
284 (set-alist 'mime-viewer/quitting-method-alist
|
|
285 'mh-show-mode
|
|
286 (function tm-mh-e/quitting-method))
|
|
287 (set-alist 'mime-viewer/show-summary-method
|
|
288 'mh-show-mode
|
|
289 (function tm-mh-e/quitting-method))
|
|
290
|
|
291 (defun tm-mh-e/following-method (buf)
|
|
292 (save-excursion
|
|
293 (set-buffer buf)
|
|
294 (goto-char (point-max))
|
|
295 (setq mh-show-buffer buf)
|
|
296 (apply (function mh-send)
|
74
|
297 (std11-field-bodies '("From" "cc" "Subject") ""))
|
4
|
298 (setq mh-sent-from-folder buf)
|
|
299 (setq mh-sent-from-msg 1)
|
|
300 (let ((last (point)))
|
|
301 (mh-yank-cur-msg)
|
|
302 (goto-char last)
|
|
303 )))
|
|
304
|
|
305 (set-alist 'mime-viewer/following-method-alist
|
|
306 'mh-show-mode
|
|
307 (function tm-mh-e/following-method))
|
|
308
|
|
309
|
|
310 ;;; @@ for tm-partial
|
|
311 ;;;
|
|
312
|
|
313 (call-after-loaded
|
|
314 'tm-partial
|
|
315 (function
|
|
316 (lambda ()
|
|
317 (set-atype 'mime/content-decoding-condition
|
|
318 '((type . "message/partial")
|
|
319 (method . mime-article/grab-message/partials)
|
|
320 (major-mode . mh-show-mode)
|
|
321 (summary-buffer-exp
|
|
322 . (and (or (string-match "^article-\\(.+\\)$" article-buffer)
|
|
323 (string-match "^show-\\(.+\\)$" article-buffer))
|
|
324 (substring article-buffer
|
|
325 (match-beginning 1) (match-end 1))
|
|
326 ))
|
|
327 ))
|
|
328 (set-alist 'tm-partial/preview-article-method-alist
|
|
329 'mh-show-mode
|
|
330 (function
|
|
331 (lambda ()
|
|
332 (let ((tm-mh-e/automatic-mime-preview t))
|
|
333 (tm-mh-e/show)
|
|
334 ))))
|
|
335 )))
|
|
336
|
|
337
|
|
338 ;;; @ set up
|
|
339 ;;;
|
|
340
|
|
341 (define-key mh-folder-mode-map "v" (function tm-mh-e/view-message))
|
|
342 (define-key mh-folder-mode-map "\et" (function tm-mh-e/toggle-decoding-mode))
|
|
343 (define-key mh-folder-mode-map "." (function tm-mh-e/show))
|
|
344 (define-key mh-folder-mode-map "," (function tm-mh-e/header-display))
|
|
345 (define-key mh-folder-mode-map "\e," (function tm-mh-e/raw-display))
|
|
346 (define-key mh-folder-mode-map "\C-c\C-b"
|
|
347 (function tm-mh-e/burst-multipart/digest))
|
|
348
|
|
349 (defun tm-mh-e/summary-before-quit ()
|
|
350 (let ((buf (get-buffer mh-show-buffer)))
|
|
351 (if buf
|
|
352 (let ((the-buf (current-buffer)))
|
|
353 (switch-to-buffer buf)
|
|
354 (if (and mime::article/preview-buffer
|
|
355 (setq buf (get-buffer mime::article/preview-buffer))
|
|
356 )
|
|
357 (progn
|
|
358 (switch-to-buffer the-buf)
|
|
359 (kill-buffer buf)
|
|
360 )
|
|
361 (switch-to-buffer the-buf)
|
|
362 )
|
|
363 ))))
|
|
364
|
|
365 (add-hook 'mh-before-quit-hook (function tm-mh-e/summary-before-quit))
|
|
366
|
|
367
|
|
368 ;;; @@ for tmh-comp.el
|
|
369 ;;;
|
|
370
|
|
371 (autoload 'tm-mh-e/edit-again "tmh-comp"
|
|
372 "Clean-up a draft or a message previously sent and make it resendable." t)
|
|
373 (autoload 'tm-mh-e/extract-rejected-mail "tmh-comp"
|
|
374 "Extract a letter returned by the mail system and make it re-editable." t)
|
|
375 (autoload 'tm-mh-e/forward "tmh-comp"
|
|
376 "Forward a message or message sequence by MIME style." t)
|
|
377
|
|
378 (call-after-loaded
|
|
379 'mime-setup
|
|
380 (function
|
|
381 (lambda ()
|
|
382 (substitute-key-definition
|
|
383 'mh-edit-again 'tm-mh-e/edit-again mh-folder-mode-map)
|
|
384 (substitute-key-definition
|
|
385 'mh-extract-rejected-mail 'tm-mh-e/extract-rejected-mail
|
|
386 mh-folder-mode-map)
|
|
387 (substitute-key-definition
|
|
388 'mh-forward 'tm-mh-e/forward mh-folder-mode-map)
|
|
389
|
|
390 (call-after-loaded
|
|
391 'mh-comp
|
|
392 (function
|
|
393 (lambda ()
|
|
394 (require 'tmh-comp)
|
|
395 ))
|
|
396 'mh-letter-mode-hook)
|
|
397 )))
|
|
398
|
|
399
|
|
400 ;;; @ for BBDB
|
|
401 ;;;
|
|
402
|
|
403 (call-after-loaded
|
|
404 'bbdb
|
|
405 (function
|
|
406 (lambda ()
|
|
407 (require 'tm-bbdb)
|
|
408 )))
|
|
409
|
|
410
|
|
411 ;;; @ end
|
|
412 ;;;
|
|
413
|
|
414 (provide 'tm-mh-e)
|
|
415
|
|
416 (run-hooks 'tm-mh-e-load-hook)
|
|
417
|
|
418 ;;; tm-mh-e.el ends here
|