Ask user to confirm charset for characters of unknown encoding.
authorShengHuo ZHU <zsh@cs.rochester.edu>
Thu, 9 Dec 1999 22:55:08 +0000 (22:55 +0000)
committerShengHuo ZHU <zsh@cs.rochester.edu>
Thu, 9 Dec 1999 22:55:08 +0000 (22:55 +0000)
lisp/ChangeLog
lisp/mm-util.el
lisp/mml.el

index 9df07b9..51c1f4c 100644 (file)
@@ -1,3 +1,9 @@
+1999-12-09 17:47:56  Shenghuo ZHU  <zsh@cs.rochester.edu>
+
+       * mm-util.el (mm-find-mime-charset-region): Revoke last change.
+       * mml.el (mml-confirmation-set): New variable.
+       (mml-parse-1): Ask user to confirm.
+
 1999-12-09  Simon Josefsson  <jas@pdc.kth.se>
 
        * gnus-start.el (gnus-get-unread-articles): Make sure all methods
index 7b10816..40845f2 100644 (file)
@@ -225,10 +225,9 @@ used as the line break code type of the coding system."
 
 (defun mm-find-mime-charset-region (b e)
   "Return the MIME charsets needed to encode the region between B and E."
-  (let ((charsets
-        (delq nil (mapcar 'mm-mime-charset
-                          (delq 'ascii
-                                (mm-find-charset-region b e))))))
+  (let ((charsets (mapcar 'mm-mime-charset
+                         (delq 'ascii
+                               (mm-find-charset-region b e)))))
     (when (memq 'iso-2022-jp-2 charsets)
       (setq charsets (delq 'iso-2022-jp charsets)))
     (delete-duplicates charsets)
index a498719..1c68556 100644 (file)
@@ -64,6 +64,13 @@ suggestion each time.  The function is called with one parameter,
 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))
@@ -76,7 +83,7 @@ called for this message.")
 
 (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
@@ -93,12 +100,23 @@ called for this message.")
        (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
@@ -110,17 +128,20 @@ called for this message.")
       (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 (char-charset (following-char)))
+                      (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)
+             (and use-ascii (not charset))
              (eq charset current)))
         ;; The initial charset was ascii.
         ((eq current 'us-ascii)