4171
|
1 ;;; metamail.el --- Metamail interface for GNU Emacs
|
|
2
|
14994
|
3 ;; Copyright (C) 1993 Free Software Foundation, Inc.
|
4171
|
4
|
|
5 ;; Author: Masanobu UMEDA <umerin@mse.kyutech.ac.jp>
|
|
6 ;; Keywords: mail, news, mime, multimedia
|
|
7
|
|
8 ;; This file is part of GNU Emacs.
|
|
9
|
|
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
11 ;; it under the terms of the GNU General Public License as published by
|
|
12 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
13 ;; any later version.
|
|
14
|
|
15 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18 ;; GNU General Public License for more details.
|
|
19
|
|
20 ;; You should have received a copy of the GNU General Public License
|
14169
|
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
23 ;; Boston, MA 02111-1307, USA.
|
4171
|
24
|
|
25 ;;; Commentary:
|
|
26
|
14018
|
27 ;; Note: Metamail does not have all options which are compatible with
|
|
28 ;; the environment variables. For that reason, metamail.el has to
|
4171
|
29 ;; hack the environment variables. In addition, there is no way to
|
|
30 ;; display all header fields without extra informative body messages
|
|
31 ;; which is suppressed by "-q" option.
|
|
32
|
|
33 ;; The idea of using metamail to process MIME messages is from
|
|
34 ;; gnus-mime.el by Spike <Spike@world.std.com>.
|
|
35
|
|
36 ;;; Code:
|
|
37
|
|
38 (defvar metamail-program-name "metamail"
|
|
39 "*Metamail program name.")
|
|
40
|
|
41 (defvar metamail-environment '("KEYHEADS=*")
|
|
42 "*Environment variables passed to `metamail'.
|
|
43 It must ba a list of strings that have the format ENVVARNAME=VALUE.")
|
|
44
|
|
45 (defvar metamail-switches '("-m" "emacs" "-x" "-d" "-z")
|
|
46 "*Switches for `metamail' program.
|
|
47 -z is required to remove zap file.")
|
|
48
|
|
49 (defun metamail-buffer (&optional buffer nodisplay)
|
|
50 "Process current buffer through `metamail'.
|
|
51 Optional 1st argument BUFFER specifies a buffer to be filled (nil
|
|
52 means current).
|
|
53 Optional 2nd argument NODISPLAY non-nil means buffer is not
|
|
54 redisplayed as output is inserted."
|
|
55 (interactive)
|
|
56 (metamail-region (point-min) (point-max) buffer nodisplay))
|
|
57
|
|
58 (defun metamail-region (beg end &optional buffer nodisplay)
|
|
59 "Process current region through 'metamail'.
|
|
60 Optional 1st argument BUFFER specifies a buffer to be filled (nil
|
|
61 means current).
|
|
62 Optional 2nd argument NODISPLAY non-nil means buffer is not
|
|
63 redisplayed as output is inserted."
|
|
64 (interactive "r")
|
|
65 (let ((curbuf (current-buffer))
|
|
66 (buffer-read-only nil)
|
|
67 (metafile (make-temp-name "/tmp/metamail")))
|
|
68 (save-excursion
|
14018
|
69 ;; Gee! Metamail does not output to stdout if input comes from
|
4171
|
70 ;; stdin.
|
|
71 (write-region beg end metafile nil 'nomessage)
|
|
72 (if buffer
|
|
73 (set-buffer buffer))
|
|
74 (setq buffer-read-only nil)
|
|
75 ;; Clear destination buffer.
|
|
76 (if (eq curbuf (current-buffer))
|
|
77 (delete-region beg end)
|
|
78 (delete-region (point-min) (point-max)))
|
|
79 ;; We have to pass the environment variable KEYHEADS to display
|
|
80 ;; all header fields. Metamail should have an optional argument
|
|
81 ;; to pass such information directly.
|
|
82 (let ((process-environment
|
|
83 (append metamail-environment process-environment)))
|
|
84 (apply (function call-process)
|
|
85 metamail-program-name
|
|
86 nil
|
|
87 t ;Output to current buffer
|
|
88 (not nodisplay) ;Force redisplay
|
|
89 (append metamail-switches (list metafile))))
|
|
90 ;; `metamail' may not delete the temporary file!
|
|
91 (condition-case error
|
|
92 (delete-file metafile)
|
|
93 (error nil))
|
|
94 )))
|
|
95
|
|
96 ;(defun metamail-region (beg end &optional buffer)
|
|
97 ; "Process current region through 'metamail'.
|
|
98 ;Optional argument BUFFER specifies a buffer to be filled (nil means current)."
|
|
99 ; (interactive "r")
|
|
100 ; (let ((curbuf (current-buffer))
|
|
101 ; (buffer-read-only nil)
|
|
102 ; (metafile (make-temp-name "/tmp/metamail")))
|
|
103 ; (save-excursion
|
|
104 ; (write-region (point-min) (point-max) metafile nil 'nomessage)
|
|
105 ; (if (eq curbuf
|
|
106 ; (if buffer (get-buffer buffer) (current-buffer)))
|
|
107 ; (delete-region (point-min) (point-max)))
|
|
108 ; (apply (function call-process)
|
|
109 ; metamail-program-name
|
|
110 ; nil
|
|
111 ; (or buffer t) ;BUFFER or current buffer
|
|
112 ; nil ;don't redisplay
|
|
113 ; (append metamail-switches (list metafile)))
|
|
114 ; )))
|
|
115
|
|
116 (provide 'metamail)
|
|
117
|
|
118 ;;; metamail.el ends here
|