1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-11-23 07:19:15 +00:00
emacs/lisp/obsolete/metamail.el
Stefan Monnier 79d585c2be * lisp/obsolete: Use lexical-binding
Use lexical-binding in all the lisp/obsolete/*.el files.
While at it, removed redundant :group arguments and used #' to quote
functions.  Commented out the key bindings which the #' revealed
to lead to non-existing commands, and replaced those revealed to be obsolete.

* lisp/obsolete/cl-compat.el: Use cl-lib.

* lisp/obsolete/cust-print.el: Assume `defalias` exists.
(with-custom-print): Use `declare`.

* lisp/obsolete/iswitchb.el (iswitchb-init-XEmacs-trick)
(iswitchb-xemacs-backspacekey): Remove functions.

* lisp/obsolete/landmark.el (landmark, landmark-nslify-wts):
Prefer `apply` to `eval`.

* lisp/obsolete/longlines.el (longlines-mode): Don't use `add-to-list`
on a hook.

* lisp/obsolete/pgg-gpg.el (pgg-gpg-process-region): Use `clear-string`.

* lisp/obsolete/pgg-pgp.el (pgg-pgp-encrypt-region): Remove oddly
unused var `passphrase`.
(pgg-pgp-verify-region): Declare var `jam-zcat-filename-list`.

* lisp/obsolete/pgg-pgp5.el (pgg-pgp5-encrypt-region): Remove oddly
unused var `passphrase`.
(pgg-pgp5-verify-region): Declare var `jam-zcat-filename-list`.

* lisp/obsolete/pgg.el: Remove some XEmacs compatibility code.
(pgg-run-at-time, pgg-cancel-timer, pgg-clear-string): Remove functions.
Use their core equivalent instead.

* lisp/obsolete/rcompile.el (remote-compile): Remove unused vars `l`,
`l-host`, `l-user`, and `localname`.

* lisp/obsolete/starttls.el (starttls-any-program-available):
Use `define-obsolete-function-alias`.

* lisp/obsolete/tls.el (tls-format-message): Delete function, use
`format-message` instead.

* lisp/obsolete/url-ns.el (url-ns-prefs): Use `with-current-buffer`
and `dlet`.

* lisp/obsolete/vip.el (vip-escape-to-emacs): Remove unused var `key`.
(vip-command-argument, vip-read-string, ex-delete, ex-line): Remove
unused var `conditions`.
(ex-map): Use a closure instead of `eval`.
(ex-set): Make it an alias of `set-variable`.
(ex-substitute): Remove unused var `cont`.

* lisp/obsolete/abbrevlist.el:
* lisp/obsolete/bruce.el:
* lisp/obsolete/cc-compat.el:
* lisp/obsolete/cl-compat.el:
* lisp/obsolete/cl.el:
* lisp/obsolete/complete.el:
* lisp/obsolete/crisp.el:
* lisp/obsolete/cust-print.el:
* lisp/obsolete/erc-compat.el:
* lisp/obsolete/erc-hecomplete.el:
* lisp/obsolete/eudcb-ph.el:
* lisp/obsolete/fast-lock.el:
* lisp/obsolete/gs.el:
* lisp/obsolete/gulp.el:
* lisp/obsolete/html2text.el:
* lisp/obsolete/info-edit.el:
* lisp/obsolete/iswitchb.el:
* lisp/obsolete/landmark.el:
* lisp/obsolete/lazy-lock.el:
* lisp/obsolete/longlines.el:
* lisp/obsolete/mailpost.el:
* lisp/obsolete/mantemp.el:
* lisp/obsolete/meese.el:
* lisp/obsolete/messcompat.el:
* lisp/obsolete/metamail.el:
* lisp/obsolete/mouse-sel.el:
* lisp/obsolete/nnir.el:
* lisp/obsolete/old-emacs-lock.el:
* lisp/obsolete/otodo-mode.el:
* lisp/obsolete/patcomp.el:
* lisp/obsolete/pc-mode.el:
* lisp/obsolete/pc-select.el:
* lisp/obsolete/pgg-def.el:
* lisp/obsolete/pgg-gpg.el:
* lisp/obsolete/pgg-parse.el:
* lisp/obsolete/pgg-pgp.el:
* lisp/obsolete/pgg-pgp5.el:
* lisp/obsolete/pgg.el:
* lisp/obsolete/rcompile.el:
* lisp/obsolete/s-region.el:
* lisp/obsolete/sb-image.el:
* lisp/obsolete/sregex.el:
* lisp/obsolete/starttls.el:
* lisp/obsolete/sup-mouse.el:
* lisp/obsolete/terminal.el:
* lisp/obsolete/tls.el:
* lisp/obsolete/tpu-edt.el:
* lisp/obsolete/tpu-extras.el:
* lisp/obsolete/tpu-mapper.el:
* lisp/obsolete/url-ns.el:
* lisp/obsolete/vc-arch.el:
* lisp/obsolete/vi.el:
* lisp/obsolete/vip.el:
* lisp/obsolete/ws-mode.el:
* lisp/obsolete/yow.el: Use lexical-binding.
2021-02-22 16:54:59 -05:00

201 lines
7.5 KiB
EmacsLisp

;;; metamail.el --- Metamail interface for GNU Emacs -*- lexical-binding: t; -*-
;; Copyright (C) 1993, 1996, 2001-2021 Free Software Foundation, Inc.
;; Author: Masanobu UMEDA <umerin@mse.kyutech.ac.jp>
;; Keywords: mail, news, mime, multimedia
;; Obsolete-since: 28.1
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; Note: Metamail does not have all the options which are compatible with
;; the environment variables. For that reason, metamail.el has to
;; hack the environment variables. In addition, there is no way to
;; display all header fields without extra informative body messages
;; which are suppressed by the "-q" option.
;; The idea of using metamail to process MIME messages is from
;; gnus-mime.el by Spike <Spike@world.std.com>.
;;; Code:
(defvar rmail-current-message)
(defvar rmail-message-vector)
(defgroup metamail nil
"Metamail interface for Emacs."
:group 'mail
:group 'processes)
(defcustom metamail-program-name "metamail"
"Metamail program name."
:type 'string)
(defcustom metamail-mailer-name "emacs"
"Mailer name set to MM_MAILER environment variable."
:type 'string)
(defvar metamail-environment '("KEYHEADS=*" "MM_QUIET=1")
"Environment variables passed to `metamail'.
It must be a list of strings that have the format ENVVARNAME=VALUE.
It is not expected to be altered globally by `set' or `setq'.
Instead, change its value temporary using `let' or `let*' form.")
(defcustom metamail-switches '("-x" "-d" "-z")
"Switches for `metamail' program.
`-z' is required to remove zap file.
It is not expected to be altered globally by `set' or `setq'.
Instead, change its value temporary using `let' or `let*' form.
`-m MAILER' argument is automatically generated from the
`metamail-mailer-name' variable."
:type '(repeat (string :tag "Switch")))
;;;###autoload
(defun metamail-interpret-header ()
"Interpret a header part of a MIME message in current buffer.
Its body part is not interpreted at all."
(interactive)
(save-excursion
(let* ((buffer-read-only nil)
(metamail-switches ;Inhibit processing an empty body.
(append metamail-switches '("-c" "text/plain" "-E" "7bit")))
(end (progn
(goto-char (point-min))
(search-forward "\n\n" nil 'move)
;; An extra newline is inserted by metamail if there
;; is no body part. So, insert a dummy body by
;; itself.
(insert "\n")
(point))))
(metamail-region (point-min) end nil nil 'nodisplay)
;; Remove an extra newline inserted by myself.
(goto-char (point-min))
(if (search-forward "\n\n\n" nil t)
(delete-char -1))
)))
;;;###autoload
(defun metamail-interpret-body (&optional viewmode nodisplay)
"Interpret a body part of a MIME message in current buffer.
Optional argument VIEWMODE specifies the value of the
EMACS_VIEW_MODE environment variable (defaulted to 1).
Optional argument NODISPLAY non-nil means buffer is not
redisplayed as output is inserted.
Its header part is not interpreted at all."
(interactive "p")
(save-excursion
(let ((contype nil)
(encoding nil)
(end (progn
(goto-char (point-min))
(search-forward "\n\n" nil t)
(point))))
;; Find Content-Type and Content-Transfer-Encoding from the header.
(save-restriction
(narrow-to-region (point-min) end)
(setq contype
(or (mail-fetch-field "Content-Type") "text/plain"))
(setq encoding
(or (mail-fetch-field "Content-Transfer-Encoding") "7bit")))
;; Interpret the body part only.
(let ((metamail-switches ;Process body part only.
(append metamail-switches
(list "-b" "-c" contype "-E" encoding))))
(metamail-region end (point-max) viewmode nil nodisplay))
;; This mode specific hack is no longer appropriate in mbox Rmail.
;; Pre-mbox, we have just modified the actual folder, so we
;; update the message-vector with the new end position of the
;; current message. In mbox Rmail, all we have done is modify a
;; display copy of the message. Note also that point-max is a
;; marker in the wrong buffer: the message-vector contains
;; markers in rmail-view-buffer (which is not in rmail-mode).
;; So this hack actually breaks the message-vector.
;; If you're calling this on the actual rmail-view-buffer (or a
;; non-swapped rmail-buffer), you would still need this hack.
;; But you're not going to do that.
;;; (cond ((eq major-mode 'rmail-mode)
;;; ;; Adjust the marker of this message if in Rmail mode buffer.
;;; (set-marker (aref rmail-message-vector (1+ rmail-current-message))
;;; (point-max))))
)))
;;;###autoload
(defun metamail-buffer (&optional viewmode buffer nodisplay)
"Process current buffer through `metamail'.
Optional argument VIEWMODE specifies the value of the
EMACS_VIEW_MODE environment variable (defaulted to 1).
Optional argument BUFFER specifies a buffer to be filled (nil
means current).
Optional argument NODISPLAY non-nil means buffer is not
redisplayed as output is inserted."
(interactive "p")
(metamail-region (point-min) (point-max) viewmode buffer nodisplay))
;;;###autoload
(defun metamail-region (beg end &optional viewmode buffer nodisplay)
"Process current region through `metamail'.
Optional argument VIEWMODE specifies the value of the
EMACS_VIEW_MODE environment variable (defaulted to 1).
Optional argument BUFFER specifies a buffer to be filled (nil
means current).
Optional argument NODISPLAY non-nil means buffer is not
redisplayed as output is inserted."
(interactive "r\np")
(let ((curbuf (current-buffer))
(buffer-read-only nil)
(metafile (make-temp-file "metamail"))
(option-environment
(list (format "EMACS_VIEW_MODE=%d"
(if (numberp viewmode) viewmode 1)))))
(save-excursion
;; Gee! Metamail does not output to stdout if input comes from
;; stdin.
(let ((selective-display nil)) ;Disable ^M to nl translation.
(write-region beg end metafile nil 'nomessage))
(if buffer
(set-buffer buffer))
(setq buffer-read-only nil)
;; Clear destination buffer.
(if (eq curbuf (current-buffer))
(delete-region beg end)
(delete-region (point-min) (point-max)))
;; We have to pass the environment variable KEYHEADS to display
;; all header fields. Metamail should have an optional argument
;; to pass such information directly.
(let ((process-environment
(append process-environment
metamail-environment option-environment))
(coding-system-for-read 'undecided))
(apply (function call-process)
metamail-program-name
nil
t ;Output to current buffer
(not nodisplay) ;Force redisplay
(append metamail-switches
(list "-m" (or metamail-mailer-name "emacs"))
(list metafile))))
;; `metamail' may not delete the temporary file!
(condition-case nil
(delete-file metafile)
(error nil))
)))
(provide 'metamail)
;;; metamail.el ends here