Remove tmp.
[gnus] / lisp / mml.el
index b9ea3e9..db11fa8 100644 (file)
@@ -72,6 +72,20 @@ unknown encoding; `use-ascii': always use ASCII for those characters
 with unknown encoding; `multipart': always send messages with more than
 one charsets.")
 
+(defvar mml-generate-default-type "text/plain")
+
+(defvar mml-buffer-list nil)
+
+(defun mml-generate-new-buffer (name) 
+  (let ((buf (generate-new-buffer name)))
+    (push buf mml-buffer-list)
+    buf))
+
+(defun mml-destroy-buffers ()
+  (let (kill-buffer-hook)
+    (mapcar 'kill-buffer mml-buffer-list)
+    (setq mml-buffer-list nil)))
+
 (defun mml-parse ()
   "Parse the current buffer as an MML document."
   (goto-char (point-min))
@@ -145,12 +159,15 @@ one charsets.")
                         (and use-ascii 'us-ascii)))
            charset struct space newline paragraph)
        (while (not (eobp))
+         (setq charset (mm-mime-charset (mm-charset-after)))
          (cond
           ;; The charset remains the same.
-          ((or (eq (setq charset (mm-mime-charset (mm-charset-after))) 
-                   'us-ascii)
-               (and use-ascii (not charset))
-               (eq charset current)))
+          ((eq charset 'us-ascii))
+          ((or (and use-ascii (not charset))
+               (eq charset current))
+           (setq space nil
+                 newline nil
+                 paragraph nil))
           ;; The initial charset was ascii.
           ((eq current 'us-ascii)
            (setq current charset
@@ -174,12 +191,12 @@ one charsets.")
          (cond
           ((memq (following-char) '(?  ?\t))
            (setq space (1+ (point))))
-          ((eq (following-char) ?\n)
-           (setq newline (1+ (point))))
           ((and (eq (following-char) ?\n)
                 (not (bobp))
                 (eq (char-after (1- (point))) ?\n))
-           (setq paragraph (point))))
+           (setq paragraph (point)))
+          ((eq (following-char) ?\n)
+           (setq newline (1+ (point)))))
          (forward-char 1))
        ;; Do the final part.
        (unless (= beg (point))
@@ -284,7 +301,8 @@ If MML is non-nil, return the buffer up till the correspondent mml tag."
            (cond 
             ((eq (car cont) 'mml)
              (let ((mml-boundary (funcall mml-boundary-function
-                                          (incf mml-multipart-number))))
+                                          (incf mml-multipart-number)))
+                   (mml-generate-default-type "text/plain"))
                (mml-to-mime))
              (let ((mm-7bit-chars (concat mm-7bit-chars "\x1b")))
                ;; ignore 0x1b, it is part of iso-2022-jp
@@ -348,6 +366,9 @@ If MML is non-nil, return the buffer up till the correspondent mml tag."
     (insert "\n"))
    ((eq (car cont) 'multipart)
     (let* ((type (or (cdr (assq 'type cont)) "mixed"))
+          (mml-generate-default-type (if (equal type "digest")
+                                         "message/rfc822"
+                                       "text/plain"))
            (handler (assoc type mml-generate-multipart-alist)))
       (if handler
           (funcall (cdr handler) cont)
@@ -355,6 +376,7 @@ If MML is non-nil, return the buffer up till the correspondent mml tag."
         (let ((mml-boundary (mml-compute-boundary cont)))
           (insert (format "Content-Type: multipart/%s; boundary=\"%s\"\n"
                           type mml-boundary))
+         ;; Skip `multipart' and `type' elements.
           (setq cont (cddr cont))
           (while cont
             (insert "\n--" mml-boundary "\n")
@@ -416,7 +438,7 @@ If MML is non-nil, return the buffer up till the correspondent mml tag."
           cont '(name access-type expiration size permission)))
     (when (or charset
              parameters
-             (not (equal type "text/plain")))
+             (not (equal type mml-generate-default-type)))
       (when (consp charset)
        (error
         "Can't encode a part with several charsets."))
@@ -518,7 +540,8 @@ If MML is non-nil, return the buffer up till the correspondent mml tag."
   (message-encode-message-body)
   (save-restriction
     (message-narrow-to-headers-or-head)
-    (mail-encode-encoded-word-buffer)))
+    (let ((mail-parse-charset message-default-charset))
+      (mail-encode-encoded-word-buffer))))
 
 (defun mml-insert-mime (handle &optional no-markup)
   (let (textp buffer mmlp)
@@ -526,7 +549,7 @@ If MML is non-nil, return the buffer up till the correspondent mml tag."
     (unless (stringp (car handle))
       (unless (setq textp (equal (mm-handle-media-supertype handle) "text"))
        (save-excursion
-         (set-buffer (setq buffer (generate-new-buffer " *mml*")))
+         (set-buffer (setq buffer (mml-generate-new-buffer " *mml*")))
          (mm-insert-part handle)
          (if (setq mmlp (equal (mm-handle-media-type handle) 
                                "message/rfc822"))
@@ -795,7 +818,9 @@ If RAW, don't highlight the article."
   (interactive "P")
   (let ((buf (current-buffer))
        (message-posting-charset (or (gnus-setup-posting-charset 
-                                     (message-fetch-field "Newsgroups"))
+                                     (save-restriction
+                                       (message-narrow-to-headers-or-head)
+                                       (message-fetch-field "Newsgroups")))
                                     message-posting-charset)))
     (switch-to-buffer (get-buffer-create 
                       (concat (if raw "*Raw MIME preview of "