Fix and enhance forward function.
authorShengHuo ZHU <zsh@cs.rochester.edu>
Fri, 28 Apr 2000 00:44:43 +0000 (00:44 +0000)
committerShengHuo ZHU <zsh@cs.rochester.edu>
Fri, 28 Apr 2000 00:44:43 +0000 (00:44 +0000)
Add mml tag.

lisp/ChangeLog
lisp/gnus-msg.el
lisp/message.el
lisp/mml.el

index 6d2f8c1..c727d00 100644 (file)
@@ -1,3 +1,14 @@
+2000-04-27 20:32:06  Shenghuo ZHU  <zsh@cs.rochester.edu>
+
+       * gnus-msg.el (gnus-summary-mail-forward): Use ARG.
+       (gnus-summary-post-forward): Ditto.
+       * message.el (message-forward-show-mml): New variable.
+       (message-forward): Use it.
+       * mml.el (mml-parse-1): Add tag mml.
+       (mml-read-part): Ditto.
+       (mml-generate-mime): Support reentance.
+       (mml-generate-mime-1): Support mml tag.
+
 2000-04-27  Dave Love  <fx@gnu.org>
 
        * gnus-art.el: Don't bother to require custom, browse-url.
index 57f7d02..31e42c0 100644 (file)
@@ -661,25 +661,53 @@ The original article will be yanked."
   (interactive "P")
   (gnus-summary-reply-with-original n t))
 
-(defun gnus-summary-mail-forward (&optional not-used post)
-  "Forward the current message to another user.
+(defun gnus-summary-mail-forward (&optional arg post)
+  "Forward the current message to another user.  
+If ARG is nil, see `message-forward-as-mime' and `message-forward-show-mml';
+if ARG is 1, decode the message and forward directly inline;
+if ARG is 2, foward message as an rfc822 MIME section;
+if ARG is 3, decode message and forward as an rfc822 MIME section;
+if ARG is 4, foward message directly inline;
+otherwise, use flipped `message-forward-as-mime'.
 If POST, post instead of mail."
   (interactive "P")
-  (gnus-setup-message 'forward
-    (gnus-summary-select-article)
-    (let (text)
-      (save-excursion
-       (set-buffer gnus-original-article-buffer)
-       (setq text (buffer-string)))
-      (set-buffer (gnus-get-buffer-create
-                  (generate-new-buffer-name " *Gnus forward*")))
-      (erase-buffer)
-      (insert text)
-      (goto-char (point-min))
-      (when (looking-at "From ")
-       (replace-match "X-From-Line: ") )
-      (run-hooks 'gnus-article-decode-hook)
-      (message-forward post))))
+  (let ((message-forward-as-mime message-forward-as-mime)
+       (message-forward-show-mml message-forward-show-mml))
+    (cond 
+     ((null arg))
+     ((eq arg 1) (setq message-forward-as-mime nil
+                      message-forward-show-mml t))
+     ((eq arg 2) (setq message-forward-as-mime t
+                      message-forward-show-mml nil))
+     ((eq arg 3) (setq message-forward-as-mime t
+                      message-forward-show-mml t))
+     ((eq arg 4) (setq message-forward-as-mime nil
+                      message-forward-show-mml nil))
+     (t (setq message-forward-as-mime (not message-forward-as-mime))))
+    (gnus-setup-message 'forward
+      (gnus-summary-select-article)
+      (let ((mail-parse-charset gnus-newsgroup-charset)
+           (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
+           text)
+       (save-excursion
+         (set-buffer gnus-original-article-buffer)
+         (setq text (buffer-string)))
+       (set-buffer 
+        (if message-forward-show-mml
+            (gnus-get-buffer-create
+             (generate-new-buffer-name " *Gnus forward*"))
+          (mm-with-unibyte-current-buffer
+            ;; create an unibyte buffer
+            (gnus-get-buffer-create
+             (generate-new-buffer-name " *Gnus forward*")))))
+       (erase-buffer)
+       (insert text)
+       (goto-char (point-min))
+       (when (looking-at "From ")
+         (replace-match "X-From-Line: ") )
+       (if message-forward-show-mml
+           (mime-to-mml))
+       (message-forward post)))))
 
 (defun gnus-summary-resend-message (address n)
   "Resend the current article to ADDRESS."
@@ -692,11 +720,11 @@ If POST, post instead of mail."
        (set-buffer gnus-original-article-buffer)
        (message-resend address)))))
 
-(defun gnus-summary-post-forward (&optional full-headers)
+(defun gnus-summary-post-forward (&optional arg)
   "Forward the current article to a newsgroup.
-If FULL-HEADERS (the prefix), include full headers when forwarding."
+See `gnus-summary-mail-forward' for ARG."
   (interactive "P")
-  (gnus-summary-mail-forward full-headers t))
+  (gnus-summary-mail-forward arg t))
 
 (defvar gnus-nastygram-message
   "The following article was inappropriately posted to %s.\n\n"
index c7dd828..6a53eff 100644 (file)
@@ -299,6 +299,11 @@ The provided functions are:
   :group 'message-forwarding
   :type 'boolean)
 
+(defcustom message-forward-show-mml t
+  "*If non-nil, forward messages are shown as mml.  Otherwise, forward messages are unchanged."
+  :group 'message-forwarding
+  :type 'boolean)
+
 (defcustom message-forward-before-signature t
   "*If non-nil, put forwarded message before signature, else after."
   :group 'message-forwarding
@@ -844,7 +849,7 @@ Defaults to `text-mode-abbrev-table'.")
                "\\([" cite-prefix "]+[" cite-suffix "]*\\)?"
                "[:>|}].*")
        (0 'message-cited-text-face))
-      ("<#/?\\(multipart\\|part\\|external\\).*>"
+      ("<#/?\\(multipart\\|part\\|external\\|mml\\).*>"
        (0 'message-mml-face))))
   "Additional expressions to highlight in Message mode.")
 
@@ -3997,9 +4002,12 @@ the message."
   "Forward the current message via mail.
 Optional NEWS will use news to forward instead of mail."
   (interactive "P")
-  (let ((cur (current-buffer))
-       (subject (message-make-forward-subject))
-       art-beg)
+  (let* ((cur (current-buffer))
+        (subject (if message-forward-show-mml
+                     (message-make-forward-subject)
+                   (mail-decode-encoded-word-string
+                    (message-make-forward-subject))))
+        art-beg)
     (if news
        (message-news nil subject)
       (message-mail nil subject))
@@ -4009,17 +4017,27 @@ Optional NEWS will use news to forward instead of mail."
         (message-goto-body)
       (goto-char (point-max)))
     (if message-forward-as-mime
-       (insert "\n\n<#part type=message/rfc822 disposition=inline>\n")
+       (if message-forward-show-mml
+           (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
+         (insert "\n\n<#part type=message/rfc822 disposition=inline"
+                 " buffer=\"" (buffer-name cur) "\">\n"))
       (insert "\n-------------------- Start of forwarded message --------------------\n"))
     (let ((b (point))
          e)
-      (mml-insert-buffer cur)
+      (if message-forward-show-mml
+         (insert-buffer-substring cur)
+       (unless message-forward-as-mime
+         (mml-insert-buffer cur)))
       (setq e (point))
       (if message-forward-as-mime
-         (insert "<#/part>\n")
+         (if message-forward-show-mml
+             (insert "<#/mml>\n")
+           (insert "<#/part>\n"))
        (insert "\n-------------------- End of forwarded message --------------------\n"))
-      (when (and (not current-prefix-arg)
-                message-forward-ignored-headers)
+      (when (and (or message-forward-show-mml
+                    (not message-forward-as-mime))
+            (not current-prefix-arg)
+            message-forward-ignored-headers)
        (save-restriction
          (narrow-to-region b e)
          (goto-char b)
index 6cee33d..17b84b9 100644 (file)
@@ -94,12 +94,12 @@ one charsets.")
        (push (nconc (mml-read-tag) (list (cons 'contents (mml-read-part))))
              struct))
        (t
-       (if (looking-at "<#part")
+       (if (or (looking-at "<#part") (looking-at "<#mml"))
            (setq tag (mml-read-tag))
          (setq tag (list 'part '(type . "text/plain"))
                warn t))
        (setq point (point)
-             contents (mml-read-part)
+             contents (mml-read-part (eq 'mml (car tag)))
              charsets (mm-find-mime-charset-region point (point)))
        (when (memq nil charsets)
          (if (or (memq 'unknown-encoding mml-confirmation-set)
@@ -204,14 +204,17 @@ one charsets.")
     (skip-chars-forward " \t\n")
     (cons (intern name) (nreverse contents))))
 
-(defun mml-read-part ()
-  "Return the buffer up till the next part, multipart or closing part or multipart."
+(defun mml-read-part (&optional mml)
+  "Return the buffer up till the next part, multipart or closing part or multipart.
+If MML is non-nil, return the buffer up till the colsing message."
   (let ((beg (point)))
     ;; If the tag ended at the end of the line, we go to the next line.
     (when (looking-at "[ \t]*\n")
       (forward-line 1))
     (if (re-search-forward
-        "<#\\(/\\)?\\(multipart\\|part\\|external\\)." nil t)
+        (if mml
+            "<#\\(/\\)\\(mml\\)."
+          "<#\\(/\\)?\\(multipart\\|part\\|external\\|mml\\).") nil t)
        (prog1
            (buffer-substring-no-properties beg (match-beginning 0))
          (if (or (not (match-beginning 1))
@@ -228,7 +231,7 @@ one charsets.")
 (defun mml-generate-mime ()
   "Generate a MIME message based on the current MML document."
   (let ((cont (mml-parse))
-       (mml-multipart-number 0))
+       (mml-multipart-number mml-multipart-number))
     (if (not cont)
        nil
       (with-temp-buffer
@@ -241,7 +244,7 @@ one charsets.")
 
 (defun mml-generate-mime-1 (cont)
   (cond
-   ((eq (car cont) 'part)
+   ((or (eq (car cont) 'part) (eq (car cont) 'mml))
     (let (coded encoding charset filename type)
       (setq type (or (cdr (assq 'type cont)) "text/plain"))
       (if (member (car (split-string type "/")) '("text" "message"))
@@ -252,6 +255,8 @@ one charsets.")
             ((and (setq filename (cdr (assq 'filename cont)))
                   (not (equal (cdr (assq 'nofile cont)) "yes")))
              (mm-insert-file-contents filename))
+            ((eq 'mml (car cont))
+             (insert (cdr (assq 'contents cont))))
             (t
              (save-restriction
                (narrow-to-region (point) (point))
@@ -259,22 +264,21 @@ one charsets.")
                ;; Remove quotes from quoted tags.
                (goto-char (point-min))
                (while (re-search-forward
-                       "<#!+/?\\(part\\|multipart\\|external\\)" nil t)
+                       "<#!+/?\\(part\\|multipart\\|external\\|mml\\)" nil t)
                  (delete-region (+ (match-beginning 0) 2)
                                 (+ (match-beginning 0) 3))))))
-           (when (string= (car (split-string type "/")) "message")
-             ;; message/rfc822 parts have to have their heads encoded.
-             (save-restriction
-               (message-narrow-to-head)
-               (let ((rfc2047-header-encoding-alist nil))
-                 (mail-encode-encoded-word-buffer))))
-           (setq charset (mm-encode-body))
-           (setq encoding (mm-body-encoding
-                           charset
-                           (if (string= (car (split-string type "/"))
-                                        "message")
-                               '8bit
-                             (cdr (assq 'encoding cont)))))
+           (cond 
+            ((eq (car cont) 'mml)
+             (let ((mml-boundary (funcall mml-boundary-function
+                                          (incf mml-multipart-number))))
+               (mml-to-mime))
+             (setq encoding (mm-body-7-or-8)))
+            ((string= (car (split-string type "/")) "message")
+             (setq encoding (mm-body-7-or-8)))
+            (t 
+             (setq charset (mm-encode-body))
+             (setq encoding (mm-body-encoding
+                             charset (cdr (assq 'encoding cont))))))
            (setq coded (buffer-string)))
        (mm-with-unibyte-buffer
          (cond
@@ -666,7 +670,7 @@ one charsets.")
       (goto-char (point-min))
       ;; Quote parts.
       (while (re-search-forward
-             "<#/?!*\\(multipart\\|part\\|external\\)" nil t)
+             "<#/?!*\\(multipart\\|part\\|external\\|mml\\)" nil t)
        ;; Insert ! after the #.
        (goto-char (+ (match-beginning 0) 2))
        (insert "!")))))