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