2808
2823
(lambda (layout)
2809
2824
(save-excursion
2810
(vm-mime-display-internal-application/octet-stream layout))))
2825
(vm-mime-save-application/octet-stream layout))))
2829
(defun vm-mime-save-application/octet-stream (layout)
2830
"Save an application/octet-stream object with LAYOUT to the
2831
stated filename. A button extent with a layout can also be given as
2832
the argument. USR, 2011-03-25"
2833
(unless (vectorp layout)
2812
2834
(goto-char (vm-extent-start-position layout))
2813
(setq layout (vm-extent-property layout 'vm-mime-layout))
2814
;; support old "name" paramater for application/octet-stream
2815
;; but don't override the "filename" parameter extracted from
2816
;; Content-Disposition, if any.
2817
(let ((default-filename (vm-mime-get-disposition-filename layout))
2819
(setq file (vm-mime-send-body-to-file layout default-filename))
2820
(if vm-mime-delete-after-saving
2821
(let ((vm-mime-confirm-delete nil))
2822
;; we don't care if the delete fails
2824
(vm-delete-mime-object (expand-file-name file))
2835
(setq layout (vm-extent-property layout 'vm-mime-layout)))
2836
;; support old "name" paramater for application/octet-stream
2837
;; but don't override the "filename" parameter extracted from
2838
;; Content-Disposition, if any.
2839
(let ((default-filename (vm-mime-get-disposition-filename layout))
2841
(setq file (vm-mime-send-body-to-file layout default-filename))
2842
(if vm-mime-delete-after-saving
2843
(let ((vm-mime-confirm-delete nil))
2844
;; we don't care if the delete fails
2846
(vm-delete-mime-object (expand-file-name file))
2827
2849
(fset 'vm-mime-display-button-application/octet-stream
2828
2850
'vm-mime-display-internal-application/octet-stream)
2830
2852
(defun vm-mime-display-button-application (layout)
2853
"Display button for an application type object described by LAYOUT."
2831
2854
(vm-mime-display-button-xxxx layout nil))
4264
4301
(eq 0 (apply 'call-process vm-imagemagick-convert-program
4266
4303
(append convert-args (list "-[0]" "png:-"))))))
4269
(write-region (point-min) (point-max) tempfile nil 0)
4271
(setcar (nthcdr 5 blob) 0))
4272
(put (vm-mm-layout-cache layout) 'vm-image-modified t))))
4273
(and work-buffer (kill-buffer work-buffer)))
4275
;; the output is always PNG now, so fix it for displaying, but restore
4276
;; it for the layout afterwards
4277
(vm-set-mm-layout-type layout '("image/png"))
4278
(vm-mark-image-tempfile-as-message-garbage-once layout tempfile)
4279
(vm-mime-display-generic extent)
4305
(write-region (point-min) (point-max) tempfile nil 0)
4307
(setcar (nthcdr 5 blob) 0))
4308
(put (vm-mm-layout-cache layout) 'vm-image-modified t)))
4309
;; unwind-protection
4310
(when work-buffer (kill-buffer work-buffer)))
4313
;; the output is always PNG now, so fix it for displaying, but restore
4314
;; it for the layout afterwards
4315
(vm-set-mm-layout-type layout '("image/png"))
4316
(vm-mark-image-tempfile-as-message-garbage-once layout tempfile)
4317
(vm-mime-display-internal-generic extent))
4280
4318
(vm-set-mm-layout-type layout saved-type))))
4282
4320
(defun vm-mark-image-tempfile-as-message-garbage-once (layout tempfile)
4353
4391
(int-to-string (/ (nth 1 dims) 2))))))
4355
4393
(defcustom vm-mime-thumbnail-max-geometry "80x80"
4356
"*Max width and height of image thumbnail."
4394
"If thumbnails should be displayed as part of MIME buttons, then set
4395
this variable to a string describing the geometry, e.g., \"80x80\".
4396
Otherwise, set it to nil. USR, 2011-03-25"
4357
4397
:group 'vm-mime
4358
4398
:type '(choice string
4359
4399
(const :tag "Disable thumbnails." nil)))
4361
4401
(defun vm-mime-display-button-image (layout)
4362
"Displays a button for the image and when possible a thumbnail."
4363
(if (not (and vm-imagemagick-convert-program
4364
vm-mime-thumbnail-max-geometry
4365
(vm-images-possible-here-p)))
4366
;; just display the normal button
4367
(vm-mime-display-button-xxxx layout t)
4368
;; otherwise create a thumb and display it
4369
(let (tempfile start end x glyph)
4370
;; fake an extent to display the image as thumb
4371
(setq start (point))
4373
(setq x (vm-make-extent start (point)))
4374
(vm-set-extent-property x 'vm-mime-layout layout)
4375
(vm-set-extent-property x 'vm-mime-disposable nil)
4376
(vm-set-extent-property x 'start-open t)
4377
;; write out the image data
4379
(set-buffer (vm-make-work-buffer))
4380
(vm-mime-insert-mime-body layout)
4381
(vm-mime-transfer-decode-region layout (point-min) (point-max))
4382
(setq tempfile (vm-make-tempfile))
4383
(let ((coding-system-for-write (vm-binary-coding-system)))
4384
(write-region (point-min) (point-max) tempfile nil 0))
4385
(kill-buffer (current-buffer)))
4386
;; store the temp filename
4387
(put (vm-mm-layout-cache layout)
4388
'vm-mime-display-internal-image-xxxx
4390
(vm-register-folder-garbage-files (list tempfile))
4392
(let ((vm-mime-internal-content-types '("image"))
4393
(vm-mime-internal-content-type-exceptions nil)
4394
(vm-mime-use-image-strips nil))
4395
(vm-mime-frob-image-xxxx x
4397
vm-mime-thumbnail-max-geometry))
4398
;; extract image data
4399
(setq glyph (if vm-xemacs-p
4400
(let ((e1 (vm-extent-at start))
4401
(e2 (vm-extent-at (1+ start))))
4402
(or (and e1 (extent-begin-glyph e1))
4403
(and e2 (extent-begin-glyph e2))))
4404
(get-text-property start 'display)))
4405
(delete-region start (point))
4406
;; insert the button and correct the image
4407
(setq start (point))
4408
(vm-mime-display-button-xxxx layout t)
4411
(set-extent-begin-glyph (vm-extent-at start) glyph)
4412
(put-text-property start (1+ start) 'display glyph)))
4413
;; force redisplay in original size
4414
(put (vm-mm-layout-cache layout)
4415
'vm-mime-display-internal-image-xxxx
4402
"Displays a button for the MIME LAYOUT and includes a thumbnail
4403
image when possible."
4404
(if (and vm-imagemagick-convert-program
4405
vm-mime-thumbnail-max-geometry
4406
(vm-images-possible-here-p))
4407
;; create a thumbnail and display it
4408
(let (tempfile start end thumb-extent glyph)
4409
;; fake an extent to display the image as thumb
4410
(setq start (point))
4412
(setq thumb-extent (vm-make-extent start (point)))
4413
(vm-set-extent-property thumb-extent 'vm-mime-layout layout)
4414
(vm-set-extent-property thumb-extent 'vm-mime-disposable nil)
4415
(vm-set-extent-property thumb-extent 'start-open t)
4416
;; write out the image data
4417
(with-current-buffer (vm-make-work-buffer)
4418
(vm-mime-insert-mime-body layout)
4419
(vm-mime-transfer-decode-region layout (point-min) (point-max))
4420
(setq tempfile (vm-make-tempfile))
4421
(let ((coding-system-for-write (vm-binary-coding-system)))
4422
(write-region (point-min) (point-max) tempfile nil 0))
4423
(kill-buffer (current-buffer)))
4424
;; store the temp filename
4425
(put (vm-mm-layout-cache layout)
4426
'vm-mime-display-internal-image-xxxx
4428
(vm-register-folder-garbage-files (list tempfile))
4429
;; display a thumbnail over the fake extent
4430
(let ((vm-mime-internal-content-types '("image"))
4431
(vm-mime-internal-content-type-exceptions nil)
4432
(vm-mime-use-image-strips nil))
4433
(vm-mime-frob-image-xxxx thumb-extent
4435
vm-mime-thumbnail-max-geometry))
4436
;; extract image data, don't need the image itself!
4437
;; if the display was not successful, glyph will be nil
4438
(setq glyph (if vm-xemacs-p
4439
(let ((e1 (vm-extent-at start))
4440
(e2 (vm-extent-at (1+ start))))
4441
(or (and e1 (extent-begin-glyph e1))
4442
(and e2 (extent-begin-glyph e2))))
4443
(get-text-property start 'display)))
4444
(delete-region start (point))
4445
;; insert the button and replace the image
4446
(setq start (point))
4447
(vm-mime-display-button-xxxx layout t)
4450
(set-extent-begin-glyph (vm-extent-at start) glyph)
4451
(put-text-property start (1+ start) 'display glyph)))
4452
;; remove the cached thumb so that full sized image will be shown
4453
(put (vm-mm-layout-cache layout)
4454
'vm-mime-display-internal-image-xxxx
4457
;; just display the normal button
4458
(vm-mime-display-button-xxxx layout t)))
4419
4460
(defun vm-mime-display-button-application/pdf (layout)
4420
4461
(vm-mime-display-button-image layout))