annotate lisp/mail/metamail.el @ 25706:498eb90e1723

(shell-quote-argument): Quote argument with double quotes for ms-dos.
author Eli Zaretskii <eliz@gnu.org>
date Tue, 14 Sep 1999 10:11:19 +0000
parents ebadb1855668
children fb6b9c37cdc4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4171
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;;; metamail.el --- Metamail interface for GNU Emacs
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2
22154
86791cda515c Update copyright notice.
Richard M. Stallman <rms@gnu.org>
parents: 18964
diff changeset
3 ;; Copyright (C) 1993, 1996 Free Software Foundation, Inc.
4171
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 ;; Author: Masanobu UMEDA <umerin@mse.kyutech.ac.jp>
25419
ebadb1855668 (metamail-region): Use temporary-file-directory.
Richard M. Stallman <rms@gnu.org>
parents: 24043
diff changeset
6 ;; Version: $Id: metamail.el,v 1.11 1999/01/11 12:36:15 fx Exp rms $
4171
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; Keywords: mail, news, mime, multimedia
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; any later version.
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14018
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14018
diff changeset
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14018
diff changeset
24 ;; Boston, MA 02111-1307, USA.
4171
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;;; Commentary:
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27
15051
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
28 ;; The latest version will be at:
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
29 ;; ftp://ftp.kyutech.ac.jp/pub/MultiMedia/mime/emacs-mime-tools.shar
24043
4307c8044e78 Comment on `latest version'.
Dave Love <fx@gnu.org>
parents: 22426
diff changeset
30 ;; [This is probably _not_ the latest version; as of Jan 1999, it
4307c8044e78 Comment on `latest version'.
Dave Love <fx@gnu.org>
parents: 22426
diff changeset
31 ;; is dated 1995.]
15051
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
32
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
33 ;; Note: Metamail does not have all options which is compatible with
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
34 ;; the environment variables. For that reason, matamail.el have to
4171
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;; hack the environment variables. In addition, there is no way to
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 ;; display all header fields without extra informative body messages
15051
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
37 ;; which are suppressed by "-q" option.
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
38
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
39 ;; The following definition is what I'm using with GNUS 4:
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
40 ;;(setq gnus-show-mime-method
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
41 ;; (function
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
42 ;; (lambda ()
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
43 ;; (metamail-interpret-header)
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
44 ;; (let ((metamail-switches ;Suppress header fields in a body.
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
45 ;; (append metamail-switches '("-q"))))
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
46 ;; (metamail-interpret-body)))))
4171
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 ;; The idea of using metamail to process MIME messages is from
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 ;; gnus-mime.el by Spike <Spike@world.std.com>.
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 ;;; Code:
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52
17663
d2c64a1563f7 Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 17661
diff changeset
53 (defgroup metamail nil
d2c64a1563f7 Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 17661
diff changeset
54 "Metamail interface for Emacs."
d2c64a1563f7 Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 17661
diff changeset
55 :group 'mail
d2c64a1563f7 Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 17661
diff changeset
56 :group 'hypermedia
d2c64a1563f7 Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 17661
diff changeset
57 :group 'processes)
4171
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58
17663
d2c64a1563f7 Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 17661
diff changeset
59 (defcustom metamail-program-name "metamail"
d2c64a1563f7 Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 17661
diff changeset
60 "*Metamail program name."
d2c64a1563f7 Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 17661
diff changeset
61 :type 'string
d2c64a1563f7 Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 17661
diff changeset
62 :group 'metamail)
d2c64a1563f7 Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 17661
diff changeset
63
d2c64a1563f7 Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 17661
diff changeset
64 (defcustom metamail-mailer-name "emacs"
d2c64a1563f7 Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 17661
diff changeset
65 "*Mailer name set to MM_MAILER environment variable."
d2c64a1563f7 Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 17661
diff changeset
66 :type 'string
d2c64a1563f7 Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 17661
diff changeset
67 :group 'metamail)
15051
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
68
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
69 (defvar metamail-environment '("KEYHEADS=*" "MM_QUIET=1")
4171
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 "*Environment variables passed to `metamail'.
15051
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
71 It must be a list of strings that have the format ENVVARNAME=VALUE.
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
72 It is not expected to be altered globally by `set' or `setq'.
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
73 Instead, change its value temporary using `let' or `let*' form.")
4171
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74
17663
d2c64a1563f7 Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 17661
diff changeset
75 (defcustom metamail-switches '("-x" "-d" "-z")
4171
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 "*Switches for `metamail' program.
15051
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
77 `-z' is required to remove zap file.
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
78 It is not expected to be altered globally by `set' or `setq'.
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
79 Instead, change its value temporary using `let' or `let*' form.
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
80 `-m MAILER' argument is automatically generated from the
17663
d2c64a1563f7 Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 17661
diff changeset
81 `metamail-mailer-name' variable."
d2c64a1563f7 Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 17661
diff changeset
82 :type '(repeat (string :tag "Switch"))
d2c64a1563f7 Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 17661
diff changeset
83 :group 'metamail)
15051
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
84
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
85 ;;;###autoload
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
86 (defun metamail-interpret-header ()
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
87 "Interpret a header part of a MIME message in current buffer.
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
88 Its body part is not interpreted at all."
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
89 (interactive)
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
90 (save-excursion
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
91 (let* ((buffer-read-only nil)
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
92 (metamail-switches ;Inhibit processing an empty body.
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
93 (append metamail-switches '("-c" "text/plain" "-E" "7bit")))
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
94 (end (progn
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
95 (goto-char (point-min))
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
96 (search-forward "\n\n" nil 'move)
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
97 ;; An extra newline is inserted by metamail if there
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
98 ;; is no body part. So, insert a dummy body by
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
99 ;; itself.
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
100 (insert "\n")
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
101 (point))))
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
102 (metamail-region (point-min) end nil nil 'nodisplay)
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
103 ;; Remove an extra newline inserted by myself.
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
104 (goto-char (point-min))
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
105 (if (search-forward "\n\n\n" nil t)
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
106 (delete-char -1))
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
107 )))
4171
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108
15051
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
109 ;;;###autoload
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
110 (defun metamail-interpret-body (&optional viewmode nodisplay)
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
111 "Interpret a body part of a MIME message in current buffer.
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
112 Optional argument VIEWMODE specifies the value of the
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
113 EMACS_VIEW_MODE environment variable (defaulted to 1).
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
114 Optional argument NODISPLAY non-nil means buffer is not
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
115 redisplayed as output is inserted.
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
116 Its header part is not interpreted at all."
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
117 (interactive "p")
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
118 (save-excursion
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
119 (let ((contype nil)
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
120 (encoding nil)
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
121 (end (progn
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
122 (goto-char (point-min))
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
123 (search-forward "\n\n" nil t)
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
124 (point))))
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
125 ;; Find Content-Type and Content-Transfer-Encoding from the header.
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
126 (save-restriction
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
127 (narrow-to-region (point-min) end)
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
128 (setq contype
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
129 (or (mail-fetch-field "Content-Type") "text/plain"))
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
130 (setq encoding
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
131 (or (mail-fetch-field "Content-Transfer-Encoding") "7bit")))
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
132 ;; Interpret the body part only.
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
133 (let ((metamail-switches ;Process body part only.
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
134 (append metamail-switches
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
135 (list "-b" "-c" contype "-E" encoding))))
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
136 (metamail-region end (point-max) viewmode nil nodisplay))
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
137 ;; Mode specific hack.
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
138 (cond ((eq major-mode 'rmail-mode)
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
139 ;; Adjust the marker of this message if in Rmail mode buffer.
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
140 (set-marker (aref rmail-message-vector (1+ rmail-current-message))
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
141 (point-max))))
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
142 )))
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
143
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
144 ;;;###autoload
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
145 (defun metamail-buffer (&optional viewmode buffer nodisplay)
4171
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 "Process current buffer through `metamail'.
15051
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
147 Optional argument VIEWMODE specifies the value of the
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
148 EMACS_VIEW_MODE environment variable (defaulted to 1).
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
149 Optional argument BUFFER specifies a buffer to be filled (nil
4171
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 means current).
15051
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
151 Optional argument NODISPLAY non-nil means buffer is not
4171
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 redisplayed as output is inserted."
15051
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
153 (interactive "p")
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
154 (metamail-region (point-min) (point-max) viewmode buffer nodisplay))
4171
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155
15051
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
156 ;;;###autoload
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
157 (defun metamail-region (beg end &optional viewmode buffer nodisplay)
4171
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 "Process current region through 'metamail'.
15051
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
159 Optional argument VIEWMODE specifies the value of the
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
160 EMACS_VIEW_MODE environment variable (defaulted to 1).
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
161 Optional argument BUFFER specifies a buffer to be filled (nil
4171
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 means current).
15051
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
163 Optional argument NODISPLAY non-nil means buffer is not
4171
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 redisplayed as output is inserted."
15051
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
165 (interactive "r\np")
4171
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 (let ((curbuf (current-buffer))
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 (buffer-read-only nil)
25419
ebadb1855668 (metamail-region): Use temporary-file-directory.
Richard M. Stallman <rms@gnu.org>
parents: 24043
diff changeset
168 (metafile (make-temp-name (expand-file-name "metamail" temporary-file-directory)))
15051
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
169 (option-environment
22426
76657a0a9c70 (metamail-region): Don't use concat with
Dave Love <fx@gnu.org>
parents: 22154
diff changeset
170 (list (format "EMACS_VIEW_MODE=%d"
15051
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
171 (if (numberp viewmode) viewmode 1)))))
4171
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 (save-excursion
15051
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
173 ;; Gee! Metamail does not ouput to stdout if input comes from
4171
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 ;; stdin.
18964
10af35406220 (metamail-region): Don't bind kanji-fileio-code
Richard M. Stallman <rms@gnu.org>
parents: 17663
diff changeset
175 (let ((selective-display nil)) ;Disable ^M to nl translation.
15051
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
176 (write-region beg end metafile nil 'nomessage))
4171
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 (if buffer
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 (set-buffer buffer))
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 (setq buffer-read-only nil)
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 ;; Clear destination buffer.
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 (if (eq curbuf (current-buffer))
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 (delete-region beg end)
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 (delete-region (point-min) (point-max)))
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 ;; We have to pass the environment variable KEYHEADS to display
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 ;; all header fields. Metamail should have an optional argument
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 ;; to pass such information directly.
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 (let ((process-environment
15051
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
188 (append process-environment
18964
10af35406220 (metamail-region): Don't bind kanji-fileio-code
Richard M. Stallman <rms@gnu.org>
parents: 17663
diff changeset
189 metamail-environment option-environment))
10af35406220 (metamail-region): Don't bind kanji-fileio-code
Richard M. Stallman <rms@gnu.org>
parents: 17663
diff changeset
190 (coding-system-for-read 'undecided))
4171
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 (apply (function call-process)
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 metamail-program-name
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 nil
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 t ;Output to current buffer
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 (not nodisplay) ;Force redisplay
15051
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
196 (append metamail-switches
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
197 (list "-m" (or metamail-mailer-name "emacs"))
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
198 (list metafile))))
4171
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 ;; `metamail' may not delete the temporary file!
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 (condition-case error
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 (delete-file metafile)
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 (error nil))
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 )))
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 (provide 'metamail)
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 ;;; metamail.el ends here