annotate lisp/mail/metamail.el @ 17011:d6a6cfeb9904

(rmail-file-coding-system): New variable. (rmail-insert-inbox-text): Perform character code conversion according to rmail-file-coding-system. (rmail-only-expunge): Pay attention to multibyte characters.
author Karl Heuer <kwzh@gnu.org>
date Thu, 20 Feb 1997 05:49:08 +0000
parents 4dbe0f673671
children e9949b093b46
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
15051
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
3 ;; Copyright (C) 1993, 1996 Masanobu UMEDA
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>
15051
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
6 ;; Version: $Header: metamail.el,v 1.10 96/04/18 11:27:08 umerin Exp $
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
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
30
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
31 ;; 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
32 ;; the environment variables. For that reason, matamail.el have to
4171
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;; hack the environment variables. In addition, there is no way to
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;; 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
35 ;; which are suppressed by "-q" option.
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
36
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
37 ;; 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
38 ;;(setq gnus-show-mime-method
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
39 ;; (function
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
40 ;; (lambda ()
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
41 ;; (metamail-interpret-header)
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
42 ;; (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
43 ;; (append metamail-switches '("-q"))))
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
44 ;; (metamail-interpret-body)))))
4171
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ;; The idea of using metamail to process MIME messages is from
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 ;; gnus-mime.el by Spike <Spike@world.std.com>.
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 ;;; Code:
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 (defvar metamail-program-name "metamail"
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 "*Metamail program name.")
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53
15051
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
54 (defvar metamail-mailer-name "emacs"
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
55 "*Mailer name set to MM_MAILER environment variable.")
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
56
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
57 (defvar metamail-environment '("KEYHEADS=*" "MM_QUIET=1")
4171
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 "*Environment variables passed to `metamail'.
15051
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
59 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
60 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
61 Instead, change its value temporary using `let' or `let*' form.")
4171
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62
15051
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
63 (defvar metamail-switches '("-x" "-d" "-z")
4171
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 "*Switches for `metamail' program.
15051
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
65 `-z' is required to remove zap file.
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
66 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
67 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
68 `-m MAILER' argument is automatically generated from the
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
69 `metamail-mailer-name' variable.")
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
70
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
71 ;;;###autoload
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
72 (defun metamail-interpret-header ()
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
73 "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
74 Its body part is not interpreted at all."
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
75 (interactive)
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
76 (save-excursion
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
77 (let* ((buffer-read-only nil)
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
78 (metamail-switches ;Inhibit processing an empty body.
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
79 (append metamail-switches '("-c" "text/plain" "-E" "7bit")))
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
80 (end (progn
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
81 (goto-char (point-min))
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
82 (search-forward "\n\n" nil 'move)
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
83 ;; 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
84 ;; 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
85 ;; itself.
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
86 (insert "\n")
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
87 (point))))
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
88 (metamail-region (point-min) end nil nil 'nodisplay)
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
89 ;; Remove an extra newline inserted by myself.
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
90 (goto-char (point-min))
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
91 (if (search-forward "\n\n\n" nil t)
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
92 (delete-char -1))
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
93 )))
4171
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94
15051
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
95 ;;;###autoload
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
96 (defun metamail-interpret-body (&optional viewmode nodisplay)
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
97 "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
98 Optional argument VIEWMODE specifies the value of the
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
99 EMACS_VIEW_MODE environment variable (defaulted to 1).
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
100 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
101 redisplayed as output is inserted.
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
102 Its header part is not interpreted at all."
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
103 (interactive "p")
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
104 (save-excursion
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
105 (let ((contype nil)
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
106 (encoding nil)
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
107 (end (progn
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
108 (goto-char (point-min))
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
109 (search-forward "\n\n" nil t)
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
110 (point))))
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
111 ;; 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
112 (save-restriction
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
113 (narrow-to-region (point-min) end)
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
114 (setq contype
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
115 (or (mail-fetch-field "Content-Type") "text/plain"))
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
116 (setq encoding
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
117 (or (mail-fetch-field "Content-Transfer-Encoding") "7bit")))
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
118 ;; Interpret the body part only.
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
119 (let ((metamail-switches ;Process body part only.
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
120 (append metamail-switches
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
121 (list "-b" "-c" contype "-E" encoding))))
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
122 (metamail-region end (point-max) viewmode nil nodisplay))
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
123 ;; Mode specific hack.
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
124 (cond ((eq major-mode 'rmail-mode)
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
125 ;; 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
126 (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
127 (point-max))))
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
128 )))
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
129
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
130 ;;;###autoload
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
131 (defun metamail-buffer (&optional viewmode buffer nodisplay)
4171
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 "Process current buffer through `metamail'.
15051
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
133 Optional argument VIEWMODE specifies the value of the
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
134 EMACS_VIEW_MODE environment variable (defaulted to 1).
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
135 Optional argument BUFFER specifies a buffer to be filled (nil
4171
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 means current).
15051
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
137 Optional argument NODISPLAY non-nil means buffer is not
4171
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 redisplayed as output is inserted."
15051
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
139 (interactive "p")
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
140 (metamail-region (point-min) (point-max) viewmode buffer nodisplay))
4171
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141
15051
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
142 ;;;###autoload
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
143 (defun metamail-region (beg end &optional viewmode buffer nodisplay)
4171
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 "Process current region through 'metamail'.
15051
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
145 Optional argument VIEWMODE specifies the value of the
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
146 EMACS_VIEW_MODE environment variable (defaulted to 1).
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
147 Optional argument BUFFER specifies a buffer to be filled (nil
4171
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 means current).
15051
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
149 Optional argument NODISPLAY non-nil means buffer is not
4171
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 redisplayed as output is inserted."
15051
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
151 (interactive "r\np")
4171
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 (let ((curbuf (current-buffer))
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 (buffer-read-only nil)
15051
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
154 (metafile (make-temp-name "/tmp/metamail"))
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
155 (option-environment
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
156 (list (concat "EMACS_VIEW_MODE="
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
157 (if (numberp viewmode) viewmode 1)))))
4171
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 (save-excursion
15051
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
159 ;; 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
160 ;; stdin.
15051
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
161 (let ((selective-display nil) ;Disable ^M to nl translation.
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
162 (kanji-fileio-code 2) ;Write in JIS code when nemacs.
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
163 (file-coding-system ;Write in JUNET style when mule.
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
164 (if (featurep 'mule) *junet*)))
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
165 (write-region beg end metafile nil 'nomessage))
4171
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 (if buffer
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 (set-buffer buffer))
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 (setq buffer-read-only nil)
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 ;; Clear destination buffer.
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 (if (eq curbuf (current-buffer))
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 (delete-region beg end)
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 (delete-region (point-min) (point-max)))
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 ;; We have to pass the environment variable KEYHEADS to display
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 ;; all header fields. Metamail should have an optional argument
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 ;; to pass such information directly.
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 (let ((process-environment
15051
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
177 (append process-environment
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
178 metamail-environment option-environment)))
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
179 ;; Specify character coding system.
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
180 (if (boundp 'NEMACS)
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
181 (define-program-kanji-code nil metamail-program-name 2)) ;JIS
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
182 (if (featurep 'mule)
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
183 (define-program-coding-system nil metamail-program-name *junet*))
4171
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 (apply (function call-process)
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 metamail-program-name
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 nil
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 t ;Output to current buffer
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 (not nodisplay) ;Force redisplay
15051
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
189 (append metamail-switches
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
190 (list "-m" (or metamail-mailer-name "emacs"))
4dbe0f673671 (metamail-mailer-name): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 14994
diff changeset
191 (list metafile))))
4171
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 ;; `metamail' may not delete the temporary file!
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 (condition-case error
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 (delete-file metafile)
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 (error nil))
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 )))
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 (provide 'metamail)
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199
341cd3b063ae entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 ;;; metamail.el ends here