1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2025-01-05 11:45:45 +00:00
emacs/lisp/mail/mh-mime.el

242 lines
8.7 KiB
EmacsLisp
Raw Normal View History

1994-03-15 06:16:30 +00:00
;;; mh-mime --- mh-e support for composing MIME messages
1995-11-03 02:30:17 +00:00
;; Time-stamp: <95/08/19 16:45:17 gildea>
1994-03-15 06:16:30 +00:00
1995-04-09 22:31:08 +00:00
;; Copyright (C) 1993, 1995 Free Software Foundation, Inc.
1994-03-15 06:16:30 +00:00
1995-11-03 02:30:17 +00:00
;; This file is part of mh-e, part of GNU Emacs.
1994-03-15 06:16:30 +00:00
1995-04-10 00:20:07 +00:00
;; GNU Emacs is free software; you can redistribute it and/or modify
1994-03-15 06:16:30 +00:00
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
1995-04-10 00:20:07 +00:00
;; GNU Emacs is distributed in the hope that it will be useful,
1994-03-15 06:16:30 +00:00
;; 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
1996-01-14 07:34:30 +00:00
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
1994-03-15 06:16:30 +00:00
;;; Commentary:
1996-01-14 07:34:30 +00:00
;; Internal support for mh-e package.
;; Support for generating an mhn composition file.
;; MIME is supported only by MH 6.8 or later.
1994-03-15 06:16:30 +00:00
1995-04-09 22:31:08 +00:00
;;; Change Log:
;; $Id: mh-mime.el,v 1.7 1997/01/13 03:25:05 rms Exp kwzh $
1995-04-09 22:31:08 +00:00
1994-03-15 06:16:30 +00:00
;;; Code:
(provide 'mh-mime)
(require 'mh-comp)
;; To do:
;; paragraph code should not fill # lines if MIME enabled.
;; implement mh-auto-edit-mhn (if non-nil, \\[mh-send-letter]
;; invokes mh-edit-mhn automatically before sending.)
;; actually, instead of mh-auto-edit-mhn,
;; should read automhnproc from profile
;; MIME option to mh-forward
;; command to move to content-description insertion point
1995-04-09 22:31:08 +00:00
(defvar mh-mhn-args nil
"Extra arguments to have \\[mh-edit-mhn] pass to the \"mhn\" command.
The arguments are passed to mhn if \\[mh-edit-mhn] is given a
prefix argument. Normally default arguments to mhn are specified in the
MH profile.")
(defvar mh-edit-mhn-hook nil
"Invoked on the formatted letter by \\<mh-letter-mode-map>\\[mh-edit-mhn].")
1995-04-20 23:35:26 +00:00
;;;###autoload
1994-03-15 06:16:30 +00:00
(defvar mh-mime-content-types
'(("text/plain") ("text/richtext")
("multipart/mixed") ("multipart/alternative") ("multipart/digest")
("multipart/parallel")
("message/rfc822") ("message/partial") ("message/external-body")
("application/octet-stream") ("application/postscript")
("image/jpeg") ("image/gif")
("audio/basic")
("video/mpeg"))
1995-04-20 23:35:26 +00:00
"Legal MIME content types. See documentation for \\[mh-edit-mhn].")
1994-03-15 06:16:30 +00:00
(defun mh-mhn-compose-insertion (filename type description attributes)
1995-04-20 23:35:26 +00:00
"Add a directive to insert a MIME message part from a file.
1994-03-15 06:16:30 +00:00
This is the typical way to insert non-text parts in a message.
Arguments are FILENAME, which tells where to find the file, TYPE, the
1995-04-09 22:31:08 +00:00
MIME content type, and DESCRIPTION, a line of text for the
Content-description header. See also \\[mh-edit-mhn]."
(interactive (let ((filename (read-file-name "Insert contents of: ")))
(list
filename
(completing-read "Content-type: "
1994-03-15 06:16:30 +00:00
mh-mime-content-types nil nil nil)
(read-string "Content-description: ")
(read-string "Content-Attributes: "
(concat "name=\""
(file-name-nondirectory filename)
"\"")))))
(mh-mhn-compose-type filename type description attributes ))
1994-03-15 06:16:30 +00:00
(defun mh-mhn-compose-type (filename type
1994-03-15 06:16:30 +00:00
&optional description attributes comment)
(beginning-of-line)
(insert "#" type)
(and attributes
(insert "; " attributes))
(and comment
(insert " (" comment ")"))
(insert " [")
(and description
(insert description))
(insert "] " (expand-file-name filename))
1994-03-15 06:16:30 +00:00
(insert "\n"))
(defun mh-mhn-compose-anon-ftp (host filename type description)
1995-04-20 23:35:26 +00:00
"Add a directive for a MIME anonymous ftp external body part.
1995-04-09 22:31:08 +00:00
This directive tells MH to include a reference to a
message/external-body part retrievable by anonymous FTP. Arguments
are HOST and FILENAME, which tell where to find the file, TYPE, the
1995-04-09 22:31:08 +00:00
MIME content type, and DESCRIPTION, a line of text for the
Content-description header. See also \\[mh-edit-mhn]."
1994-03-15 06:16:30 +00:00
(interactive (list
(read-string "Remote host: ")
(read-string "Remote filename: ")
1994-03-15 06:16:30 +00:00
(completing-read "External Content-type: "
mh-mime-content-types nil nil nil)
(read-string "External Content-description: ")))
(mh-mhn-compose-external-type "anon-ftp" host filename
1994-03-15 06:16:30 +00:00
type description))
(defun mh-mhn-compose-external-compressed-tar (host filename description)
1995-04-20 23:35:26 +00:00
"Add a directive to include a MIME reference to a compressed tar file.
1995-04-09 22:31:08 +00:00
The file should be available via anonymous ftp. This directive
tells MH to include a reference to a message/external-body part.
Arguments are HOST and FILENAME, which tell where to find the file, and
1995-04-09 22:31:08 +00:00
DESCRIPTION, a line of text for the Content-description header.
1994-03-15 06:16:30 +00:00
See also \\[mh-edit-mhn]."
(interactive (list
(read-string "Remote host: ")
(read-string "Remote filename: ")
1994-03-15 06:16:30 +00:00
(read-string "Tar file Content-description: ")))
(mh-mhn-compose-external-type "anon-ftp" host filename
1994-03-15 06:16:30 +00:00
"application/octet-stream"
description
"type=tar; conversions=x-compress"
"mode=image"))
(defun mh-mhn-compose-external-type (access-type host filename type
1994-03-15 06:16:30 +00:00
&optional description
attributes extra-params comment)
(beginning-of-line)
(insert "#@" type)
(and attributes
(insert "; " attributes))
(and comment
(insert " (" comment ") "))
(insert " [")
(and description
(insert description))
(insert "] ")
(insert "access-type=" access-type "; ")
(insert "site=" host)
(insert "; name=" (file-name-nondirectory filename))
(insert "; directory=\"" (file-name-directory filename) "\"")
1994-03-15 06:16:30 +00:00
(and extra-params
(insert "; " extra-params))
(insert "\n"))
1995-04-09 22:31:08 +00:00
(defun mh-mhn-compose-forw (&optional description folder messages)
1995-04-20 23:35:26 +00:00
"Add a forw directive to this message, to forward a message with MIME.
1994-03-15 06:16:30 +00:00
This directive tells MH to include the named messages in this one.
Arguments are DESCRIPTION, a line of text for the Content-description header,
1995-04-20 23:35:26 +00:00
and FOLDER and MESSAGES, which name the message(s) to be forwarded.
1994-03-15 06:16:30 +00:00
See also \\[mh-edit-mhn]."
(interactive (list
(read-string "Forw Content-description: ")
1995-04-09 22:31:08 +00:00
(mh-prompt-for-folder "Message from" mh-sent-from-folder nil)
1994-03-15 06:16:30 +00:00
(read-string (format "Messages%s: "
(if mh-sent-from-msg
(format " [%d]" mh-sent-from-msg)
1995-04-09 22:31:08 +00:00
"")))))
1994-03-15 06:16:30 +00:00
(beginning-of-line)
(insert "#forw [")
(and description
(not (string= description ""))
(insert description))
(insert "]")
(and folder
(not (string= folder ""))
(insert " " folder))
1995-04-09 22:31:08 +00:00
(if (and messages
(not (string= messages "")))
1994-03-15 06:16:30 +00:00
(let ((start (point)))
1995-04-09 22:31:08 +00:00
(insert " " messages)
1994-03-15 06:16:30 +00:00
(subst-char-in-region start (point) ?, ? ))
(if mh-sent-from-msg
(insert " " (int-to-string mh-sent-from-msg))))
(insert "\n"))
1995-04-09 22:31:08 +00:00
(defun mh-edit-mhn (&optional extra-args)
"Format the current draft for MIME, expanding any mhn directives.
Process the current draft with the mhn program, which,
using directives already inserted in the draft, fills in
1994-03-15 06:16:30 +00:00
all the MIME components and header fields.
This step should be done last just before sending the message.
The mhn program is part of MH version 6.8 or later.
The `\\[mh-revert-mhn-edit]' command undoes this command.
1995-04-09 22:31:08 +00:00
The arguments in the list `mh-mhn-args' are passed to mhn
if this function is passed an argument.
For assistance with creating mhn directives to insert
1994-03-15 06:16:30 +00:00
various types of components in a message, see
\\[mh-mhn-compose-insertion] (generic insertion from a file),
\\[mh-mhn-compose-anon-ftp] (external reference to file via anonymous ftp),
\\[mh-mhn-compose-external-compressed-tar] \
\(reference to compressed tar file via anonymous ftp), and
\\[mh-mhn-compose-forw] (forward message)."
1995-04-09 22:31:08 +00:00
(interactive "*P")
1994-03-15 06:16:30 +00:00
(save-buffer)
(message "mhn editing...")
1995-04-09 22:31:08 +00:00
(mh-exec-cmd-error (format "mhdraft=%s" buffer-file-name)
"mhn" (if extra-args mh-mhn-args) buffer-file-name)
1994-03-15 06:16:30 +00:00
(revert-buffer t t)
1995-04-09 22:31:08 +00:00
(message "mhn editing...done")
(run-hooks 'mh-edit-mhn-hook))
1994-03-15 06:16:30 +00:00
(defun mh-revert-mhn-edit (noconfirm)
"Undoes the effect of \\[mh-edit-mhn] by reverting to the backup file.
1995-04-09 22:31:08 +00:00
Optional non-nil argument means don't ask for confirmation."
1994-03-15 06:16:30 +00:00
(interactive "*P")
(if (null buffer-file-name)
(error "Buffer does not seem to be associated with any file"))
(let ((backup-strings '("," "#"))
backup-file)
(while (and backup-strings
(not (file-exists-p
(setq backup-file
(concat (file-name-directory buffer-file-name)
(car backup-strings)
(file-name-nondirectory buffer-file-name)
".orig")))))
(setq backup-strings (cdr backup-strings)))
(or backup-strings
(error "mhn backup file for %s no longer exists!" buffer-file-name))
(or noconfirm
(yes-or-no-p (format "Revert buffer from file %s? "
backup-file))
(error "mhn edit revert not confirmed."))
(let ((buffer-read-only nil))
(erase-buffer)
(insert-file-contents backup-file))
(after-find-file nil)))