* lisp/gnus-bbdb.el (gnus-bbdb/update-record): Save excursion while
[elisp/gnus.git-] / lisp / mml.el
index 150e776..de23d5f 100644 (file)
 (require 'mm-bodies)
 (require 'mm-encode)
 (require 'mm-decode)
-(require 'gnus-ems)
 (require 'mml-sec)
 (eval-when-compile (require 'cl))
 
 (eval-and-compile
   (autoload 'message-make-message-id "message")
   (autoload 'gnus-setup-posting-charset "gnus-msg")
+  (autoload 'gnus-add-minor-mode "gnus-ems")
   (autoload 'message-fetch-field "message")
   (autoload 'message-posting-charset "message"))
 
@@ -90,13 +90,14 @@ one charsets.")
 
 (defun mml-parse ()
   "Parse the current buffer as an MML document."
-  (goto-char (point-min))
-  (let ((table (syntax-table)))
-    (unwind-protect
-       (progn
-         (set-syntax-table mml-syntax-table)
-         (mml-parse-1))
-      (set-syntax-table table))))
+  (save-excursion
+    (goto-char (point-min))
+    (let ((table (syntax-table)))
+      (unwind-protect
+         (progn
+           (set-syntax-table mml-syntax-table)
+           (mml-parse-1))
+       (set-syntax-table table)))))
 
 (defun mml-parse-1 ()
   "Parse the current buffer as an MML document."
@@ -124,8 +125,11 @@ one charsets.")
                         (mm-find-mime-charset-region point (point))))
        (when (and (not raw) (memq nil charsets))
          (if (or (memq 'unknown-encoding mml-confirmation-set)
-                 (y-or-n-p
-                  "Message contains characters with unknown encoding.  Really send?"))
+                 (prog1 (y-or-n-p
+                  "\
+Message contains characters with unknown encoding.  Really send?")
+                   (set (make-local-variable 'mml-confirmation-set)
+                        (push 'unknown-encoding mml-confirmation-set))))
              (if (setq use-ascii 
                        (or (memq 'use-ascii mml-confirmation-set)
                            (y-or-n-p "Use ASCII as charset?")))
@@ -145,10 +149,13 @@ one charsets.")
            (when (and warn
                       (not (memq 'multipart mml-confirmation-set))
                       (not
-                       (y-or-n-p
-                        (format
-                         "Warning: Your message contains more than %d parts.  Really send? "
-                         (length nstruct)))))
+                       (prog1 (y-or-n-p
+                               (format
+                                "\
+A message part needs to be split into %d charset parts.  Really send? "
+                                (length nstruct)))
+                         (set (make-local-variable 'mml-confirmation-set)
+                              (push 'multipart mml-confirmation-set)))))
              (error "Edit your message to use only one charset"))
            (setq struct (nconc nstruct struct)))))))
     (unless (eobp)
@@ -215,7 +222,8 @@ one charsets.")
 
 (defun mml-read-tag ()
   "Read a tag and return the contents."
-  (let (contents name elem val)
+  (let ((orig-point (point))
+       contents name elem val)
     (forward-char 2)
     (setq name (buffer-substring-no-properties
                (point) (progn (forward-sexp 1) (point))))
@@ -233,6 +241,8 @@ one charsets.")
     (goto-char (match-end 0))
     ;; Don't skip the leading space.
     ;;(skip-chars-forward " \t\n")
+    ;; Put the tag location into the returned contents
+    (setq contents (append (list (cons 'tag-location orig-point)) contents))
     (cons (intern name) (nreverse contents))))
 
 (defun mml-read-part (&optional mml)
@@ -295,7 +305,8 @@ If MML is non-nil, return the buffer up till the correspondent mml tag."
              (with-temp-buffer
                (setq charset (mm-charset-to-coding-system 
                               (cdr (assq 'charset cont))))
-               (if (eq charset 'ascii) (setq charset nil))
+               (when (eq charset 'ascii)
+                 (setq charset nil))
                (cond
                 ((cdr (assq 'buffer cont))
                  (insert-buffer-substring (cdr (assq 'buffer cont))))
@@ -312,7 +323,8 @@ If MML is non-nil, return the buffer up till the correspondent mml tag."
                    ;; Remove quotes from quoted tags.
                    (goto-char (point-min))
                    (while (re-search-forward
-                           "<#!+/?\\(part\\|multipart\\|external\\|mml\\)" nil t)
+                           "<#!+/?\\(part\\|multipart\\|external\\|mml\\)"
+                           nil t)
                      (delete-region (+ (match-beginning 0) 2)
                                     (+ (match-beginning 0) 3))))))
                (cond