1 ;;; mh-mime --- mh-e support for composing MIME messages
2 ;; Time-stamp: <95/08/19 16:45:17 gildea>
4 ;; Copyright (C) 1993, 1995 Free Software Foundation, Inc.
6 ;; This file is part of mh-e, part of GNU Emacs.
8 ;; GNU Emacs is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; GNU Emacs is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GNU Emacs; see the file COPYING. If not, write to the
20 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 ;; Boston, MA 02111-1307, USA.
25 ;; Internal support for mh-e package.
26 ;; Support for generating an mhn composition file.
27 ;; MIME is supported only by MH 6.8 or later.
31 ;; $Id: mh-mime.el,v 1.5 1995/11/03 02:29:49 kwzh Exp erik $
40 ;; paragraph code should not fill # lines if MIME enabled.
41 ;; implement mh-auto-edit-mhn (if non-nil, \\[mh-send-letter]
42 ;; invokes mh-edit-mhn automatically before sending.)
43 ;; actually, instead of mh-auto-edit-mhn,
44 ;; should read automhnproc from profile
45 ;; MIME option to mh-forward
46 ;; command to move to content-description insertion point
48 (defvar mh-mhn-args nil
49 "Extra arguments to have \\[mh-edit-mhn] pass to the \"mhn\" command.
50 The arguments are passed to mhn if \\[mh-edit-mhn] is given a
51 prefix argument. Normally default arguments to mhn are specified in the
54 (defvar mh-edit-mhn-hook nil
55 "Invoked on the formatted letter by \\<mh-letter-mode-map>\\[mh-edit-mhn].")
58 (defvar mh-mime-content-types
59 '(("text/plain") ("text/richtext")
60 ("multipart/mixed") ("multipart/alternative") ("multipart/digest")
61 ("multipart/parallel")
62 ("message/rfc822") ("message/partial") ("message/external-body")
63 ("application/octet-stream") ("application/postscript")
64 ("image/jpeg") ("image/gif")
67 "Legal MIME content types. See documentation for \\[mh-edit-mhn].")
69 (defun mh-mhn-compose-insertion (pathname type description
)
70 "Add a directive to insert a MIME message part from a file.
71 This is the typical way to insert non-text parts in a message.
72 Arguments are PATHNAME, which tells where to find the file, TYPE, the
73 MIME content type, and DESCRIPTION, a line of text for the
74 Content-description header. See also \\[mh-edit-mhn]."
76 (read-file-name "Insert contents of: ")
77 (completing-read "Content-type: "
78 mh-mime-content-types nil nil nil
)
79 (read-string "Content-description: ")))
80 (mh-mhn-compose-type pathname type description
))
82 (defun mh-mhn-compose-type (pathname type
83 &optional description attributes comment
)
87 (insert "; " attributes
))
89 (insert " (" comment
")"))
93 (insert "] " (expand-file-name pathname
))
97 (defun mh-mhn-compose-anon-ftp (host pathname type description
)
98 "Add a directive for a MIME anonymous ftp external body part.
99 This directive tells MH to include a reference to a
100 message/external-body part retrievable by anonymous FTP. Arguments
101 are HOST and PATHNAME, which tell where to find the file, TYPE, the
102 MIME content type, and DESCRIPTION, a line of text for the
103 Content-description header. See also \\[mh-edit-mhn]."
105 (read-string "Remote host: ")
106 (read-string "Remote pathname: ")
107 (completing-read "External Content-type: "
108 mh-mime-content-types nil nil nil
)
109 (read-string "External Content-description: ")))
110 (mh-mhn-compose-external-type "anon-ftp" host pathname
113 (defun mh-mhn-compose-external-compressed-tar (host pathname description
)
114 "Add a directive to include a MIME reference to a compressed tar file.
115 The file should be available via anonymous ftp. This directive
116 tells MH to include a reference to a message/external-body part.
117 Arguments are HOST and PATHNAME, which tell where to find the file, and
118 DESCRIPTION, a line of text for the Content-description header.
119 See also \\[mh-edit-mhn]."
121 (read-string "Remote host: ")
122 (read-string "Remote pathname: ")
123 (read-string "Tar file Content-description: ")))
124 (mh-mhn-compose-external-type "anon-ftp" host pathname
125 "application/octet-stream"
127 "type=tar; conversions=x-compress"
131 (defun mh-mhn-compose-external-type (access-type host pathname type
132 &optional description
133 attributes extra-params comment
)
137 (insert "; " attributes
))
139 (insert " (" comment
") "))
142 (insert description
))
144 (insert "access-type=" access-type
"; ")
145 (insert "site=" host
)
146 (insert "; name=" (file-name-nondirectory pathname
))
147 (insert "; directory=\"" (file-name-directory pathname
) "\"")
149 (insert "; " extra-params
))
152 (defun mh-mhn-compose-forw (&optional description folder messages
)
153 "Add a forw directive to this message, to forward a message with MIME.
154 This directive tells MH to include the named messages in this one.
155 Arguments are DESCRIPTION, a line of text for the Content-description header,
156 and FOLDER and MESSAGES, which name the message(s) to be forwarded.
157 See also \\[mh-edit-mhn]."
159 (read-string "Forw Content-description: ")
160 (mh-prompt-for-folder "Message from" mh-sent-from-folder nil
)
161 (read-string (format "Messages%s: "
163 (format " [%d]" mh-sent-from-msg
)
168 (not (string= description
""))
169 (insert description
))
172 (not (string= folder
""))
175 (not (string= messages
"")))
176 (let ((start (point)))
177 (insert " " messages
)
178 (subst-char-in-region start
(point) ?
, ?
))
180 (insert " " (int-to-string mh-sent-from-msg
))))
183 (defun mh-edit-mhn (&optional extra-args
)
184 "Format the current draft for MIME, expanding any mhn directives.
185 Process the current draft with the mhn program, which,
186 using directives already inserted in the draft, fills in
187 all the MIME components and header fields.
188 This step should be done last just before sending the message.
189 The mhn program is part of MH version 6.8 or later.
190 The `\\[mh-revert-mhn-edit]' command undoes this command.
191 The arguments in the list `mh-mhn-args' are passed to mhn
192 if this function is passed an argument.
194 For assistance with creating mhn directives to insert
195 various types of components in a message, see
196 \\[mh-mhn-compose-insertion] (generic insertion from a file),
197 \\[mh-mhn-compose-anon-ftp] (external reference to file via anonymous ftp),
198 \\[mh-mhn-compose-external-compressed-tar] \
199 \(reference to compressed tar file via anonymous ftp), and
200 \\[mh-mhn-compose-forw] (forward message)."
203 (message "mhn editing...")
204 (mh-exec-cmd-error (format "mhdraft=%s" buffer-file-name
)
205 "mhn" (if extra-args mh-mhn-args
) buffer-file-name
)
207 (message "mhn editing...done")
208 (run-hooks 'mh-edit-mhn-hook
))
211 (defun mh-revert-mhn-edit (noconfirm)
212 "Undoes the effect of \\[mh-edit-mhn] by reverting to the backup file.
213 Optional non-nil argument means don't ask for confirmation."
215 (if (null buffer-file-name
)
216 (error "Buffer does not seem to be associated with any file"))
217 (let ((backup-strings '("," "#"))
219 (while (and backup-strings
222 (concat (file-name-directory buffer-file-name
)
224 (file-name-nondirectory buffer-file-name
)
226 (setq backup-strings
(cdr backup-strings
)))
228 (error "mhn backup file for %s no longer exists!" buffer-file-name
))
230 (yes-or-no-p (format "Revert buffer from file %s? "
232 (error "mhn edit revert not confirmed."))
233 (let ((buffer-read-only nil
))
235 (insert-file-contents backup-file
))
236 (after-find-file nil
)))