(require 'mm-util)
(require 'mm-bodies)
(require 'mm-encode)
+(require 'mm-decode)
(eval-and-compile
(autoload 'message-make-message-id "message"))
((eq (car cont) 'part)
(let (coded encoding charset filename type)
(setq type (or (cdr (assq 'type cont)) "text/plain"))
- (if (equal (car (split-string type "/")) "text")
+ (if (member (car (split-string type "/")) '("text" "message"))
(with-temp-buffer
(cond
((cdr (assq 'buffer cont))
(insert-buffer-substring (cdr (assq 'buffer cont))))
- ((setq filename (cdr (assq 'filename cont)))
- (insert-file-contents filename))
+ ((and (setq filename (cdr (assq 'filename cont)))
+ (not (equal (cdr (assq 'nofile cont)) "yes")))
+ (mm-insert-file-contents filename))
(t
(save-restriction
(narrow-to-region (point) (point))
(cond
((cdr (assq 'buffer cont))
(insert-buffer-substring (cdr (assq 'buffer cont))))
- ((setq filename (cdr (assq 'filename cont)))
- (insert-file-contents filename))
+ ((and (setq filename (cdr (assq 'filename cont)))
+ (not (equal (cdr (assq 'nofile cont)) "yes")))
+ (mm-insert-file-contents filename))
(t
(insert (cdr (assq 'contents cont)))))
(setq encoding (mm-encode-buffer type)
(cond
((cdr (assq 'buffer cont))
(insert-buffer-substring (cdr (assq 'buffer cont))))
- ((setq filename (cdr (assq 'filename cont)))
- (insert-file-contents filename))
+ ((and (setq filename (cdr (assq 'filename cont)))
+ (not (equal (cdr (assq 'nofile cont)) "yes")))
+ (mm-insert-file-contents filename))
(t
(insert (cdr (assq 'contents cont)))))
(goto-char (point-min))
(let (textp buffer)
;; Determine type and stuff.
(unless (stringp (car handle))
- (unless (setq textp (equal
- (car (split-string
- (car (mm-handle-type handle)) "/"))
- "text"))
+ (unless (setq textp (equal (mm-handle-media-supertype handle)
+ "text"))
(save-excursion
(set-buffer (setq buffer (generate-new-buffer " *mml*")))
(mm-insert-part handle))))
(unless no-markup
- (mml-insert-mml-markup handle buffer))
+ (mml-insert-mml-markup handle buffer textp))
(cond
((stringp (car handle))
(mapcar 'mml-insert-mime (cdr handle))
(t
(insert "<#/part>\n")))))
-(defun mml-insert-mml-markup (handle &optional buffer)
+(defun mml-insert-mml-markup (handle &optional buffer nofile)
"Take a MIME handle and insert an MML tag."
(if (stringp (car handle))
- (insert "<#multipart type=" (cadr (split-string (car handle) "/"))
+ (insert "<#multipart type=" (mm-handle-media-subtype handle)
">\n")
- (insert "<#part type=" (car (mm-handle-type handle)))
+ (insert "<#part type=" (mm-handle-media-type handle))
(dolist (elem (append (cdr (mm-handle-type handle))
(cdr (mm-handle-disposition handle))))
(insert " " (symbol-name (car elem)) "=\"" (cdr elem) "\""))
(insert " disposition=" (car (mm-handle-disposition handle))))
(when buffer
(insert " buffer=\"" (buffer-name buffer) "\""))
+ (when nofile
+ (insert " nofile=yes"))
(when (mm-handle-description handle)
(insert " description=\"" (mm-handle-description handle) "\""))
- (equal (split-string (car (mm-handle-type handle)) "/") "text")
(insert ">\n")))
(defun mml-insert-parameter (&rest parameters)
["Multipart" mml-insert-multipart t]
["Part" mml-insert-part t])
["Quote" mml-quote-region t]
- ["Validate" mml-validate t]))
+ ["Validate" mml-validate t]
+ ["Preview" mml-preview t]))
(defvar mml-mode nil
"Minor mode for editing MML.")
(when (string-match "[\"\\~/* \t\n]" value)
(setq value (prin1-to-string value)))
(insert (format " %s=%s" key value)))))
- (insert ">\n<#/part>\n"))
+ (insert ">\n<#/" name ">\n"))
;;; Attachment functions.
'description description))
(defun mml-insert-multipart (&optional type)
- (interactive (list (completing-read "Multipart type (default mixed): ")
- "mixed"
+ (interactive (list (completing-read "Multipart type (default mixed): "
'(("mixed") ("alternative") ("digest") ("parallel")
- ("signed") ("encrypted"))))
+ ("signed") ("encrypted"))
+ nil nil "mixed")))
(or type
(setq type "mixed"))
(mml-insert-tag "multipart" 'type type)
- (insert "<#/!multipart>\n")
(forward-line -1))
(defun mml-preview (&optional raw)
(fundamental-mode)
(setq buffer-read-only t)
(goto-char (point-min))))
-
+
+(defun mml-validate ()
+ "Validate the current MML document."
+ (interactive)
+ (mml-parse))
+
(provide 'mml)
;;; mml.el ends here