-
-;; I really think this function should be renamed. It is only useful
-;; for inserting file attachments.
-
-(defun message-mime-attach-file (file type description)
- "Attach a file to the outgoing MIME message.
-The file is not inserted or encoded until you send the message with
-`\\[message-send-and-exit]' or `\\[message-send]'.
-
-FILE is the name of the file to attach. TYPE is its content-type, a
-string of the form \"type/subtype\". DESCRIPTION is a one-line
-description of the attachment."
- (interactive
- (let* ((file (read-file-name "Attach file: " nil nil t))
- (type (completing-read
- (format "Content type (default %s): "
- (or (mm-default-file-encoding file)
- ;; Perhaps here we should check
- ;; what the file looks like, and
- ;; offer text/plain if it looks
- ;; like text/plain.
- "application/octet-stream"))
- (delete-duplicates
- (mapcar (lambda (m) (list (cdr m))) mailcap-mime-extensions)
- :test 'equal)))
- (description (read-string "One line description: ")))
- (list file type description)))
- (when (string-match "\\`[ \t]*\\'" description)
- (setq description nil))
- (when (string-match "\\`[ \t]*\\'" type)
- (setq type (mm-default-file-encoding file))) nil
- ;; Prevent some common errors. This is inspired by similar code in
- ;; VM.
- (when (file-directory-p file)
- (error "%s is a directory, cannot attach" file))
- (unless (file-exists-p file)
- (error "No such file: %s" file))
- (unless (file-readable-p file)
- (error "Permission denied: %s" file))
- (insert (format "<#part type=%s filename=%s%s><#/part>\n"
- type (prin1-to-string file)
- (if description
- (format " description=%s" (prin1-to-string description))
- ""))))
-
-(defun message-mime-insert-external (file type)
- "Insert a message/external-body part into the buffer."
- (interactive
- (let* ((file (read-file-name "Insert file: "))
- (type (mm-default-file-encoding file)))
- (list file
- (completing-read
- (format "MIME type for %s: " file)
- (delete-duplicates
- (mapcar (lambda (m) (list (cdr m))) mailcap-mime-extensions))
- nil nil type))))
- (insert (format "<#external type=%s name=\"%s\"><#/external>\n"
- type file)))