123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- (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
- :group 'metamail)
- (defcustom metamail-mailer-name "emacs"
- "*Mailer name set to MM_MAILER environment variable."
- :type 'string
- :group 'metamail)
- (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"))
- :group 'metamail)
- (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
- (append metamail-switches '("-c" "text/plain" "-E" "7bit")))
- (end (progn
- (goto-char (point-min))
- (search-forward "\n\n" nil 'move)
-
-
-
- (insert "\n")
- (point))))
- (metamail-region (point-min) end nil nil 'nodisplay)
-
- (goto-char (point-min))
- (if (search-forward "\n\n\n" nil t)
- (delete-char -1))
- )))
- (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))))
-
- (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")))
-
- (let ((metamail-switches
- (append metamail-switches
- (list "-b" "-c" contype "-E" encoding))))
- (metamail-region end (point-max) viewmode nil nodisplay))
-
-
-
-
-
-
-
-
-
-
-
- )))
- (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))
- (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
-
-
- (let ((selective-display nil))
- (write-region beg end metafile nil 'nomessage))
- (if buffer
- (set-buffer buffer))
- (setq buffer-read-only nil)
-
- (if (eq curbuf (current-buffer))
- (delete-region beg end)
- (delete-region (point-min) (point-max)))
-
-
-
- (let ((process-environment
- (append process-environment
- metamail-environment option-environment))
- (coding-system-for-read 'undecided))
- (apply (function call-process)
- metamail-program-name
- nil
- t
- (not nodisplay)
- (append metamail-switches
- (list "-m" (or metamail-mailer-name "emacs"))
- (list metafile))))
-
- (condition-case error
- (delete-file metafile)
- (error nil))
- )))
- (provide 'metamail)
|