;;; mml.el --- A package for parsing and validating MML documents
-;; Copyright (C) 1998,99 Free Software Foundation, Inc.
+;; Copyright (C) 1998-2000 Free Software Foundation, Inc.
;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
;; This file is part of GNU Emacs.
(eval-and-compile
(autoload 'message-make-message-id "message"))
-(defvar mml-generate-multipart-alist
- '(("signed" . rfc2015-generate-signed-multipart)
- ("encrypted" . rfc2015-generate-encrypted-multipart))
+(defvar mml-generate-multipart-alist nil
"*Alist of multipart generation functions.
-
Each entry has the form (NAME . FUNCTION), where
-NAME: is a string containing the name of the part (without the
+NAME is a string containing the name of the part (without the
leading \"/multipart/\"),
-FUNCTION: is a Lisp function which is called to generate the part.
+FUNCTION is a Lisp function which is called to generate the part.
The Lisp function has to supply the appropriate MIME headers and the
contents of this part.")
which is a number that says how many times the function has been
called for this message.")
+(defvar mml-confirmation-set nil
+ "A list of symbols, each of which disables some warning.
+`unknown-encoding': always send messages contain characters with
+unknown encoding; `use-ascii': always use ASCII for those characters
+with unknown encoding; `multipart': always send messages with more than
+one charsets.")
+
(defun mml-parse ()
"Parse the current buffer as an MML document."
(goto-char (point-min))
(defun mml-parse-1 ()
"Parse the current buffer as an MML document."
- (let (struct tag point contents charsets warn)
+ (let (struct tag point contents charsets warn use-ascii)
(while (and (not (eobp))
(not (looking-at "<#/multipart")))
(cond
(setq point (point)
contents (mml-read-part)
charsets (mm-find-mime-charset-region point (point)))
+ (when (memq nil charsets)
+ (if (or (memq 'unknown-encoding mml-confirmation-set)
+ (y-or-n-p
+ "Warning: You message contains characters with unknown encoding. Really send?"))
+ (if (setq use-ascii
+ (or (memq 'use-ascii mml-confirmation-set)
+ (y-or-n-p "Use ASCII as charset?")))
+ (setq charsets (delq nil charsets))
+ (setq warn nil))
+ (error "Edit your message to remove those characters")))
(if (< (length charsets) 2)
(push (nconc tag (list (cons 'contents contents)))
struct)
(let ((nstruct (mml-parse-singlepart-with-multiple-charsets
- tag point (point))))
+ tag point (point) use-ascii)))
(when (and warn
+ (not (memq 'multipart mml-confirmation-set))
(not
(y-or-n-p
(format
(forward-line 1))
(nreverse struct)))
-(defun mml-parse-singlepart-with-multiple-charsets (orig-tag beg end)
+(defun mml-parse-singlepart-with-multiple-charsets
+ (orig-tag beg end &optional use-ascii)
(save-excursion
(narrow-to-region beg end)
(goto-char (point-min))
- (let ((current (mm-mime-charset (char-charset (following-char))))
+ (let ((current (or (mm-mime-charset (mm-charset-after))
+ (and use-ascii 'us-ascii)))
charset struct space newline paragraph)
(while (not (eobp))
(cond
;; The charset remains the same.
- ((or (eq (setq charset (mm-mime-charset
- (char-charset (following-char)))) 'us-ascii)
+ ((or (eq (setq charset (mm-mime-charset (mm-charset-after)))
+ 'us-ascii)
+ (and use-ascii (not charset))
(eq charset current)))
;; The initial charset was ascii.
((eq current 'us-ascii)
(format "Content type (default %s): " default)
(mapcar
'list
- (delete-duplicates
+ (mm-delete-duplicates
(nconc
(mapcar (lambda (m) (cdr m))
mailcap-mime-extensions)
nil
type)))
(cdr l))))
- mailcap-mime-data)))
- :test 'equal)))))
+ mailcap-mime-data))))))))
(if (not (equal string ""))
string
default)))
(defun mml-insert-multipart (&optional type)
(interactive (list (completing-read "Multipart type (default mixed): "
- '(("mixed") ("alternative") ("digest") ("parallel")
- ("signed") ("encrypted"))
- nil nil "mixed")))
+ '(("mixed") ("alternative") ("digest") ("parallel")
+ ("signed") ("encrypted"))
+ nil nil "mixed")))
(or type
(setq type "mixed"))
(mml-insert-empty-tag "multipart" 'type type)
(forward-line -1))
+(defun mml-insert-part (&optional type)
+ (interactive
+ (list (mml-minibuffer-read-type "")))
+ (mml-insert-tag 'part 'type type 'disposition "inline")
+ (forward-line -1))
+
(defun mml-preview (&optional raw)
- "Display current buffer with Gnus, in a new buffer.
+ "Display current buffer with Gnus, in a new buffer.
If RAW, don't highlight the article."
- (interactive "P")
- (let ((buf (current-buffer)))
- (switch-to-buffer (get-buffer-create
- (concat (if raw "*Raw MIME preview of "
- "*MIME preview of ") (buffer-name))))
- (erase-buffer)
- (insert-buffer buf)
- (if (re-search-forward
- (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
- (replace-match "\n"))
- (mml-to-mime)
- (unless raw
- (run-hooks 'gnus-article-decode-hook)
- (let ((gnus-newsgroup-name "dummy"))
- (gnus-article-prepare-display)))
- (fundamental-mode)
- (setq buffer-read-only t)
- (goto-char (point-min))))
+ (interactive "P")
+ (let ((buf (current-buffer)))
+ (switch-to-buffer (get-buffer-create
+ (concat (if raw "*Raw MIME preview of "
+ "*MIME preview of ") (buffer-name))))
+ (erase-buffer)
+ (insert-buffer buf)
+ (if (re-search-forward
+ (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
+ (replace-match "\n"))
+ (mml-to-mime)
+ (unless raw
+ (run-hooks 'gnus-article-decode-hook)
+ (let ((gnus-newsgroup-name "dummy"))
+ (gnus-article-prepare-display)))
+ (fundamental-mode)
+ (setq buffer-read-only t)
+ (goto-char (point-min))))
(defun mml-validate ()
"Validate the current MML document."