512
524
(write-region begin end file1 nil 'no-msg)))
513
525
(setq file2 (mew-make-temp-name))
514
526
(if (eq prog mew-prog-application/msword)
517
(if mew-use-old-wvhtml
518
(call-process prog nil nil nil file1 file2)
519
(call-process prog nil nil nil
521
(concat "--targetdir=" (file-name-directory file2))
523
(file-name-nondirectory file2)))
524
(let ((buffer-file-coding-system)) ;; to prevent the side effect
525
(mew-insert-file-contents file2)))
527
(mew-frwlet 'utf-8 mew-cs-dummy
528
(if mew-use-old-wvhtml
529
(call-process prog nil nil nil file1 file2)
530
(call-process prog nil nil nil
532
(concat "--targetdir=" (file-name-directory file2))
534
(file-name-nondirectory file2)))
535
(let ((buffer-file-coding-system)) ;; to prevent the side effect
536
(mew-insert-file-contents file2)))
526
537
(if (eq prog mew-prog-application/rtf)
528
'shift_jis mew-cs-dummy
529
(call-process prog nil (current-buffer) nil file1))
532
(call-process prog nil (current-buffer) nil file1))))
538
(mew-frwlet 'shift_jis mew-cs-dummy
539
(call-process prog nil (current-buffer) nil file1))
540
(mew-frwlet 'utf-8 mew-cs-dummy
541
(call-process prog nil (current-buffer) nil file1))))
533
542
(mew-delete-file file1)
534
543
(mew-delete-file file2)
572
581
(call-process mew-prog-tnef file t nil "--verbose" "-C" dir)
573
582
(mew-delete-file file))))
584
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
586
;;; Executing external commands
589
(defun mew-summary-ask-ct (ct fname)
593
(setq ct (or (mew-ctdb-ct (mew-ctdb-by-file fname))
594
(mew-content-type (mew-sinfo-get-case))))
595
(setq pt "Type for %s (%s): ")
598
(setq pt "Type %s(%s): ")
600
(mew-input-type pt fl ct mew-mime-content-type-list)))
602
(defun mew-summary-execute-external (&optional ask-command)
603
"Execute an external command according to Content-Type:.
604
If this command is executed on the entire message, the first part
605
is chosen as a target.
607
If Content-Type of the target part is Application/Octet-Stream,
608
Content-Type is automatically asked. And if it has both
609
internal and external visualization mechanisms, you are asked
610
which you want to use.
612
If executed with '\\[universal-argument]', you can specify a
613
command to be executed.
615
See 'mew-mime-content-type' to know how actions can be defined."
617
(mew-summary-msg-or-part
618
(let* ((fld (mew-summary-folder-name))
619
(msg (mew-summary-message-number2))
620
(nums (mew-syntax-nums))
621
(cache (mew-cache-hit fld msg 'must-hit))
622
(syntax (mew-cache-decode-syntax cache))
623
(stx (mew-syntax-get-entry syntax nums))
624
(ctl (mew-syntax-get-ct stx))
625
(ct (mew-syntax-get-value ctl 'cap))
626
(win (selected-window))
627
begin end params cdpl fname program options async was-apo erase-p
629
(when (and (string= ct mew-ct-msg)
630
(or (not ask-command)
631
(not (y-or-n-p "Save the entire message (y) or the first part (n)? "))))
632
(setq stx (mew-syntax-get-part stx))
633
(if (mew-syntax-multipart-p stx)
634
(setq stx (mew-syntax-get-part stx)))
635
(setq ctl (mew-syntax-get-ct stx))
636
(setq ct (mew-syntax-get-value ctl 'cap)))
637
(setq begin (mew-syntax-get-begin stx))
638
(setq end (mew-syntax-get-end stx))
639
(setq params (mew-syntax-get-params ctl))
640
(setq cdpl (mew-syntax-get-cdp stx))
641
(setq fname (mew-syntax-get-filename cdpl ctl))
642
(when (or (string= ct mew-ct-apo)
643
(eq (mew-ctdb-prog (mew-ctdb-by-ct ct))
644
'mew-mime-application/octet-stream))
645
(setq ct (mew-summary-ask-ct ct fname))
647
(if (not ask-command)
648
(setq program (mew-ctdb-prog (mew-ctdb-by-ct ct)))
649
(setq pro-opt (mew-input-command mew-default-external-program))
650
(setq program (car pro-opt))
651
(setq options (cdr pro-opt)))
653
;; func => called for both
655
;; (nil prog) == prog
656
;; (nil (prog...)) == (prog...)
657
;; (nil func) != func
658
;; (func func) => need to select
659
;; (func prog) => need to select
660
;; (func (prog ...)) => need to select
667
(setq ent1 (nth 0 program))
668
(setq ent2 (nth 1 program))
671
(mew-set '(program options async) program))
678
(mew-set '(program options async) ent2))
680
(setq program ent2))))
683
(y-or-n-p "Internal (y) or External (n)? "))
692
(mew-set '(program options async) program)))))))
693
(mew-summary-toggle-disp-msg 'on)
694
(mew-window-configure 'message)
695
(if erase-p (mew-erase-buffer))
701
(mew-summary-execute-program
702
program ct ctl cache begin end params fname options async))
704
(mew-summary-execute-symbol
705
program ct ctl cache begin end params fname was-apo)))
706
(mew-summary-display-postscript 'no-hook))
707
(select-window win)))))
709
(defun mew-summary-execute-symbol (program ct ctl cache begin end params fname was-apo)
711
((not (fboundp program))
712
(message "%s is not implemented" (symbol-name program)))
713
((eq program mew-prog-rfc822)
714
(message "%s cannot be executed" mew-prog-rfc822))
715
((or (mew-ct-imagep ct) (mew-ct-modelp ct))
716
(funcall program cache begin end params fname ct))
718
(let ((mew-use-text/html t)
719
(mbuf (current-buffer))
721
(if (and was-apo (mew-ct-textp ct)) ;; decode-broken?
723
(insert-buffer-substring cache begin end)
724
(mew-cs-decode-region (point-min) (point-max) mew-cs-autoconv)
725
(setq tbuf (current-buffer))
726
(setq begin (point-min))
727
(setq end (point-max))
729
(funcall program tbuf begin end params))
730
(funcall program cache begin end params))))))
733
(defun mew-summary-execute-program (program ct ctl cache begin end params fname options async)
734
(if (not (mew-which-exec program))
735
(message "%s does not exist" program)
736
(let ((file (mew-make-temp-name fname))
740
;; NEVER use call-process-region for privacy reasons
742
((not (mew-ct-linebasep ct))
743
(setq wcs mew-cs-binary))
744
((not (mew-ct-textp ct))
745
(setq wcs mew-cs-text-for-write))
748
((or (string= mew-ct-htm ct) (string= mew-ct-xml ct))
749
(setq wcs (mew-text/html-detect-cs begin end))
750
(unless (mew-coding-system-p wcs)
751
(setq wcs (mew-charset-to-cs
752
(mew-syntax-get-param ctl "charset")))))
754
(setq wcs (mew-charset-to-cs
755
(mew-syntax-get-param ctl "charset")))))
756
(unless (mew-coding-system-p wcs)
757
(setq wcs (if mew-decode-broken
759
(mew-charset-guess-region
761
mew-cs-text-for-write)))))
762
(mew-frwlet mew-cs-dummy wcs
763
(write-region begin end file nil 'no-msg))
765
(mew-mime-start-process program options file)
766
(mew-mime-call-process program options file))))))
575
768
(provide 'mew-mime)
577
770
;;; Copyright Notice:
579
;; Copyright (C) 1997-2007 Mew developing team.
772
;; Copyright (C) 1997-2008 Mew developing team.
580
773
;; All rights reserved.
582
775
;; Redistribution and use in source and binary forms, with or without
583
776
;; modification, are permitted provided that the following conditions
586
779
;; 1. Redistributions of source code must retain the above copyright
587
780
;; notice, this list of conditions and the following disclaimer.
588
781
;; 2. Redistributions in binary form must reproduce the above copyright