Source

mew / mew / mew-xemacs.el

Full commit
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
;;; mew-xemacs.el --- Environment of XEmacs for Mew

;; Author:  Kazu Yamamoto <Kazu@Mew.org>
;; Created: Mar 20, 1997
;; Revised: Aug 30, 1999

;;; Code:

(defconst mew-xemacs-version "mew-xemacs.el version 0.09")

;;
;; Common
;;

(cond
 ((not mew-icon-p)
  (defvar mew-icon-directory nil)
  (defvar mew-icon-separate-spec nil)
  (defvar mew-icon-blank nil)
  (defvar mew-icon-audio nil)
  (defvar mew-icon-image nil)
  (defvar mew-icon-video nil)
  (defvar mew-icon-application/postscript nil)
  (defvar mew-icon-application/octet-stream nil)
  (defvar mew-icon-message/rfc822 nil)
  (defvar mew-icon-message/external-body nil)
  (defvar mew-icon-text nil)
  (defvar mew-icon-multipart nil)
  (defvar mew-icon-unknown nil)
  (defvar mew-summary-toolbar nil)
  (defvar mew-draft-toolbar nil))
 (t
  (defvar mew-icon-directory (locate-data-directory "mew"))

  (defvar mew-icon-separate
    (toolbar-make-button-list
     (expand-file-name "mew-sep.xpm" mew-icon-directory)))

  (defvar mew-icon-separate-spec
    (list [mew-icon-separate nil nil ""]))

  (defvar mew-icon-blank
    (toolbar-make-button-list
     (expand-file-name "mew-Blank.xpm" mew-icon-directory)))

  (defvar mew-icon-audio 
    (toolbar-make-button-list
     (expand-file-name "mew-Audio.xpm" mew-icon-directory)))

  (defvar mew-icon-image
    (toolbar-make-button-list
     (expand-file-name "mew-Image.xpm" mew-icon-directory)))

  (defvar mew-icon-video
    (toolbar-make-button-list
     (expand-file-name "mew-Video.xpm" mew-icon-directory)))

  (defvar mew-icon-application/postscript
    (toolbar-make-button-list
     (expand-file-name "mew-Postscript.xpm" mew-icon-directory)))

  (defvar mew-icon-application/octet-stream
    (toolbar-make-button-list
     (expand-file-name "mew-Octet-Stream.xpm" mew-icon-directory)))

  (defvar mew-icon-message/rfc822
    (toolbar-make-button-list
     (expand-file-name "mew-Rfc822.xpm" mew-icon-directory)))

  (defvar mew-icon-message/external-body
    (toolbar-make-button-list
     (expand-file-name "mew-External.xpm" mew-icon-directory)))

  (defvar mew-icon-text
    (toolbar-make-button-list
     (expand-file-name "mew-Text.xpm" mew-icon-directory)))

  (defvar mew-icon-multipart
    (toolbar-make-button-list
     (expand-file-name "mew-Folder.xpm" mew-icon-directory)))

  (defvar mew-icon-unknown
    (toolbar-make-button-list
     (expand-file-name "mew-Unknown.xpm" mew-icon-directory)))

  ;;
  ;; Summary mode
  ;;

  (defvar mew-summary-toolbar-icon-show
    (toolbar-make-button-list
     (expand-file-name "mew-show.xpm" mew-icon-directory)))

  (defvar mew-summary-toolbar-icon-next
    (toolbar-make-button-list
     (expand-file-name "mew-next.xpm" mew-icon-directory)))

  (defvar mew-summary-toolbar-icon-prev
    (toolbar-make-button-list
     (expand-file-name "mew-prev.xpm" mew-icon-directory)))

  (defvar mew-summary-toolbar-icon-inc
    (toolbar-make-button-list
     (expand-file-name "mew-inc.xpm" mew-icon-directory)))

  (defvar mew-summary-toolbar-icon-write
    (toolbar-make-button-list
     (expand-file-name "mew-write.xpm" mew-icon-directory)))

  (defvar mew-summary-toolbar-icon-reply
    (toolbar-make-button-list
     (expand-file-name "mew-reply.xpm" mew-icon-directory)))

  (defvar mew-summary-toolbar-icon-forward
    (toolbar-make-button-list
     (expand-file-name "mew-forward.xpm" mew-icon-directory)))

  (defvar mew-summary-toolbar-icon-refile
    (toolbar-make-button-list
     (expand-file-name "mew-refile.xpm" mew-icon-directory)))

  (defvar mew-summary-toolbar
    '(
      [mew-summary-toolbar-icon-show
       mew-summary-show
       t
       "Read Forward"]
      [mew-summary-toolbar-icon-next
       mew-summary-display-down
       t
       "Show Next Message"]
      [mew-summary-toolbar-icon-prev
       mew-summary-display-up
       t
       "Show Previous Message"]
      [mew-summary-toolbar-icon-inc
       mew-summary-get
       t
       "Check New Messages"]
      [mew-summary-toolbar-icon-write
       mew-summary-send
       t
       "Write Message"]
      [mew-summary-toolbar-icon-reply
       mew-summary-reply
       t
       "Reply to This Message"]
      [mew-summary-toolbar-icon-forward
       mew-summary-forward
       t
       "Forward This Message"]
      [mew-summary-toolbar-icon-refile
       mew-summary-refile
       t
       "Refile This Message"]
      ))

  ;;
  ;; Draft mode
  ;;

  (defvar mew-draft-toolbar-icon-comp
    (toolbar-make-button-list
     (expand-file-name "mew-comp.xpm" mew-icon-directory)))

  (defvar mew-draft-toolbar-icon-send
    (toolbar-make-button-list
     (expand-file-name "mew-send.xpm" mew-icon-directory)))

  (defvar mew-draft-toolbar-icon-attach
    (toolbar-make-button-list
     (expand-file-name "mew-attach.xpm" mew-icon-directory)))

  (defvar mew-draft-toolbar-icon-cite
    (toolbar-make-button-list
     (expand-file-name "mew-cite.xpm" mew-icon-directory)))

  (defvar mew-draft-toolbar-icon-yank
    (toolbar-make-button-list
     (expand-file-name "mew-yank.xpm" mew-icon-directory)))

  (defvar mew-draft-toolbar-icon-pgp-sign
    (toolbar-make-button-list
     (expand-file-name "mew-pgp-sign.xpm" mew-icon-directory)))

  (defvar mew-draft-toolbar-icon-pgp-enc
    (toolbar-make-button-list
     (expand-file-name "mew-pgp-enc.xpm" mew-icon-directory)))

  (defvar mew-draft-toolbar-icon-pgp-sigenc
    (toolbar-make-button-list
     (expand-file-name "mew-pgp-sigenc.xpm" mew-icon-directory)))

  (defvar mew-draft-toolbar
    '(
      [mew-draft-toolbar-icon-comp
       mew-draft-make-message
       (mew-header-p)
       "Compose Message"]
      [mew-draft-toolbar-icon-send
       mew-draft-send-letter
       (not (mew-header-p))
       "Send Message"]
      [mew-draft-toolbar-icon-cite
       mew-draft-cite
       (mew-header-p)
       "Cite Message"]
      [mew-draft-toolbar-icon-yank
       mew-draft-yank
       (mew-header-p)
       "Cite Message without Label"]
      [mew-draft-toolbar-icon-attach
       mew-draft-prepare-attachments
       (and (mew-header-p) (not (mew-attach-p)))
       "Prepare Attachments"]
      [mew-draft-toolbar-icon-pgp-sign
       mew-pgp-sign-letter
       (mew-header-p)
       "Sign Message with PGP"]
      [mew-draft-toolbar-icon-pgp-enc
       mew-pgp-encrypt-letter
       (mew-header-p)
       "Encrypt Message with PGP"]
      [mew-draft-toolbar-icon-pgp-sigenc
       mew-pgp-sign-encrypt-letter
       (mew-header-p)
       "Sign Then Encrypt Message with PGP"]
      ))

  ;;
  ;; Button
  ;; 

  (define-key toolbar-map 'button3   'pressed-and-activate-toolbar-button)
  (define-key toolbar-map 'button3up 'release-and-activate-toolbar-button)

  (defun mew-summary-button ()
    "Call back function for toolbar of Summary mode. 
If event is button 1, show a part.
If event is button 3, show a menu."
    (interactive)
    (let* ((msg (mew-summary-message-number))
	   (part (mew-syntax-number))
	   (nums (mew-syntax-number-to-nums part))
	   (button (event-button last-command-event)))
      (mew-summary-goto-part msg part)
      (mew-summary-recenter)
      (cond
       ((eq button 1)
	(mew-summary-show-part msg nums))
       ((eq button 3)
	(popup-menu mew-summary-mode-toolbar-menu)))))

  (defun mew-summary-show-part (msg nums)
    "Show a part according to the clicked icon."
    (interactive)
    (let ((fld (mew-summary-folder-name))
	  (ofld-msg (mew-current-get 'message))
	  (buf (buffer-name)))
      (if (null nums) 
	  (message "No message")
	(mew-summary-toggle-disp-msg 'on)
	(unwind-protect
	    (progn
	      (mew-window-configure buf 'message)
	      ;; message buffer
	      (mew-summary-display-part 
	       (mew-cache-decode-syntax (mew-cache-hit ofld-msg)) nums))
	  (mew-pop-to-buffer buf)))))

  (defun mew-draft-button ()
    "Call back function for toolbar of Draft mode. 
If event is button 1, show a part.
If event is button 3, show a menu."
    (interactive)
    (let ((nums (mew-syntax-nums))
	  (button (event-button last-command-event)))
      (mew-attach-goto-number 'here nums)
      (cond
       ((eq button 1)
	(mew-draft-show-attach nums))
       ((eq button 3)
	(popup-menu mew-draft-mode-toolbar-menu)))))

  ;; This is a toy at present. Support only CT: Image/*.
  ;; To make Summary and Draft symmetric, left button click on icon
  ;; should display the attachment. 
  (defun mew-draft-show-attach (nums)
    "Show a part according to the clicked icon."
    (interactive)
    (let ((case-fold-search t)
	  (str (toolbar-button-help-string last-pressed-toolbar-button))
	  (image-extent (extent-at (point-max) nil nil nil 'at))
	  ct)
      (if (and image-extent (glyphp image-extent))
	  (mew-overlay-delete image-extent))
      (if (null (string-match "(\\(.*\\))" str))
	  ()
	(setq ct (mew-match 1 str))
	(if (string-match "^Image/" ct)
	    (let* ((subdir (mew-attach-expand-path mew-encode-syntax nums))
		   (syntax (mew-syntax-get-entry mew-encode-syntax nums))
		   (name (mew-syntax-get-file syntax))
		   (ename (if (equal subdir "") name (concat subdir name)))
		   (file (expand-file-name ename (mew-attachdir)))
		   (attr (mew-attr-by-ct ct))
		   (program (mew-attr-get-prog attr))
		   (options (mew-attr-get-opt attr))
		   (async   (mew-attr-get-async attr))
		   (zmacs-regions nil) ;; for XEmacs
		   (format (cond
			    ((and (string-match "jpeg" ct)
				  (valid-image-instantiator-format-p 'jpeg))
			     'jpeg)
			    ((and (string-match "gif" ct)
				  (valid-image-instantiator-format-p 'gif)) 
			     'gif)
			    ((and (string-match "xbm" ct)
				  (valid-image-instantiator-format-p 'xbm))
			     'xbm)
			    ((and (string-match "xpm" ct)
				  (valid-image-instantiator-format-p 'xpm))
			     'xpm)
			    ((and (string-match "png" ct)
				  (valid-image-instantiator-format-p 'png))
			     'png)
			    (t nil)))
		   glyph) 
	      (if format
		  (progn
		    (message "Loading image...")
		    (setq glyph (make-glyph (vector format :file file)))
		    (if (eq format 'xbm)
			(set-glyph-property glyph 'face 'x-face))
		    (set-extent-begin-glyph
		     (mew-overlay-make (point-max) (point-max)) glyph)
		    (message "Loading image...done."))
		(if (and (stringp program) (mew-which program exec-path))
		    (if async
			(mew-mime-start-process program options file)
		      (mew-mime-call-process program options file)))))))))

  (defun pressed-and-activate-toolbar-button (event)
    "A replacement function 'press-toolbar-button' so that
popup menu can be implemented."
    (interactive "_e")
    (or (button-press-event-p event)
	(error "%s must be invoked by a mouse-press" this-command))
    (let ((button (event-toolbar-button event)) callback)
      (if (null (toolbar-button-p button))
	  ()
	(setq last-pressed-toolbar-button button)
	(if (and (setq callback (toolbar-button-callback button))
		 (or (equal callback 'mew-summary-button)
		     (equal callback 'mew-draft-button)))
	    (if (null (toolbar-button-enabled-p button))
		()
	      ;; (setq toolbar-active t) is meaningless... why?
	      (setq this-command callback)
	      (if (symbolp callback)
		  (call-interactively callback)
		(eval callback)))
	  ;; emulate press-toolbar-button
	  (setq this-command last-command)
	  (setq toolbar-active t)
	  (set-toolbar-button-down-flag button t)))))

  )) ;; end of cond


(defmacro mew-summary-toolbar-update ()
  '(if mew-icon-p
       (set-specifier default-toolbar
		      (cons (current-buffer) mew-summary-toolbar))))

(defmacro mew-draft-toolbar-update ()
  '(if mew-icon-p
       (set-specifier default-toolbar
		      (cons (current-buffer) mew-draft-toolbar))))

(defvar mew-x-emacs-end-of-message nil)
(defvar mew-x-emacs-end-of-part nil)

(defmacro mew-message-set-end-of-message ()
  '(progn
     (if (not (glyphp mew-x-emacs-end-of-message))
	 (setq mew-x-emacs-end-of-message
	       (make-glyph
		(vector 'string :data mew-end-of-message-string))))
     (mew-overlay-put mew-message-overlay
		      'begin-glyph
		      mew-x-emacs-end-of-message)))

(defmacro mew-message-set-end-of-part ()
  '(progn
     (if (not (glyphp mew-x-emacs-end-of-part))
	 (setq mew-x-emacs-end-of-part
	       (make-glyph
		(vector 'string :data mew-end-of-part-string))))
     (mew-overlay-put mew-message-overlay
		      'begin-glyph
		      mew-x-emacs-end-of-part)))

(defmacro mew-message-set-end-of-nil ()
  '(mew-overlay-put mew-message-overlay 'begin-glyph nil))
  
(provide 'mew-xemacs)

;;; Copyright Notice:

;; Copyright (C) 1997, 1998, 1999 Mew developing team.
;; All rights reserved.

;; Redistribution and use in source and binary forms, with or without
;; modification, are permitted provided that the following conditions
;; are met:
;; 
;; 1. Redistributions of source code must retain the above copyright
;;    notice, this list of conditions and the following disclaimer.
;; 2. Redistributions in binary form must reproduce the above copyright
;;    notice, this list of conditions and the following disclaimer in the
;;    documentation and/or other materials provided with the distribution.
;; 3. Neither the name of the team nor the names of its contributors
;;    may be used to endorse or promote products derived from this software
;;    without specific prior written permission.
;; 
;; THIS SOFTWARE IS PROVIDED BY THE TEAM AND CONTRIBUTORS ``AS IS'' AND
;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
;; PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE TEAM OR CONTRIBUTORS BE
;; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

;;; mew-xemacs.el ends here