4
|
1 ;;; tm-vm.el --- tm-MUA (MIME Extension module) for VM
|
|
2
|
|
3 ;; Copyright (C) 1994,1995,1996 Free Software Foundation, Inc.
|
|
4
|
|
5 ;; Author: MASUTANI Yasuhiro <masutani@me.es.osaka-u.ac.jp>
|
|
6 ;; Kenji Wakamiya <wkenji@flab.fujitsu.co.jp>
|
|
7 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
|
|
8 ;; Shuhei KOBAYASHI <shuhei-k@jaist.ac.jp>
|
|
9 ;; Oscar Figueiredo <Oscar.Figueiredo@di.epfl.ch>
|
|
10 ;; Maintainer: Oscar Figueiredo <Oscar.Figueiredo@di.epfl.ch>
|
|
11 ;; Created: 1994/10/29
|
16
|
12 ;; Version: $Revision: 1.3 $
|
4
|
13 ;; Keywords: mail, MIME, multimedia, multilingual, encoded-word
|
|
14
|
|
15 ;; This file is part of tm (Tools for MIME).
|
|
16
|
|
17 ;; This program is free software; you can redistribute it and/or
|
|
18 ;; modify it under the terms of the GNU General Public License as
|
|
19 ;; published by the Free Software Foundation; either version 2, or (at
|
|
20 ;; your option) any later version.
|
|
21
|
|
22 ;; This program is distributed in the hope that it will be useful, but
|
|
23 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
24 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
25 ;; General Public License for more details.
|
|
26
|
|
27 ;; You should have received a copy of the GNU General Public License
|
|
28 ;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
29 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
30 ;; Boston, MA 02111-1307, USA.
|
|
31
|
|
32 ;;; Commentary:
|
|
33
|
|
34 ;; Plese insert `(require 'tm-vm)' in your ~/.vm file.
|
|
35
|
|
36 ;;; Code:
|
|
37
|
8
|
38 (eval-when-compile
|
|
39 (require 'tm-edit)
|
|
40 (require 'tm-mail)
|
|
41 (require 'vm)
|
|
42 (require 'vm-window))
|
|
43
|
4
|
44 (require 'tm-view)
|
16
|
45 (require 'vm-menu)
|
|
46
|
|
47
|
|
48 ;;; @ Variables
|
|
49
|
|
50 ;;; @@ User customization variables
|
|
51
|
|
52 (defvar tm-vm/use-vm-bindings t
|
|
53 "*If t, use VM compatible keybindings in MIME Preview buffers.
|
|
54 Otherwise TM generic bindings for content extraction/playing are
|
|
55 made available.")
|
|
56
|
|
57 (defvar tm-vm/attach-to-popup-menus t
|
|
58 "*If t append MIME specific commands to VM's popup menus.")
|
|
59
|
|
60 (defvar tm-vm/use-original-url-button nil
|
|
61 "*If it is t, use original URL button instead of tm's.")
|
|
62
|
|
63 (defvar tm-vm/automatic-mime-preview t
|
|
64 "*If non-nil, automatically process and show MIME messages.")
|
|
65
|
|
66 (defvar tm-vm/strict-mime t
|
|
67 "*If nil, do MIME processing even if there is no MIME-Version field.")
|
|
68
|
|
69 (defvar tm-vm/use-ps-print (not (featurep 'mule))
|
|
70 "*Use Postscript printing (ps-print) to print MIME messages.")
|
|
71
|
|
72 (defvar tm-vm-load-hook nil
|
|
73 "*List of functions called after tm-vm is loaded.")
|
|
74
|
|
75 (defvar tm-vm/select-message-hook nil
|
|
76 "*List of functions called every time a message is selected.
|
|
77 tm-vm uses `vm-select-message-hook', use tm-vm/select-message-hook instead.
|
|
78 When the hooks are run current buffer is either VM folder buffer with
|
|
79 the current message delimited by (point-min) and (point-max) or the MIME
|
|
80 Preview buffer.")
|
|
81
|
|
82 (defvar tm-vm/forward-message-hook vm-forward-message-hook
|
|
83 "*List of functions called after a Mail mode buffer has been
|
|
84 created to forward a message in message/rfc822 type format.
|
|
85 If `vm-forwarding-digest-type' is \"rfc1521\", tm-vm runs this
|
|
86 hook instead of `vm-forward-message-hook'.")
|
|
87
|
|
88 (defvar tm-vm/send-digest-hook nil
|
|
89 "*List of functions called after a Mail mode buffer has been
|
|
90 created to send a digest in multipart/digest type format.
|
|
91 If `vm-digest-send-type' is \"rfc1521\", tm-vm runs this hook
|
|
92 instead of `vm-send-digest-hook'.")
|
|
93
|
|
94
|
|
95 ;;; @@ System/Information variables
|
4
|
96
|
|
97 (defconst tm-vm/RCS-ID
|
16
|
98 "$Id: tm-vm.el,v 1.3 1997/02/02 05:06:20 steve Exp $")
|
4
|
99 (defconst tm-vm/version (get-version-string tm-vm/RCS-ID))
|
|
100
|
16
|
101 (defvar tm-vm/vm-emulation-map
|
|
102 (let ((map (make-sparse-keymap)))
|
|
103 (define-key map "h" 'vm-summarize)
|
|
104 ;(define-key map "\M-n" 'vm-next-unread-message)
|
|
105 ;(define-key map "\M-p" 'vm-previous-unread-message)
|
|
106 (define-key map "n" 'vm-next-message)
|
|
107 (define-key map "p" 'vm-previous-message)
|
|
108 (define-key map "N" 'vm-next-message-no-skip)
|
|
109 (define-key map "P" 'vm-previous-message-no-skip)
|
|
110 ;(define-key map "\C-\M-n" 'vm-move-message-forward)
|
|
111 ;(define-key map "\C-\M-p" 'vm-move-message-backward)
|
|
112 ;(define-key map "\t" 'vm-goto-message-last-seen)
|
|
113 ;(define-key map "\r" 'vm-goto-message)
|
|
114 ;(define-key map "^" 'vm-goto-parent-message)
|
|
115 (define-key map "t" 'vm-expose-hidden-headers)
|
|
116 (define-key map " " 'vm-scroll-forward)
|
|
117 (define-key map "b" 'vm-scroll-backward)
|
|
118 (define-key map "\C-?" 'vm-scroll-backward)
|
|
119 ;(define-key map "d" 'vm-delete-message)
|
|
120 ;(define-key map "\C-d" 'vm-delete-message-backward)
|
|
121 ;(define-key map "u" 'vm-undelete-message)
|
|
122 ;(define-key map "U" 'vm-unread-message)
|
|
123 ;(define-key map "e" 'vm-edit-message)
|
|
124 ;(define-key map "a" 'vm-set-message-attributes)
|
|
125 ;(define-key map "j" 'vm-discard-cached-data)
|
|
126 ;(define-key map "k" 'vm-kill-subject)
|
|
127 (define-key map "f" 'vm-followup)
|
|
128 (define-key map "F" 'vm-followup-include-text)
|
|
129 (define-key map "r" 'vm-reply)
|
|
130 (define-key map "R" 'vm-reply-include-text)
|
|
131 (define-key map "\M-r" 'vm-resend-bounced-message)
|
|
132 (define-key map "B" 'vm-resend-message)
|
|
133 (define-key map "z" 'vm-forward-message)
|
|
134 ;(define-key map "c" 'vm-continue-composing-message)
|
|
135 (define-key map "@" 'vm-send-digest)
|
|
136 ;(define-key map "*" 'vm-burst-digest)
|
|
137 (define-key map "m" 'vm-mail)
|
|
138 (define-key map "g" 'vm-get-new-mail)
|
|
139 ;(define-key map "G" 'vm-sort-messages)
|
|
140 (define-key map "v" 'vm-visit-folder)
|
|
141 ;(define-key map "s" 'vm-save-message)
|
|
142 ;(define-key map "w" 'vm-save-message-sans-headers)
|
|
143 ;(define-key map "A" 'vm-auto-archive-messages)
|
|
144 ;(define-key map "S" 'vm-save-folder)
|
|
145 ;(define-key map "|" 'vm-pipe-message-to-command)
|
|
146 ;(define-key map "#" 'vm-expunge-folder)
|
|
147 (define-key map "q" 'vm-quit)
|
|
148 (define-key map "x" 'vm-quit-no-change)
|
|
149 (define-key map "i" 'vm-iconify-frame)
|
|
150 (define-key map "?" 'vm-help)
|
|
151 (define-key map "\C-_" 'vm-undo)
|
|
152 (define-key map "\C-xu" 'vm-undo)
|
|
153 (define-key map "!" 'shell-command)
|
|
154 (define-key map "<" 'vm-beginning-of-message)
|
|
155 (define-key map ">" 'vm-end-of-message)
|
|
156 ;(define-key map "\M-s" 'vm-isearch-forward)
|
|
157 (define-key map "=" 'vm-summarize)
|
|
158 ;(define-key map "L" 'vm-load-init-file)
|
|
159 ;(define-key map "l" (make-sparse-keymap))
|
|
160 ;(define-key map "la" 'vm-add-message-labels)
|
|
161 ;(define-key map "ld" 'vm-delete-message-labels)
|
|
162 ;(define-key map "V" (make-sparse-keymap))
|
|
163 ;(define-key map "VV" 'vm-visit-virtual-folder)
|
|
164 ;(define-key map "VC" 'vm-create-virtual-folder)
|
|
165 ;(define-key map "VA" 'vm-apply-virtual-folder)
|
|
166 ;(define-key map "VM" 'vm-toggle-virtual-mirror)
|
|
167 ;(define-key map "V?" 'vm-virtual-help)
|
|
168 ;(define-key map "M" (make-sparse-keymap))
|
|
169 ;(define-key map "MN" 'vm-next-command-uses-marks)
|
|
170 ;(define-key map "Mn" 'vm-next-command-uses-marks)
|
|
171 ;(define-key map "MM" 'vm-mark-message)
|
|
172 ;(define-key map "MU" 'vm-unmark-message)
|
|
173 ;(define-key map "Mm" 'vm-mark-all-messages)
|
|
174 ;(define-key map "Mu" 'vm-clear-all-marks)
|
|
175 ;(define-key map "MC" 'vm-mark-matching-messages)
|
|
176 ;(define-key map "Mc" 'vm-unmark-matching-messages)
|
|
177 ;(define-key map "MT" 'vm-mark-thread-subtree)
|
|
178 ;(define-key map "Mt" 'vm-unmark-thread-subtree)
|
|
179 ;(define-key map "MS" 'vm-mark-messages-same-subject)
|
|
180 ;(define-key map "Ms" 'vm-unmark-messages-same-subject)
|
|
181 ;(define-key map "MA" 'vm-mark-messages-same-author)
|
|
182 ;(define-key map "Ma" 'vm-unmark-messages-same-author)
|
|
183 ;(define-key map "M?" 'vm-mark-help)
|
|
184 ;(define-key map "W" (make-sparse-keymap))
|
|
185 ;(define-key map "WW" 'vm-apply-window-configuration)
|
|
186 ;(define-key map "WS" 'vm-save-window-configuration)
|
|
187 ;(define-key map "WD" 'vm-delete-window-configuration)
|
|
188 ;(define-key map "W?" 'vm-window-help)
|
|
189 ;(define-key map "\C-t" 'vm-toggle-threads-display)
|
|
190 ;(define-key map "\C-x\C-s" 'vm-save-buffer)
|
|
191 ;(define-key map "\C-x\C-w" 'vm-write-file)
|
|
192 ;(define-key map "\C-x\C-q" 'vm-toggle-read-only)
|
|
193 ;(define-key map "%" 'vm-change-folder-type)
|
|
194 ;(define-key map "\M-C" 'vm-show-copying-restrictions)
|
|
195 ;(define-key map "\M-W" 'vm-show-no-warranty)
|
|
196 ;; suppress-keymap provides these, but now that we don't use
|
|
197 ;; suppress-keymap anymore...
|
|
198 (define-key map "0" 'digit-argument)
|
|
199 (define-key map "1" 'digit-argument)
|
|
200 (define-key map "2" 'digit-argument)
|
|
201 (define-key map "3" 'digit-argument)
|
|
202 (define-key map "4" 'digit-argument)
|
|
203 (define-key map "5" 'digit-argument)
|
|
204 (define-key map "6" 'digit-argument)
|
|
205 (define-key map "7" 'digit-argument)
|
|
206 (define-key map "8" 'digit-argument)
|
|
207 (define-key map "9" 'digit-argument)
|
|
208 (define-key map "-" 'negative-argument)
|
|
209 (if mouse-button-2
|
|
210 (define-key map mouse-button-2 (function tm:button-dispatcher)))
|
|
211 (if (vm-menu-fsfemacs-menus-p)
|
|
212 (progn
|
|
213 (vm-menu-initialize-vm-mode-menu-map)
|
|
214 (define-key map [menu-bar]
|
|
215 (lookup-key vm-mode-menu-map [rootmenu vm]))))
|
|
216 map)
|
|
217 "VM emulation keymap for MIME-Preview buffers.")
|
|
218
|
|
219 (defvar tm-vm/popup-menu
|
|
220 (let (fsfmenu
|
|
221 (dummy (make-sparse-keymap))
|
|
222 (menu (append vm-menu-dispose-menu
|
|
223 (list "----"
|
|
224 (cons mime-viewer/menu-title
|
|
225 (mapcar (function
|
|
226 (lambda (item)
|
|
227 (vector (nth 1 item)(nth 2 item) t)))
|
|
228 mime-viewer/menu-list))))))
|
|
229 (if running-xemacs
|
|
230 menu
|
|
231 (vm-easy-menu-define fsfmenu (list dummy) nil menu)
|
|
232 fsfmenu))
|
|
233 "VM's popup menu + MIME specific commands")
|
|
234
|
4
|
235 (define-key vm-mode-map "Z" 'tm-vm/view-message)
|
|
236 (define-key vm-mode-map "T" 'tm-vm/decode-message-header)
|
|
237 (define-key vm-mode-map "\et" 'tm-vm/toggle-preview-mode)
|
|
238
|
|
239
|
16
|
240 ;;; @ MIME encoded-words
|
4
|
241
|
|
242 (defvar tm-vm/use-tm-patch nil
|
|
243 "Does not decode encoded-words in summary buffer if it is t.
|
|
244 If you use tiny-mime patch for VM (by RIKITAKE Kenji
|
|
245 <kenji@reseau.toyonaka.osaka.jp>), please set it t [tm-vm.el]")
|
|
246
|
|
247 (or tm-vm/use-tm-patch
|
|
248 (progn
|
|
249 ;;;
|
|
250 (defvar tm-vm/chop-full-name-function 'tm-vm/default-chop-full-name)
|
|
251 (setq vm-chop-full-name-function tm-vm/chop-full-name-function)
|
|
252
|
|
253 (defun tm-vm/default-chop-full-name (address)
|
|
254 (let* ((ret (vm-default-chop-full-name address))
|
|
255 (full-name (car ret))
|
|
256 )
|
|
257 (if (stringp full-name)
|
|
258 (cons (mime-eword/decode-string full-name)
|
|
259 (cdr ret))
|
|
260 ret)))
|
|
261
|
|
262 (require 'vm-summary)
|
|
263 (or (fboundp 'tm:vm-su-subject)
|
|
264 (fset 'tm:vm-su-subject (symbol-function 'vm-su-subject))
|
|
265 )
|
|
266 (defun vm-su-subject (m)
|
|
267 (mime-eword/decode-string (tm:vm-su-subject m))
|
|
268 )
|
|
269
|
|
270 (or (fboundp 'tm:vm-su-full-name)
|
|
271 (fset 'tm:vm-su-full-name (symbol-function 'vm-su-full-name))
|
|
272 )
|
|
273 (defun vm-su-full-name (m)
|
|
274 (mime-eword/decode-string (tm:vm-su-full-name m))
|
|
275 )
|
|
276
|
|
277 (or (fboundp 'tm:vm-su-to-names)
|
|
278 (fset 'tm:vm-su-to-names (symbol-function 'vm-su-to-names))
|
|
279 )
|
|
280 (defun vm-su-to-names (m)
|
|
281 (mime-eword/decode-string (tm:vm-su-to-names m))
|
|
282 )
|
|
283 ;;;
|
|
284 ))
|
|
285
|
|
286 (defun tm-vm/decode-message-header (&optional count)
|
|
287 "Decode MIME header of current message.
|
|
288 Numeric prefix argument COUNT means to decode the current message plus
|
|
289 the next COUNT-1 messages. A negative COUNT means decode the current
|
|
290 message and the previous COUNT-1 messages.
|
|
291 When invoked on marked messages (via vm-next-command-uses-marks),
|
|
292 all marked messages are affected, other messages are ignored."
|
|
293 (interactive "p")
|
|
294 (or count (setq count 1))
|
|
295 (vm-follow-summary-cursor)
|
|
296 (vm-select-folder-buffer)
|
|
297 (vm-check-for-killed-summary)
|
|
298 (vm-error-if-folder-empty)
|
|
299 (vm-error-if-folder-read-only)
|
|
300 (let ((mlist (vm-select-marked-or-prefixed-messages count))
|
|
301 (realm nil)
|
|
302 (vlist nil)
|
|
303 (vbufs nil))
|
|
304 (save-excursion
|
|
305 (while mlist
|
|
306 (setq realm (vm-real-message-of (car mlist)))
|
|
307 ;; Go to real folder of this message.
|
|
308 ;; But maybe this message is already real message...
|
|
309 (set-buffer (vm-buffer-of realm))
|
|
310 (let ((buffer-read-only nil))
|
|
311 (vm-save-restriction
|
|
312 (narrow-to-region (vm-headers-of realm) (vm-text-of realm))
|
|
313 (mime/decode-message-header))
|
|
314 (let ((vm-message-pointer (list realm))
|
|
315 (last-command nil))
|
|
316 (vm-discard-cached-data))
|
|
317 ;; Mark each virtual and real message for later summary
|
|
318 ;; update.
|
|
319 (setq vlist (cons realm (vm-virtual-messages-of realm)))
|
|
320 (while vlist
|
|
321 (vm-mark-for-summary-update (car vlist))
|
|
322 ;; Remember virtual and real folders related this message,
|
|
323 ;; for later display update.
|
|
324 (or (memq (vm-buffer-of (car vlist)) vbufs)
|
|
325 (setq vbufs (cons (vm-buffer-of (car vlist)) vbufs)))
|
|
326 (setq vlist (cdr vlist)))
|
|
327 (if (eq vm-flush-interval t)
|
|
328 (vm-stuff-virtual-attributes realm)
|
|
329 (vm-set-modflag-of realm t)))
|
|
330 (setq mlist (cdr mlist)))
|
|
331 ;; Update mail-buffers and summaries.
|
|
332 (while vbufs
|
|
333 (set-buffer (car vbufs))
|
|
334 (vm-preview-current-message)
|
|
335 (setq vbufs (cdr vbufs))))))
|
|
336
|
|
337 (defun tm-vm/header-filter ()
|
16
|
338 "Filter headers in current buffer according to vm-visible-headers and vm-invisible-header-regexp.
|
|
339 Current buffer is assumed to have a message-like structure."
|
4
|
340 (goto-char (point-min))
|
|
341 (let ((visible-headers vm-visible-headers))
|
|
342 (if (or vm-use-lucid-highlighting
|
|
343 vm-display-xfaces)
|
|
344 (setq visible-headers (cons "X-Face:" vm-visible-headers)))
|
|
345 (vm-reorder-message-headers nil
|
|
346 visible-headers
|
|
347 vm-invisible-header-regexp)
|
|
348 (mime/decode-message-header)))
|
|
349
|
16
|
350 (setq mime-viewer/content-header-filter-alist
|
|
351 (append '((vm-mode . tm-vm/header-filter)
|
|
352 (vm-virtual-mode . tm-vm/header-filter))
|
|
353 mime-viewer/content-header-filter-alist))
|
|
354
|
|
355
|
|
356
|
|
357 ;;; @ MIME Viewer
|
|
358
|
|
359 ;;; @@ MIME-Preview buffer management
|
|
360
|
|
361 (defvar tm-vm/system-state nil)
|
|
362
|
4
|
363 (defun tm-vm/system-state ()
|
|
364 (save-excursion
|
|
365 (if mime::preview/article-buffer
|
|
366 (set-buffer mime::preview/article-buffer)
|
|
367 (vm-select-folder-buffer))
|
|
368 tm-vm/system-state))
|
|
369
|
16
|
370 (defun tm-vm/build-preview-buffer ()
|
|
371 "Build the MIME Preview buffer for the current VM message.
|
|
372 Current buffer should be VM's folder buffer."
|
|
373
|
|
374 (set (make-local-variable 'tm-vm/system-state) 'mime-viewing)
|
|
375 (setq vm-system-state 'reading)
|
|
376
|
|
377 ;; Update message flags and store them in folder buffer before
|
|
378 ;; entering MIME viewer
|
|
379 (tm-vm/update-message-status)
|
|
380
|
|
381 ;; We need to save window configuration because we may be working
|
|
382 ;; in summary window
|
|
383 (save-window-excursion
|
|
384 (save-restriction
|
|
385 (save-excursion
|
|
386 (widen)
|
|
387 (goto-char (vm-start-of (car vm-message-pointer)))
|
|
388 (forward-line)
|
|
389 (narrow-to-region (point)
|
|
390 (vm-end-of (car vm-message-pointer)))
|
|
391
|
|
392 (let ((ml vm-message-list))
|
|
393 (mime/viewer-mode nil nil nil nil nil nil)
|
|
394 (setq vm-mail-buffer mime::preview/article-buffer)
|
|
395 (setq vm-message-list ml))
|
|
396 ;; Install VM toolbar for MIME-Preview buffer if not installed
|
|
397 (tm-vm/check-for-toolbar)
|
|
398 (if tm-vm/use-vm-bindings
|
|
399 (progn
|
|
400 (define-key tm-vm/vm-emulation-map "\C-c" (current-local-map))
|
|
401 (use-local-map tm-vm/vm-emulation-map)
|
|
402 (vm-menu-install-menubar)
|
|
403 (if (and vm-use-menus
|
|
404 (vm-menu-support-possible-p))
|
|
405 (setq mode-popup-menu tm-vm/popup-menu))))
|
|
406
|
|
407 ;; Highlight message (and display XFace if supported)
|
|
408 (if (or vm-highlighted-header-regexp
|
|
409 (and (vm-xemacs-p) vm-use-lucid-highlighting))
|
|
410 (vm-highlight-headers))
|
|
411 ;; Energize URLs and buttons
|
|
412 (if (and tm-vm/use-original-url-button
|
|
413 vm-use-menus (vm-menu-support-possible-p))
|
|
414 (progn
|
|
415 (vm-energize-urls)
|
|
416 (vm-energize-headers)))))))
|
|
417
|
4
|
418 (defun tm-vm/sync-preview-buffer ()
|
16
|
419 "Ensure that the MIME preview buffer, if it exists, actually corresponds to the current message.
|
|
420 If no MIME Preview buffer is needed then kill it. If no
|
4
|
421 MIME Preview buffer exists nothing is done."
|
|
422 ;; Current buffer should be message buffer when calling this function
|
|
423 (let* ((mbuf (current-buffer))
|
|
424 (pbuf (and mime::article/preview-buffer
|
16
|
425 (get-buffer mime::article/preview-buffer))))
|
4
|
426 (if pbuf
|
16
|
427 ;; A MIME Preview buffer exists then it may need to be synch'ed
|
|
428 (save-excursion
|
|
429 (set-buffer mbuf)
|
|
430 (if (and tm-vm/strict-mime
|
|
431 (not (vm-get-header-contents (car vm-message-pointer)
|
|
432 "MIME-Version:")))
|
|
433 (progn
|
|
434 (setq mime::article/preview-buffer nil
|
|
435 tm-vm/system-state nil)
|
|
436 (if pbuf (kill-buffer pbuf)))
|
|
437 (tm-vm/build-preview-buffer)))
|
4
|
438 ;; Return to previous frame
|
16
|
439 )))
|
|
440
|
|
441 (defun tm-vm/toggle-preview-mode ()
|
|
442 "Toggle automatic MIME preview on or off.
|
|
443 In automatic MIME Preview mode each newly selected article is MIME processed if
|
|
444 it has MIME content without need for an explicit request from the user. This
|
|
445 behaviour is controlled by the variable tm-vm/automatic-mime-preview."
|
|
446
|
|
447 (interactive)
|
|
448 (if tm-vm/automatic-mime-preview
|
|
449 (progn
|
|
450 (tm-vm/quit-view-message)
|
|
451 (setq tm-vm/automatic-mime-preview nil)
|
|
452 (message "Automatic MIME Preview is now disabled."))
|
|
453 ;; Enable Automatic MIME Preview
|
|
454 (tm-vm/view-message)
|
|
455 (setq tm-vm/automatic-mime-preview t)
|
|
456 (message "Automatic MIME Preview is now enabled.")
|
|
457 ))
|
|
458
|
|
459 ;;; @@ Display functions
|
|
460
|
|
461 (defun tm-vm/update-message-status ()
|
|
462 "Update current message display and summary.
|
|
463 Remove 'unread' and 'new' flags. The MIME Preview buffer is not displayed,
|
|
464 tm-vm/display-preview-buffer should be called for that. This function is
|
|
465 display-configuration safe."
|
|
466 (if mime::preview/article-buffer
|
|
467 (set-buffer mime::preview/article-buffer)
|
|
468 (vm-select-folder-buffer))
|
|
469 (if (or (and mime::article/preview-buffer
|
|
470 (get-buffer mime::article/preview-buffer)
|
|
471 (vm-get-visible-buffer-window mime::article/preview-buffer))
|
|
472 (vm-get-visible-buffer-window (current-buffer)))
|
|
473 (progn
|
|
474 (if (vm-new-flag (car vm-message-pointer))
|
|
475 (vm-set-new-flag (car vm-message-pointer) nil))
|
|
476 (if (vm-unread-flag (car vm-message-pointer))
|
|
477 (vm-set-unread-flag (car vm-message-pointer) nil))
|
|
478 (vm-update-summary-and-mode-line)
|
|
479 (tm-vm/howl-if-eom))
|
|
480 (vm-update-summary-and-mode-line)))
|
4
|
481
|
|
482 (defun tm-vm/display-preview-buffer ()
|
16
|
483 "Replace the VM message buffer with the MIME-Preview buffer if the VM message buffer is currently displayed or undisplay it if tm-vm/system-state is nil."
|
4
|
484 (let* ((mbuf (current-buffer))
|
|
485 (mwin (vm-get-visible-buffer-window mbuf))
|
|
486 (pbuf (and mime::article/preview-buffer
|
|
487 (get-buffer mime::article/preview-buffer)))
|
|
488 (pwin (and pbuf (vm-get-visible-buffer-window pbuf))))
|
|
489 (if (and pbuf (tm-vm/system-state))
|
16
|
490 ;; display preview buffer if preview-buffer exists
|
4
|
491 (cond
|
|
492 ((and mwin pwin)
|
|
493 (vm-undisplay-buffer mbuf)
|
16
|
494 (tm-vm/update-message-status))
|
4
|
495 ((and mwin (not pwin))
|
|
496 (set-window-buffer mwin pbuf)
|
16
|
497 (tm-vm/update-message-status))
|
4
|
498 (pwin
|
16
|
499 (tm-vm/update-message-status))
|
4
|
500 (t
|
|
501 ;; don't display if neither mwin nor pwin was displayed before.
|
|
502 ))
|
|
503 ;; display folder buffer
|
|
504 (cond
|
|
505 ((and mwin pwin)
|
|
506 (vm-undisplay-buffer pbuf))
|
|
507 ((and (not mwin) pwin)
|
|
508 (set-window-buffer pwin mbuf))
|
|
509 (mwin
|
|
510 ;; folder buffer is already displayed.
|
|
511 )
|
|
512 (t
|
|
513 ;; don't display if neither mwin nor pwin was displayed before.
|
|
514 )))
|
16
|
515 (set-buffer mbuf)))
|
4
|
516
|
|
517 (defun tm-vm/preview-current-message ()
|
16
|
518 "Either preview message (view first lines only) or MIME-Preview it.
|
|
519 The message is previewed if message previewing is enabled see vm-preview-lines.
|
|
520 If not, MIME-Preview current message (ie. parse MIME
|
|
521 contents and display appropriately) if it has MIME contents and
|
|
522 tm-vm/automatic-mime-preview is non nil. Installed on vm-visit-folder-hook and
|
|
523 vm-select-message-hook."
|
4
|
524 ;; assumed current buffer is folder buffer.
|
|
525 (setq tm-vm/system-state nil)
|
|
526 (if (get-buffer mime/output-buffer-name)
|
|
527 (vm-undisplay-buffer mime/output-buffer-name))
|
16
|
528 (if (and vm-message-pointer
|
|
529 tm-vm/automatic-mime-preview
|
|
530 (or (null vm-preview-lines)
|
|
531 (not (eq vm-system-state 'previewing))
|
|
532 (and (not vm-preview-read-messages)
|
|
533 (not (vm-new-flag (car vm-message-pointer)))
|
|
534 (not (vm-unread-flag (car vm-message-pointer))))))
|
4
|
535 (if (or (not tm-vm/strict-mime)
|
|
536 (vm-get-header-contents (car vm-message-pointer)
|
|
537 "MIME-Version:"))
|
|
538 ;; do MIME processing.
|
16
|
539 (progn
|
|
540 (tm-vm/build-preview-buffer)
|
|
541 (save-excursion
|
|
542 (set-buffer mime::article/preview-buffer)
|
|
543 (run-hooks 'tm-vm/select-message-hook)))
|
4
|
544 ;; don't do MIME processing. decode header only.
|
|
545 (let (buffer-read-only)
|
16
|
546 (mime/decode-message-header)
|
|
547 (run-hooks 'tm-vm/select-message-hook))
|
4
|
548 )
|
|
549 ;; don't preview; do nothing.
|
16
|
550 (run-hooks 'tm-vm/select-message-hook))
|
|
551 (tm-vm/display-preview-buffer))
|
|
552
|
|
553 (defun tm-vm/view-message ()
|
|
554 "Decode and view the current VM message as a MIME encoded message.
|
|
555 A MIME Preview buffer using mime/viewer-mode is created.
|
|
556 See mime/viewer-mode for more information"
|
|
557 (interactive)
|
|
558 (vm-follow-summary-cursor)
|
|
559 (vm-select-folder-buffer)
|
|
560 (vm-check-for-killed-summary)
|
|
561 (vm-error-if-folder-empty)
|
|
562 (vm-display (current-buffer) t '(tm-vm/view-message
|
|
563 tm-vm/toggle-preview-mode)
|
|
564 '(tm-vm/view-message reading-message))
|
|
565 (let ((tm-vm/automatic-mime-preview t))
|
|
566 (tm-vm/preview-current-message))
|
|
567 )
|
4
|
568
|
16
|
569 (defun tm-vm/quit-view-message ()
|
|
570 "Quit MIME-Viewer and go back to normal VM.
|
|
571 MIME Preview buffer is killed. This function is called by `mime-viewer/quit'
|
|
572 command via `mime-viewer/quitting-method-alist'."
|
|
573 (if (get-buffer mime/output-buffer-name)
|
|
574 (vm-undisplay-buffer mime/output-buffer-name))
|
|
575 (vm-select-folder-buffer)
|
|
576 (let* ((mbuf (current-buffer))
|
|
577 (pbuf (and mime::article/preview-buffer
|
|
578 (get-buffer mime::article/preview-buffer)))
|
|
579 (pwin (and pbuf (vm-get-visible-buffer-window pbuf))))
|
|
580 (if pbuf (kill-buffer pbuf))
|
|
581 (and pwin
|
|
582 (select-window pwin)
|
|
583 (switch-to-buffer mbuf)))
|
|
584 (setq tm-vm/system-state nil)
|
|
585 (vm-display (current-buffer) t (list this-command)
|
|
586 (list 'reading-message)))
|
4
|
587
|
|
588 (add-hook 'vm-select-message-hook 'tm-vm/preview-current-message)
|
|
589 (add-hook 'vm-visit-folder-hook 'tm-vm/preview-current-message)
|
|
590
|
|
591
|
|
592
|
|
593
|
16
|
594
|
|
595 ;;; @@ for tm-view
|
4
|
596
|
|
597 ;;; based on vm-do-reply [vm-reply.el]
|
|
598 (defun tm-vm/do-reply (buf to-all include-text)
|
|
599 (save-excursion
|
|
600 (set-buffer buf)
|
|
601 (let ((dir default-directory)
|
16
|
602 to cc subject in-reply-to references newsgroups)
|
4
|
603 (cond ((setq to
|
|
604 (let ((reply-to (std11-field-body "Reply-To")))
|
|
605 (if (vm-ignored-reply-to reply-to)
|
|
606 nil
|
|
607 reply-to))))
|
|
608 ((setq to (std11-field-body "From")))
|
|
609 ;; (t (error "No From: or Reply-To: header in message"))
|
|
610 )
|
|
611 (if to-all
|
|
612 (setq cc (delq nil (cons cc (std11-field-bodies '("To" "Cc"))))
|
|
613 cc (mapconcat 'identity cc ","))
|
|
614 )
|
|
615 (setq subject (std11-field-body "Subject"))
|
|
616 (and subject vm-reply-subject-prefix
|
|
617 (let ((case-fold-search t))
|
|
618 (not
|
|
619 (equal
|
|
620 (string-match (regexp-quote vm-reply-subject-prefix)
|
|
621 subject)
|
|
622 0)))
|
|
623 (setq subject (concat vm-reply-subject-prefix subject)))
|
|
624 (setq in-reply-to (std11-field-body "Message-Id")
|
|
625 references (nconc
|
|
626 (std11-field-bodies '("References" "In-Reply-To"))
|
|
627 (list in-reply-to))
|
|
628 newsgroups (list (or (and to-all
|
|
629 (std11-field-body "Followup-To"))
|
|
630 (std11-field-body "Newsgroups"))))
|
|
631 (setq to (vm-parse-addresses to)
|
|
632 cc (vm-parse-addresses cc))
|
|
633 (if vm-reply-ignored-addresses
|
|
634 (setq to (vm-strip-ignored-addresses to)
|
|
635 cc (vm-strip-ignored-addresses cc)))
|
|
636 (setq to (vm-delete-duplicates to nil t))
|
|
637 (setq cc (vm-delete-duplicates
|
|
638 (append (vm-delete-duplicates cc nil t)
|
|
639 to (copy-sequence to))
|
|
640 t t))
|
|
641 (and to (setq to (mapconcat 'identity to ",\n ")))
|
|
642 (and cc (setq cc (mapconcat 'identity cc ",\n ")))
|
|
643 (and (null to) (setq to cc cc nil))
|
|
644 (setq references (delq nil references)
|
|
645 references (mapconcat 'identity references " ")
|
|
646 references (vm-parse references "[^<]*\\(<[^>]+>\\)")
|
|
647 references (vm-delete-duplicates references)
|
|
648 references (if references (mapconcat 'identity references "\n\t")))
|
|
649 (setq newsgroups (delq nil newsgroups)
|
|
650 newsgroups (mapconcat 'identity newsgroups ",")
|
|
651 newsgroups (vm-parse newsgroups "[ \t\f\r\n,]*\\([^ \t\f\r\n,]+\\)")
|
|
652 newsgroups (vm-delete-duplicates newsgroups)
|
|
653 newsgroups (if newsgroups (mapconcat 'identity newsgroups ",")))
|
|
654 (vm-mail-internal
|
|
655 (if to
|
|
656 (format "reply to %s%s"
|
|
657 (std11-full-name-string
|
|
658 (car (std11-parse-address-string to)))
|
|
659 (if cc ", ..." "")))
|
|
660 to subject in-reply-to cc references newsgroups)
|
|
661 (setq mail-reply-buffer buf
|
|
662 ;; vm-system-state 'replying
|
|
663 default-directory dir))
|
|
664 (if include-text
|
|
665 (save-excursion
|
|
666 (goto-char (point-min))
|
|
667 (let ((case-fold-search nil))
|
|
668 (re-search-forward
|
|
669 (concat "^" (regexp-quote mail-header-separator) "$") nil 0))
|
|
670 (forward-char 1)
|
|
671 (tm-vm/yank-content)))
|
|
672 (run-hooks 'vm-reply-hook)
|
|
673 (run-hooks 'vm-mail-mode-hook)
|
|
674 ))
|
|
675
|
|
676 (defun tm-vm/following-method (buf)
|
|
677 (tm-vm/do-reply buf 'to-all 'include-text)
|
|
678 )
|
|
679
|
|
680 (defun tm-vm/yank-content ()
|
|
681 (interactive)
|
|
682 (let ((this-command 'vm-yank-message))
|
|
683 (vm-display nil nil '(vm-yank-message)
|
|
684 '(vm-yank-message composing-message))
|
|
685 (save-restriction
|
|
686 (narrow-to-region (point)(point))
|
|
687 (insert-buffer mail-reply-buffer)
|
|
688 (goto-char (point-max))
|
|
689 (push-mark)
|
|
690 (goto-char (point-min)))
|
|
691 (cond (mail-citation-hook (run-hooks 'mail-citation-hook))
|
|
692 (mail-yank-hooks (run-hooks 'mail-yank-hooks))
|
|
693 (t (mail-indent-citation)))
|
|
694 ))
|
|
695
|
|
696 (set-alist 'mime-viewer/following-method-alist
|
|
697 'vm-mode
|
|
698 (function tm-vm/following-method))
|
|
699 (set-alist 'mime-viewer/following-method-alist
|
|
700 'vm-virtual-mode
|
|
701 (function tm-vm/following-method))
|
|
702
|
|
703
|
|
704 (set-alist 'mime-viewer/quitting-method-alist
|
|
705 'vm-mode
|
|
706 'tm-vm/quit-view-message)
|
|
707
|
|
708 (set-alist 'mime-viewer/quitting-method-alist
|
|
709 'vm-virtual-mode
|
|
710 'tm-vm/quit-view-message)
|
|
711
|
16
|
712 ;;; @@ Motion commands
|
4
|
713
|
16
|
714 (defmacro tm-vm/save-window-excursion (&rest forms)
|
|
715 (list 'let '((tm-vm/selected-window (selected-window)))
|
|
716 (list 'unwind-protect
|
|
717 (cons 'progn forms)
|
|
718 '(if (window-live-p tm-vm/selected-window)
|
|
719 (select-window tm-vm/selected-window)))))
|
|
720
|
|
721 (defmacro tm-vm/save-frame-excursion (&rest forms)
|
|
722 (list 'let '((tm-vm/selected-frame (vm-selected-frame)))
|
|
723 (list 'unwind-protect
|
|
724 (cons 'progn forms)
|
|
725 '(if (frame-live-p tm-vm/selected-frame)
|
|
726 (vm-select-frame tm-vm/selected-frame)))))
|
|
727
|
|
728 (defadvice vm-scroll-forward (around tm-aware activate)
|
|
729 "Made TM-aware (handles the MIME-Preview buffer)."
|
|
730 (if (and
|
|
731 (not (save-excursion
|
|
732 (if mime::preview/article-buffer
|
|
733 (set-buffer mime::preview/article-buffer))
|
|
734 (vm-select-folder-buffer)
|
|
735 (eq vm-system-state 'previewing)))
|
|
736 (not (tm-vm/system-state)))
|
|
737 (progn
|
|
738 ad-do-it
|
|
739 (tm-vm/display-preview-buffer))
|
|
740 (let* ((mp-changed (vm-follow-summary-cursor))
|
|
741 (mbuf (or (vm-select-folder-buffer) (current-buffer)))
|
|
742 (mwin (vm-get-buffer-window mbuf))
|
|
743 (pbuf (and mime::article/preview-buffer
|
|
744 (get-buffer mime::article/preview-buffer)))
|
|
745 (pwin (and pbuf (vm-get-buffer-window pbuf)))
|
|
746 )
|
|
747 (vm-check-for-killed-summary)
|
|
748 (vm-error-if-folder-empty)
|
|
749 (cond
|
|
750 ; A new message was selected
|
|
751 ; => leave it to tm-vm/preview-current-message
|
|
752 (mp-changed
|
|
753 nil)
|
|
754 ((eq vm-system-state 'previewing)
|
|
755 (vm-display (current-buffer) t (list this-command) '(reading-message))
|
|
756 (vm-show-current-message)
|
|
757 (tm-vm/preview-current-message))
|
|
758 ; Preview buffer was killed
|
|
759 ((null pbuf)
|
|
760 (tm-vm/preview-current-message))
|
|
761 ; Preview buffer was undisplayed
|
|
762 ((null pwin)
|
|
763 (if (null mwin)
|
|
764 (vm-display mbuf t '(vm-scroll-forward vm-scroll-backward)
|
|
765 (list this-command 'reading-message)))
|
|
766 (tm-vm/display-preview-buffer))
|
|
767 ; Preview buffer is displayed => scroll
|
|
768 (t
|
|
769 (tm-vm/save-window-excursion
|
|
770 (select-window pwin)
|
|
771 (set-buffer pbuf)
|
|
772 (if (pos-visible-in-window-p (point-max) pwin)
|
|
773 (vm-next-message)
|
|
774 ;; not at the end of message. scroll preview buffer only.
|
|
775 (scroll-up)
|
|
776 (tm-vm/howl-if-eom))
|
|
777 ))))
|
|
778 )
|
|
779 )
|
|
780
|
|
781 (defadvice vm-scroll-backward (around tm-aware activate)
|
|
782 "Made TM-aware (handles the MIME-Preview buffer)."
|
|
783 (if (and
|
|
784 (not (save-excursion
|
|
785 (if mime::preview/article-buffer
|
|
786 (set-buffer mime::preview/article-buffer))
|
|
787 (vm-select-folder-buffer)
|
|
788 (eq vm-system-state 'previewing)))
|
|
789 (not (tm-vm/system-state)))
|
|
790 ad-do-it
|
|
791 (let* ((mp-changed (vm-follow-summary-cursor))
|
|
792 (mbuf (or (vm-select-folder-buffer) (current-buffer)))
|
|
793 (mwin (vm-get-buffer-window mbuf))
|
|
794 (pbuf (and mime::article/preview-buffer
|
|
795 (get-buffer mime::article/preview-buffer)))
|
|
796 (pwin (and pbuf (vm-get-buffer-window pbuf)))
|
|
797 )
|
|
798 (vm-check-for-killed-summary)
|
|
799 (vm-error-if-folder-empty)
|
|
800 (cond
|
|
801 ; A new message was selected
|
|
802 ; => leave it to tm-vm/preview-current-message
|
|
803 (mp-changed
|
|
804 nil)
|
|
805 ((eq vm-system-state 'previewing)
|
|
806 (tm-vm/update-message-status)
|
|
807 (setq vm-system-state 'reading)
|
|
808 (tm-vm/preview-current-message))
|
|
809 ; Preview buffer was killed
|
|
810 ((null pbuf)
|
|
811 (tm-vm/preview-current-message))
|
|
812 ; Preview buffer was undisplayed
|
|
813 ((null pwin)
|
|
814 (if (null mwin)
|
|
815 (vm-display mbuf t '(vm-scroll-forward vm-scroll-backward)
|
|
816 (list this-command 'reading-message)))
|
|
817 (tm-vm/display-preview-buffer))
|
|
818 ; Preview buffer is displayed => scroll
|
|
819 (t
|
|
820 (tm-vm/save-window-excursion
|
|
821 (select-window pwin)
|
|
822 (if (pos-visible-in-window-p (point-min) pwin)
|
|
823 nil
|
|
824 ;; not at the end of message. scroll preview buffer only.
|
|
825 (scroll-down))
|
|
826 ))))
|
|
827 ))
|
|
828
|
|
829 (defadvice vm-beginning-of-message (around tm-aware activate)
|
|
830 "Made TM-aware, works properly in MIME-Preview buffers."
|
|
831 (if (not (tm-vm/system-state))
|
|
832 ad-do-it
|
|
833 (vm-follow-summary-cursor)
|
|
834 (vm-select-folder-buffer)
|
|
835 (vm-check-for-killed-summary)
|
|
836 (vm-error-if-folder-empty)
|
|
837 (let ((mbuf (current-buffer))
|
|
838 (pbuf (and mime::article/preview-buffer
|
|
839 (get-buffer mime::article/preview-buffer))))
|
|
840 (if (null pbuf)
|
|
841 (progn
|
|
842 (tm-vm/preview-current-message)
|
|
843 (setq pbuf (get-buffer mime::article/preview-buffer))
|
|
844 ))
|
|
845 (vm-display mbuf t '(vm-beginning-of-message)
|
|
846 '(vm-beginning-of-message reading-message))
|
|
847 (tm-vm/display-preview-buffer)
|
|
848 (set-buffer pbuf)
|
|
849 (tm-vm/save-window-excursion
|
|
850 (select-window (vm-get-buffer-window pbuf))
|
|
851 (push-mark)
|
|
852 (goto-char (point-min))
|
|
853 ))))
|
|
854
|
|
855 (defadvice vm-end-of-message (around tm-aware activate)
|
|
856 "Made TM-aware, works properly in MIME-Preview buffers."
|
|
857 (interactive)
|
|
858 (if (not (tm-vm/system-state))
|
|
859 ad-do-it
|
|
860 (vm-follow-summary-cursor)
|
|
861 (vm-select-folder-buffer)
|
|
862 (vm-check-for-killed-summary)
|
|
863 (vm-error-if-folder-empty)
|
|
864 (let ((mbuf (current-buffer))
|
|
865 (pbuf (and mime::article/preview-buffer
|
|
866 (get-buffer mime::article/preview-buffer))))
|
|
867 (if (null pbuf)
|
|
868 (progn
|
|
869 (tm-vm/preview-current-message)
|
|
870 (setq pbuf (get-buffer mime::article/preview-buffer))
|
|
871 ))
|
|
872 (vm-display mbuf t '(vm-end-of-message)
|
|
873 '(vm-end-of-message reading-message))
|
|
874 (tm-vm/display-preview-buffer)
|
|
875 (set-buffer pbuf)
|
|
876 (tm-vm/save-window-excursion
|
|
877 (select-window (vm-get-buffer-window pbuf))
|
|
878 (push-mark)
|
|
879 (goto-char (point-max))
|
|
880 ))))
|
|
881
|
|
882 ;;; based on vm-howl-if-eom [vm-page.el]
|
|
883 (defun tm-vm/howl-if-eom ()
|
|
884 (let* ((pbuf (or mime::article/preview-buffer (current-buffer)))
|
|
885 (pwin (and (vm-get-visible-buffer-window pbuf))))
|
|
886 (and pwin
|
|
887 (save-excursion
|
|
888 (save-window-excursion
|
|
889 (condition-case ()
|
|
890 (let ((next-screen-context-lines 0))
|
|
891 (tm-vm/save-frame-excursion
|
|
892 (vm-select-frame (vm-window-frame pwin))
|
|
893 (save-selected-window
|
|
894 (select-window pwin)
|
|
895 (save-excursion
|
|
896 (let ((scroll-in-place-replace-original nil))
|
|
897 (scroll-up)))))
|
|
898 nil)
|
|
899 (error t))))
|
|
900 (vm-emit-eom-blurb)
|
|
901 )))
|
|
902
|
|
903 (defadvice vm-emit-eom-blurb (around tm-aware activate)
|
|
904 "Made TM-aware, works properly in MIME-Preview buffers."
|
|
905 (save-excursion
|
|
906 (if mime::preview/article-buffer
|
|
907 (set-buffer mime::preview/article-buffer))
|
|
908 ad-do-it))
|
|
909
|
|
910 (defadvice vm-next-message (around tm-aware activate)
|
|
911 "Made TM-aware, works properly in MIME-Preview buffers."
|
|
912 (if mime::preview/article-buffer
|
|
913 (set-buffer mime::preview/article-buffer))
|
|
914 (tm-vm/save-window-excursion
|
|
915 ad-do-it))
|
|
916
|
|
917 (defadvice vm-previous-message (around tm-aware activate)
|
|
918 "Made TM-aware, works properly in MIME-Preview buffers."
|
|
919 (if mime::preview/article-buffer
|
|
920 (set-buffer mime::preview/article-buffer))
|
|
921 (tm-vm/save-window-excursion
|
|
922 ad-do-it))
|
|
923
|
|
924 (defadvice vm-next-message-no-skip (around tm-aware activate)
|
|
925 "Made TM-aware, works properly in MIME-Preview buffers."
|
|
926 (if mime::preview/article-buffer
|
|
927 (set-buffer mime::preview/article-buffer))
|
|
928 (tm-vm/save-window-excursion
|
|
929 ad-do-it))
|
|
930
|
|
931 (defadvice vm-previous-message-no-skip (around tm-aware activate)
|
|
932 "TM wrapper for vm-previous-message-no-skip (which see)."
|
|
933 (if mime::preview/article-buffer
|
|
934 (set-buffer mime::preview/article-buffer))
|
|
935 (tm-vm/save-window-excursion
|
|
936 ad-do-it))
|
|
937
|
|
938 (defadvice vm-next-unread-message (around tm-aware activate)
|
|
939 "Made TM-aware, works properly in MIME-Preview buffers."
|
|
940 (if mime::preview/article-buffer
|
|
941 (set-buffer mime::preview/article-buffer))
|
|
942 (tm-vm/save-window-excursion
|
|
943 ad-do-it))
|
|
944
|
|
945 (defadvice vm-previous-unread-message (around tm-aware activate)
|
|
946 "Made TM-aware, works properly in MIME-Preview buffers."
|
|
947 (if mime::preview/article-buffer
|
|
948 (set-buffer mime::preview/article-buffer))
|
|
949 (tm-vm/save-window-excursion
|
|
950 ad-do-it))
|
|
951
|
|
952
|
|
953 (set-alist 'mime-viewer/over-to-previous-method-alist
|
|
954 'vm-mode 'vm-previous-message)
|
|
955 (set-alist 'mime-viewer/over-to-next-method-alist
|
|
956 'vm-mode 'vm-next-message)
|
|
957 (set-alist 'mime-viewer/over-to-previous-method-alist
|
|
958 'vm-virtual-mode 'vm-previous-message)
|
|
959 (set-alist 'mime-viewer/over-to-next-method-alist
|
|
960 'vm-virtual-mode 'vm-next-message)
|
|
961
|
|
962
|
|
963
|
|
964
|
|
965
|
|
966
|
|
967 ;;; @ MIME Editor
|
|
968
|
|
969 ;;; @@ vm-yank-message
|
|
970
|
|
971 (require 'vm-reply)
|
|
972
|
|
973 (defvar tm-vm/yank:message-to-restore nil
|
|
974 "For internal use by tm-vm only.")
|
|
975
|
|
976 (defun vm-yank-message (&optional message)
|
|
977 "Yank message number N into the current buffer at point.
|
|
978 When called interactively N is always read from the minibuffer. When
|
|
979 called non-interactively the first argument is expected to be a
|
|
980 message struct.
|
|
981
|
|
982 This function originally provided by vm-reply has been patched for TM
|
|
983 in order to provide better citation of MIME messages : if a MIME
|
|
984 Preview buffer exists for the message then its contents are inserted
|
|
985 instead of the raw message.
|
|
986
|
|
987 This command is meant to be used in VM created Mail mode buffers; the
|
|
988 yanked message comes from the mail buffer containing the message you
|
|
989 are replying to, forwarding, or invoked VM's mail command from.
|
|
990
|
|
991 All message headers are yanked along with the text. Point is
|
|
992 left before the inserted text, the mark after. Any hook
|
|
993 functions bound to mail-citation-hook are run, after inserting
|
|
994 the text and setting point and mark. For backward compatibility,
|
|
995 if mail-citation-hook is set to nil, `mail-yank-hooks' is run
|
|
996 instead.
|
|
997
|
|
998 If mail-citation-hook and mail-yank-hooks are both nil, this
|
|
999 default action is taken: the yanked headers are trimmed as
|
|
1000 specified by vm-included-text-headers and
|
|
1001 vm-included-text-discard-header-regexp, and the value of
|
|
1002 vm-included-text-prefix is prepended to every yanked line."
|
|
1003 (interactive
|
|
1004 (list
|
|
1005 ;; What we really want for the first argument is a message struct,
|
|
1006 ;; but if called interactively, we let the user type in a message
|
|
1007 ;; number instead.
|
|
1008 (let (mp default
|
|
1009 (result 0)
|
|
1010 prompt
|
|
1011 (last-command last-command)
|
|
1012 (this-command this-command))
|
|
1013 (if (bufferp vm-mail-buffer)
|
|
1014 (save-excursion
|
|
1015 (vm-select-folder-buffer)
|
|
1016 (setq default (and vm-message-pointer
|
|
1017 (vm-number-of (car vm-message-pointer)))
|
|
1018 prompt (if default
|
|
1019 (format "Yank message number: (default %s) "
|
|
1020 default)
|
|
1021 "Yank message number: "))
|
|
1022 (while (zerop result)
|
|
1023 (setq result (read-string prompt))
|
|
1024 (and (string= result "") default (setq result default))
|
|
1025 (setq result (string-to-int result)))
|
|
1026 (if (null (setq mp (nthcdr (1- result) vm-message-list)))
|
|
1027 (error "No such message."))
|
|
1028 (setq tm-vm/yank:message-to-restore (string-to-int default))
|
|
1029 (save-selected-window
|
|
1030 (vm-goto-message result))
|
|
1031 (car mp))
|
|
1032 nil))))
|
|
1033 (if (null message)
|
|
1034 (if mail-reply-buffer
|
|
1035 (tm-vm/yank-content)
|
|
1036 (error "This is not a VM Mail mode buffer."))
|
|
1037 (if (null (buffer-name vm-mail-buffer))
|
|
1038 (error "The folder buffer containing message %d has been killed."
|
|
1039 (vm-number-of message)))
|
|
1040 (vm-display nil nil '(vm-yank-message)
|
|
1041 '(vm-yank-message composing-message))
|
|
1042 (let ((b (current-buffer)) (start (point)) end)
|
|
1043 (save-restriction
|
|
1044 (widen)
|
|
1045 (save-excursion
|
|
1046 (set-buffer (vm-buffer-of message))
|
|
1047 (let (pbuf)
|
|
1048 (tm-vm/sync-preview-buffer)
|
|
1049 (setq pbuf (and mime::article/preview-buffer
|
|
1050 (get-buffer mime::article/preview-buffer)))
|
|
1051 (if (and pbuf
|
|
1052 (not (eq this-command 'vm-forward-message)))
|
|
1053 ;; Yank contents of MIME Preview buffer
|
|
1054 (if running-xemacs
|
|
1055 (let ((tmp (generate-new-buffer "tm-vm/tmp")))
|
|
1056 (set-buffer pbuf)
|
|
1057 (append-to-buffer tmp (point-min) (point-max))
|
|
1058 (set-buffer tmp)
|
|
1059 (map-extents
|
|
1060 '(lambda (ext maparg)
|
|
1061 (set-extent-property ext 'begin-glyph nil)))
|
|
1062 (append-to-buffer b (point-min) (point-max))
|
|
1063 (setq end (vm-marker
|
|
1064 (+ start (length (buffer-string))) b))
|
|
1065 (kill-buffer tmp))
|
|
1066 (set-buffer pbuf)
|
|
1067 (append-to-buffer b (point-min) (point-max))
|
|
1068 (setq end (vm-marker
|
|
1069 (+ start (length (buffer-string))) b)))
|
|
1070 ;; Yank contents of raw VM message
|
|
1071 (save-restriction
|
|
1072 (setq message (vm-real-message-of message))
|
|
1073 (set-buffer (vm-buffer-of message))
|
|
1074 (widen)
|
|
1075 (append-to-buffer
|
|
1076 b (vm-headers-of message) (vm-text-end-of message))
|
|
1077 (setq end
|
|
1078 (vm-marker (+ start (- (vm-text-end-of message)
|
|
1079 (vm-headers-of message))) b))))))
|
|
1080 (push-mark end)
|
|
1081 (cond (mail-citation-hook (run-hooks 'mail-citation-hook))
|
|
1082 (mail-yank-hooks (run-hooks 'mail-yank-hooks))
|
|
1083 (t (vm-mail-yank-default message)))
|
|
1084 ))
|
|
1085 (if tm-vm/yank:message-to-restore
|
|
1086 (save-selected-window
|
|
1087 (vm-goto-message tm-vm/yank:message-to-restore)
|
|
1088 (setq tm-vm/yank:message-to-restore nil)))
|
|
1089 ))
|
|
1090
|
|
1091 ;;; @@ for tm-partial
|
4
|
1092 ;;;
|
|
1093
|
|
1094 (call-after-loaded
|
|
1095 'tm-partial
|
|
1096 (function
|
|
1097 (lambda ()
|
|
1098 (set-atype 'mime/content-decoding-condition
|
|
1099 '((type . "message/partial")
|
|
1100 (method . mime-article/grab-message/partials)
|
|
1101 (major-mode . vm-mode)
|
|
1102 (summary-buffer-exp . vm-summary-buffer)
|
|
1103 ))
|
|
1104 (set-alist 'tm-partial/preview-article-method-alist
|
|
1105 'vm-mode
|
|
1106 (function
|
|
1107 (lambda ()
|
|
1108 (tm-vm/view-message)
|
|
1109 )))
|
|
1110 )))
|
|
1111
|
|
1112
|
16
|
1113 ;;; @@ for tm-edit
|
4
|
1114 ;;;
|
|
1115
|
16
|
1116 (call-after-loaded
|
|
1117 'mime-setup
|
|
1118 (function
|
|
1119 (lambda ()
|
|
1120 (setq vm-forwarding-digest-type "rfc1521")
|
|
1121 (setq vm-digest-send-type "rfc1521")
|
|
1122 )))
|
4
|
1123
|
16
|
1124 ;;; @@@ multipart/digest
|
4
|
1125
|
|
1126 (defun tm-vm/enclose-messages (mlist &optional preamble)
|
|
1127 "Enclose the messages in MLIST as multipart/digest.
|
|
1128 The resulting digest is inserted at point in the current buffer.
|
|
1129
|
|
1130 MLIST should be a list of message structs (real or virtual).
|
|
1131 These are the messages that will be enclosed."
|
|
1132 (if mlist
|
|
1133 (let ((digest (consp (cdr mlist)))
|
|
1134 (mp mlist)
|
|
1135 m)
|
|
1136 (save-restriction
|
|
1137 (narrow-to-region (point) (point))
|
|
1138 (while mlist
|
|
1139 (setq m (vm-real-message-of (car mlist)))
|
|
1140 (mime-editor/insert-tag "message" "rfc822")
|
|
1141 (tm-mail/insert-message m)
|
|
1142 (goto-char (point-max))
|
|
1143 (setq mlist (cdr mlist)))
|
|
1144 (if preamble
|
|
1145 (progn
|
|
1146 (goto-char (point-min))
|
|
1147 (mime-editor/insert-tag "text" "plain")
|
|
1148 (vm-unsaved-message "Building digest preamble...")
|
|
1149 (while mp
|
|
1150 (let ((vm-summary-uninteresting-senders nil))
|
|
1151 (insert
|
|
1152 (vm-sprintf 'vm-digest-preamble-format (car mp)) "\n"))
|
|
1153 (if vm-digest-center-preamble
|
|
1154 (progn
|
|
1155 (forward-char -1)
|
|
1156 (center-line)
|
|
1157 (forward-char 1)))
|
|
1158 (setq mp (cdr mp)))))
|
|
1159 (if digest
|
|
1160 (mime-editor/enclose-digest-region (point-min) (point-max)))
|
|
1161 ))))
|
|
1162
|
16
|
1163 (defadvice vm-forward-message (around tm-aware activate)
|
|
1164 "Extended to support rfc1521 multipart digests and to work properly in MIME-Preview buffers."
|
4
|
1165 (if (not (equal vm-forwarding-digest-type "rfc1521"))
|
16
|
1166 ad-do-it
|
4
|
1167 (if mime::preview/article-buffer
|
|
1168 (set-buffer mime::preview/article-buffer))
|
|
1169 (vm-follow-summary-cursor)
|
|
1170 (vm-select-folder-buffer)
|
|
1171 (vm-check-for-killed-summary)
|
|
1172 (vm-error-if-folder-empty)
|
|
1173 (if (eq last-command 'vm-next-command-uses-marks)
|
|
1174 (let ((vm-digest-send-type vm-forwarding-digest-type))
|
|
1175 (setq this-command 'vm-next-command-uses-marks)
|
|
1176 (command-execute 'tm-vm/send-digest))
|
|
1177 (let ((dir default-directory)
|
|
1178 (mp vm-message-pointer))
|
|
1179 (save-restriction
|
|
1180 (widen)
|
|
1181 (vm-mail-internal
|
|
1182 (format "forward of %s's note re: %s"
|
|
1183 (vm-su-full-name (car vm-message-pointer))
|
|
1184 (vm-su-subject (car vm-message-pointer)))
|
|
1185 nil
|
|
1186 (and vm-forwarding-subject-format
|
|
1187 (let ((vm-summary-uninteresting-senders nil))
|
|
1188 (vm-sprintf 'vm-forwarding-subject-format (car mp)))))
|
|
1189 (make-local-variable 'vm-forward-list)
|
|
1190 (setq vm-system-state 'forwarding
|
|
1191 vm-forward-list (list (car mp))
|
|
1192 default-directory dir)
|
|
1193 (goto-char (point-min))
|
|
1194 (re-search-forward
|
|
1195 (concat "^" (regexp-quote mail-header-separator) "\n") nil 0)
|
|
1196 (tm-vm/enclose-messages vm-forward-list)
|
|
1197 (mail-position-on-field "To"))
|
|
1198 (run-hooks 'tm-vm/forward-message-hook)
|
|
1199 (run-hooks 'vm-mail-mode-hook)))))
|
|
1200
|
|
1201 (defun tm-vm/send-digest (&optional arg)
|
|
1202 "Send a digest of all messages in the current folder to recipients.
|
|
1203 The type of the digest is specified by the variable vm-digest-send-type.
|
|
1204 You will be placed in a Mail mode buffer as is usual with replies, but you
|
|
1205 must fill in the To: and Subject: headers manually.
|
|
1206
|
|
1207 If invoked on marked messages (via vm-next-command-uses-marks),
|
|
1208 only marked messages will be put into the digest."
|
|
1209 (interactive "P")
|
|
1210 (if (not (equal vm-digest-send-type "rfc1521"))
|
|
1211 (vm-send-digest arg)
|
|
1212 (vm-select-folder-buffer)
|
|
1213 (vm-check-for-killed-summary)
|
|
1214 (vm-error-if-folder-empty)
|
|
1215 (let ((dir default-directory)
|
|
1216 (vm-forward-list (if (eq last-command 'vm-next-command-uses-marks)
|
|
1217 (vm-select-marked-or-prefixed-messages 0)
|
16
|
1218 vm-message-list)))
|
4
|
1219 (save-restriction
|
|
1220 (widen)
|
|
1221 (vm-mail-internal (format "digest from %s" (buffer-name)))
|
|
1222 (setq vm-system-state 'forwarding
|
|
1223 default-directory dir)
|
|
1224 (goto-char (point-min))
|
|
1225 (re-search-forward (concat "^" (regexp-quote mail-header-separator)
|
|
1226 "\n"))
|
|
1227 (goto-char (match-end 0))
|
|
1228 (vm-unsaved-message "Building %s digest..." vm-digest-send-type)
|
|
1229 (tm-vm/enclose-messages vm-forward-list arg)
|
|
1230 (mail-position-on-field "To")
|
|
1231 (message "Building %s digest... done" vm-digest-send-type)))
|
|
1232 (run-hooks 'tm-vm/send-digest-hook)
|
|
1233 (run-hooks 'vm-mail-mode-hook)))
|
|
1234
|
|
1235 (substitute-key-definition 'vm-send-digest
|
|
1236 'tm-vm/send-digest vm-mode-map)
|
|
1237
|
16
|
1238 ;;; @@@ Menus
|
4
|
1239
|
|
1240 ;;; modified by Steven L. Baur <steve@miranova.com>
|
|
1241 ;;; 1995/12/6 (c.f. [tm-en:209])
|
|
1242 (defun mime-editor/attach-to-vm-mode-menu ()
|
|
1243 "Arrange to attach MIME editor's popup menu to VM's"
|
|
1244 (if (boundp 'vm-menu-mail-menu)
|
|
1245 (progn
|
|
1246 (setq vm-menu-mail-menu
|
|
1247 (append vm-menu-mail-menu
|
|
1248 (list "----"
|
|
1249 mime-editor/popup-menu-for-xemacs)))
|
|
1250 (remove-hook 'vm-mail-mode-hook 'mime-editor/attach-to-vm-mode-menu)
|
16
|
1251 ))
|
|
1252 )
|
4
|
1253
|
|
1254 (call-after-loaded
|
|
1255 'tm-edit
|
|
1256 (function
|
|
1257 (lambda ()
|
|
1258 (autoload 'tm-mail/insert-message "tm-mail")
|
|
1259 (set-alist 'mime-editor/message-inserter-alist
|
|
1260 'mail-mode (function tm-mail/insert-message))
|
|
1261 (set-alist 'mime-editor/split-message-sender-alist
|
|
1262 'mail-mode (function
|
|
1263 (lambda ()
|
|
1264 (interactive)
|
8
|
1265 (funcall send-mail-function)
|
4
|
1266 )))
|
|
1267 (if (and (string-match "XEmacs\\|Lucid" emacs-version)
|
16
|
1268 tm-vm/attach-to-popup-menus)
|
4
|
1269 (add-hook 'vm-mail-mode-hook 'mime-editor/attach-to-vm-mode-menu)
|
|
1270 )
|
|
1271 )))
|
|
1272
|
16
|
1273
|
|
1274
|
|
1275 ;;; @ VM Integration
|
|
1276
|
|
1277 (add-hook 'vm-quit-hook 'tm-vm/quit-view-message)
|
|
1278
|
|
1279 ;;; @@ Wrappers for miscellaneous VM functions
|
|
1280
|
|
1281 (defadvice vm-summarize (around tm-aware activate)
|
|
1282 "Made TM aware. Callable from the MIME Preview buffer."
|
|
1283 (if mime::preview/article-buffer
|
|
1284 (set-buffer mime::preview/article-buffer))
|
|
1285 ad-do-it
|
|
1286 (save-excursion
|
|
1287 (set-buffer vm-summary-buffer)
|
|
1288 (tm-vm/check-for-toolbar))
|
|
1289 (tm-vm/preview-current-message))
|
|
1290
|
|
1291 (defadvice vm-expose-hidden-headers (around tm-aware activate)
|
|
1292 "Made TM aware. Callable from the MIME Preview buffer."
|
|
1293 (if mime::preview/article-buffer
|
|
1294 (set-buffer mime::preview/article-buffer))
|
|
1295 (let ((visible-headers vm-visible-headers))
|
|
1296 (tm-vm/quit-view-message)
|
|
1297 ad-do-it
|
|
1298 (let ((vm-visible-headers visible-headers))
|
|
1299 (if (= (point-min) (vm-start-of (car vm-message-pointer)))
|
|
1300 (setq vm-visible-headers '(".*")))
|
|
1301 (tm-vm/preview-current-message))))
|
|
1302
|
|
1303 (if (vm-mouse-fsfemacs-mouse-p)
|
|
1304 (progn
|
|
1305 (define-key tm-vm/vm-emulation-map [mouse-3] 'ignore)
|
|
1306 (define-key tm-vm/vm-emulation-map [down-mouse-3] 'vm-mouse-button-3)
|
|
1307 (defadvice vm-mouse-button-3 (after tm-aware activate)
|
|
1308 "Made TM aware. Works in MIME-Preview buffers."
|
|
1309 (if (and
|
|
1310 vm-use-menus
|
|
1311 (eq major-mode 'mime/viewer-mode))
|
|
1312 (vm-menu-popup-mode-menu event))))
|
|
1313 )
|
4
|
1314
|
|
1315
|
16
|
1316 ;;; @@ VM Toolbar Integration
|
|
1317
|
|
1318 (require 'vm-toolbar)
|
|
1319
|
|
1320 ;;; based on vm-toolbar-any-messages-p [vm-toolbar.el]
|
|
1321 (defun tm-vm/check-for-toolbar ()
|
|
1322 "Install VM toolbar if necessary."
|
|
1323 (if (and running-xemacs
|
|
1324 vm-toolbar-specifier)
|
|
1325 (progn
|
|
1326 (if (null (specifier-instance vm-toolbar-specifier))
|
|
1327 (vm-toolbar-install-toolbar))
|
|
1328 (vm-toolbar-update-toolbar))))
|
|
1329
|
|
1330 (defun vm-toolbar-any-messages-p ()
|
|
1331 (save-excursion
|
|
1332 (if mime::preview/article-buffer
|
|
1333 (set-buffer mime::preview/article-buffer))
|
|
1334 (vm-check-for-killed-folder)
|
|
1335 (vm-select-folder-buffer)
|
|
1336 vm-message-list))
|
|
1337
|
|
1338
|
|
1339 ;;; @ BBDB Integration
|
4
|
1340 ;;;
|
|
1341
|
|
1342 (call-after-loaded
|
|
1343 'bbdb
|
|
1344 (function
|
|
1345 (lambda ()
|
|
1346 (require 'bbdb-vm)
|
|
1347 (require 'tm-bbdb)
|
|
1348 (defun tm-bbdb/vm-update-record (&optional offer-to-create)
|
16
|
1349 (save-excursion
|
|
1350 (vm-select-folder-buffer)
|
|
1351 (if (and (tm-vm/system-state)
|
|
1352 mime::article/preview-buffer
|
|
1353 (get-buffer mime::article/preview-buffer))
|
|
1354 (let ((tm-bbdb/auto-create-p bbdb/mail-auto-create-p))
|
|
1355 (tm-bbdb/update-record offer-to-create))
|
|
1356 (or (bbdb/vm-update-record offer-to-create)
|
|
1357 (delete-windows-on (get-buffer "*BBDB*")))
|
|
1358 )))
|
4
|
1359 (remove-hook 'vm-select-message-hook 'bbdb/vm-update-record)
|
|
1360 (remove-hook 'vm-show-message-hook 'bbdb/vm-update-record)
|
|
1361 (add-hook 'tm-vm/select-message-hook 'tm-bbdb/vm-update-record)
|
|
1362 )))
|
|
1363
|
16
|
1364 ;;; @ ps-print (Suggested by Anders Stenman <stenman@isy.liu.se>)
|
4
|
1365 ;;;
|
|
1366
|
|
1367 (if tm-vm/use-ps-print
|
|
1368 (progn
|
8
|
1369 (autoload 'ps-print-buffer-with-faces "ps-print" "Postscript Print" t)
|
4
|
1370 (add-hook 'vm-mode-hook 'tm-vm/ps-print-setup)
|
|
1371 (add-hook 'mime-viewer/define-keymap-hook 'tm-vm/ps-print-setup)
|
|
1372 (fset 'vm-toolbar-print-command 'tm-vm/print-message)))
|
|
1373
|
|
1374 (defun tm-vm/ps-print-setup ()
|
|
1375 "Set things up for printing MIME messages with ps-print. Set binding to
|
|
1376 the [Print Screen] key."
|
8
|
1377 (local-set-key (if running-xemacs
|
|
1378 'f22
|
|
1379 [f22])
|
|
1380 'tm-vm/print-message)
|
4
|
1381 (setq ps-header-lines 3)
|
|
1382 (setq ps-left-header
|
|
1383 (list 'ps-article-subject 'ps-article-author 'buffer-name)))
|
|
1384
|
|
1385 (defun tm-vm/print-message ()
|
|
1386 "Print current message with ps-print if it's a MIME message.
|
|
1387 Value of tm-vm/strict-mime is also taken into consideration."
|
|
1388 (interactive)
|
|
1389 (vm-follow-summary-cursor)
|
16
|
1390 (vm-select-folder-buffer)
|
|
1391 (tm-vm/sync-preview-buffer)
|
|
1392 (let ((pbuf (and mime::article/preview-buffer
|
|
1393 (get-buffer mime::article/preview-buffer))))
|
4
|
1394 (if pbuf
|
|
1395 (save-excursion
|
|
1396 (set-buffer pbuf)
|
|
1397 (require 'ps-print)
|
|
1398 (ps-print-buffer-with-faces))
|
|
1399 (vm-print-message))))
|
|
1400
|
|
1401
|
|
1402 ;;; @ end
|
|
1403
|
|
1404 (provide 'tm-vm)
|
|
1405 (run-hooks 'tm-vm-load-hook)
|
|
1406
|
|
1407 ;;; tm-vm.el ends here.
|