Support multipart/digest.
authorShengHuo ZHU <zsh@cs.rochester.edu>
Fri, 12 May 2000 19:24:50 +0000 (19:24 +0000)
committerShengHuo ZHU <zsh@cs.rochester.edu>
Fri, 12 May 2000 19:24:50 +0000 (19:24 +0000)
lisp/ChangeLog
lisp/gnus-uu.el
lisp/message.el
lisp/mm-decode.el
lisp/mml.el
lisp/nndoc.el

index 22f4d05..1e0dacb 100644 (file)
@@ -1,3 +1,18 @@
+2000-05-12 15:15:55  Shenghuo ZHU  <zsh@cs.rochester.edu>
+
+       * nndoc.el (nndoc-type-alist): mime-digest head-begin.
+       (nndoc-mime-digest-type-p): Locate article head precisely.
+       * mml.el (mml-generate-default-type): New variable.
+       (mml-generate-mime-1): Use it.
+       (mml-insert-mime-headers): Use it.
+       * gnus-uu.el (gnus-uu-digest-buffer): New variable.
+       (gnus-uu-digest-mail-forward): Use it and call message-forward 
+       with argument digest.
+       (gnus-uu-save-article): Support message-forward-as-mime.
+       * message.el (message-forward): Add parameter digest.
+       * mm-decode.el (mm-dissect-default-type): New variable.
+       (mm-dissect-buffer): Use it.
+
 2000-05-11 11:08:03  Shenghuo ZHU  <zsh@cs.rochester.edu>
 
        * mml.el (mml-parse-singlepart-with-multiple-charsets): Set space,
index 3a60f7d..eec2bea 100644 (file)
@@ -349,6 +349,7 @@ didn't work, and overwrite existing files.  Otherwise, ask each time."
 
 (defvar gnus-uu-default-dir gnus-article-save-directory)
 (defvar gnus-uu-digest-from-subject nil)
+(defvar gnus-uu-digest-buffer nil)
 
 ;; Keymaps
 
@@ -519,15 +520,13 @@ didn't work, and overwrite existing files.  Otherwise, ask each time."
   (interactive "P")
   (let ((gnus-uu-save-in-digest t)
        (file (make-temp-name (nnheader-concat gnus-uu-tmp-dir "forward")))
-       buf subject from)
+       gnus-uu-digest-buffer subject from)
     (gnus-setup-message 'forward
       (setq gnus-uu-digest-from-subject nil)
+      (setq gnus-uu-digest-buffer 
+           (gnus-get-buffer-create " *gnus-uu-forward*"))
       (gnus-uu-decode-save n file)
-      (setq buf (switch-to-buffer
-                (gnus-get-buffer-create " *gnus-uu-forward*")))
-      (erase-buffer)
-      (insert-file file)
-      (delete-file file)
+      (switch-to-buffer gnus-uu-digest-buffer)
       (let ((fs gnus-uu-digest-from-subject))
        (when fs
          (setq from (caar fs)
@@ -557,7 +556,7 @@ didn't work, and overwrite existing files.  Otherwise, ask each time."
       (when (re-search-forward "^From: ")
        (delete-region (point) (gnus-point-at-eol))
        (insert from))
-      (message-forward post))
+      (message-forward post t))
     (setq gnus-uu-digest-from-subject nil)))
 
 (defun gnus-uu-digest-post-forward (&optional n)
@@ -850,8 +849,13 @@ When called interactively, prompt for REGEXP."
              (set-buffer (gnus-get-buffer-create "*gnus-uu-pre*"))
              (erase-buffer)
              (insert (format
-                      "Date: %s\nFrom: %s\nSubject: %s Digest\n\nTopics:\n"
-                      (current-time-string) name name))))
+                      "Date: %s\nFrom: %s\nSubject: %s Digest\n\n"
+                      (current-time-string) name name))
+             (when (and message-forward-as-mime gnus-uu-digest-buffer)
+               ;; The default part in multipart/digest is message/rfc822.
+               ;; This is a fake head.
+               (insert "<#part type=text/plain>\nSubject: Topics\n\n"))
+             (insert "Topics:\n")))
        (when (not (eq in-state 'end))
          (setq state (list 'middle))))
       (save-excursion
@@ -865,14 +869,19 @@ When called interactively, prompt for REGEXP."
              ;; These two are necessary for XEmacs 19.12 fascism.
              (put-text-property (point-min) (point-max) 'invisible nil)
              (put-text-property (point-min) (point-max) 'intangible nil))
+           (when (and message-forward-as-mime gnus-uu-digest-buffer)
+             ;; FIX ME:: when message-forward-show-mml is nil.
+             (mm-enable-multibyte)
+             (mime-to-mml))
            (goto-char (point-min))
            (re-search-forward "\n\n")
-           ;; Quote all 30-dash lines.
-           (save-excursion
-             (while (re-search-forward "^-" nil t)
-               (beginning-of-line)
-               (delete-char 1)
-               (insert "- ")))
+           (unless (and message-forward-as-mime gnus-uu-digest-buffer)
+             ;; Quote all 30-dash lines.
+             (save-excursion
+               (while (re-search-forward "^-" nil t)
+                 (beginning-of-line)
+                 (delete-char 1)
+                 (insert "- "))))
            (setq body (buffer-substring (1- (point)) (point-max)))
            (narrow-to-region (point-min) (point))
            (if (not (setq headers gnus-uu-digest-headers))
@@ -890,9 +899,13 @@ When called interactively, prompt for REGEXP."
                                          (1- (point)))
                                     (progn (forward-line 1) (point)))))))))
            (widen)))
+       (when (and message-forward-as-mime gnus-uu-digest-buffer)
+         (insert "\n<#mml type=message/rfc822>\n"))
        (insert sorthead) (goto-char (point-max))
        (insert body) (goto-char (point-max))
-       (insert (concat "\n" (make-string 30 ?-) "\n\n"))
+       (if (and message-forward-as-mime gnus-uu-digest-buffer)
+           (insert "\n<#/mml>\n")
+         (insert (concat "\n" (make-string 30 ?-) "\n\n")))
        (goto-char beg)
        (when (re-search-forward "^Subject: \\(.*\\)$" nil t)
          (setq subj (buffer-substring (match-beginning 1) (match-end 1)))
@@ -901,19 +914,33 @@ When called interactively, prompt for REGEXP."
            (insert (format "   %s\n" subj)))))
       (when (or (eq in-state 'last)
                (eq in-state 'first-and-last))
-       (save-excursion
-         (set-buffer "*gnus-uu-pre*")
-         (insert (format "\n\n%s\n\n" (make-string 70 ?-)))
-         (gnus-write-buffer gnus-uu-saved-article-name))
-       (save-excursion
-         (set-buffer "*gnus-uu-body*")
-         (goto-char (point-max))
-         (insert
-          (concat (setq end-string (format "End of %s Digest" name))
-                  "\n"))
-         (insert (concat (make-string (length end-string) ?*) "\n"))
-         (write-region
-          (point-min) (point-max) gnus-uu-saved-article-name t))
+       (if (and message-forward-as-mime gnus-uu-digest-buffer)
+           (with-current-buffer gnus-uu-digest-buffer
+             (erase-buffer)
+             (insert-buffer "*gnus-uu-pre*")
+             (goto-char (point-max))
+             (insert-buffer "*gnus-uu-body*"))
+         (save-excursion
+           (set-buffer "*gnus-uu-pre*")
+           (insert (format "\n\n%s\n\n" (make-string 70 ?-)))
+           (if gnus-uu-digest-buffer
+               (with-current-buffer gnus-uu-digest-buffer
+                 (erase-buffer)
+                 (insert-buffer "*gnus-uu-pre*"))
+             (gnus-write-buffer gnus-uu-saved-article-name)))
+         (save-excursion
+           (set-buffer "*gnus-uu-body*")
+           (goto-char (point-max))
+           (insert
+            (concat (setq end-string (format "End of %s Digest" name))
+                    "\n"))
+           (insert (concat (make-string (length end-string) ?*) "\n"))
+           (if gnus-uu-digest-buffer
+               (with-current-buffer gnus-uu-digest-buffer
+                 (goto-char (point-max))
+                 (insert-buffer "*gnus-uu-body*"))
+             (write-region
+              (point-min) (point-max) gnus-uu-saved-article-name t))))
        (gnus-kill-buffer "*gnus-uu-pre*")
        (gnus-kill-buffer "*gnus-uu-body*")
        (push 'end state))
index 1f317e2..a4c6f30 100644 (file)
@@ -4005,9 +4005,10 @@ the message."
        subject))))
 
 ;;;###autoload
-(defun message-forward (&optional news)
+(defun message-forward (&optional news digest)
   "Forward the current message via mail.
-Optional NEWS will use news to forward instead of mail."
+Optional NEWS will use news to forward instead of mail.
+Optional DIGEST will use digest to forward."
   (interactive "P")
   (let* ((cur (current-buffer))
         (subject (if message-forward-show-mml
@@ -4024,22 +4025,29 @@ Optional NEWS will use news to forward instead of mail."
         (message-goto-body)
       (goto-char (point-max)))
     (if message-forward-as-mime
-       (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"))
+       (if digest
+           (insert "\n<#multipart type=digest>\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)
-      (if message-forward-show-mml
-         (insert-buffer-substring cur)
-       (unless message-forward-as-mime
-         (mml-insert-buffer cur)))
+    (let ((b (point)) e)
+      (if digest
+         (if message-forward-as-mime
+             (insert-buffer-substring cur)
+           (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
-         (if message-forward-show-mml
-             (insert "<#/mml>\n")
-           (insert "<#/part>\n"))
+         (if digest
+             (insert "<#/multipart>\n")
+           (if message-forward-show-mml
+               (insert "<#/mml>\n")
+             (insert "<#/part>\n")))
        (insert "\n-------------------- End of forwarded message --------------------\n"))
       (when (and (or message-forward-show-mml
                     (not message-forward-as-mime))
@@ -4049,7 +4057,9 @@ Optional NEWS will use news to forward instead of mail."
          (narrow-to-region b e)
          (goto-char b)
          (narrow-to-region (point) (or (search-forward "\n\n" nil t) (point)))
-         (message-remove-header message-forward-ignored-headers t))))
+         (if (and digest message-forward-as-mime)
+             (delete-region (point-min) (point-max))
+           (message-remove-header message-forward-ignored-headers t)))))
     (message-position-point)))
 
 ;;;###autoload
index a09c05c..b166d07 100644 (file)
@@ -210,6 +210,11 @@ to:
 (defvar mm-last-shell-command "")
 (defvar mm-content-id-alist nil)
 
+;; According to RFC2046, in particular, in a digest, the default
+;; Content-Type value for a body part is changed from "text/plain" to
+;; "message/rfc822".
+(defvar mm-dissect-default-type "text/plain")
+
 ;;; The functions.
 
 (defun mm-dissect-buffer (&optional no-strict-mime)
@@ -231,7 +236,7 @@ to:
       (if (or (not ctl)
              (not (string-match "/" (car ctl))))
          (mm-dissect-singlepart
-          '("text/plain")
+          (list mm-dissect-default-type)
           (and cte (intern (downcase (mail-header-remove-whitespace
                                       (mail-header-remove-comments
                                        cte)))))
@@ -245,7 +250,10 @@ to:
         result
         (cond
          ((equal type "multipart")
-          (cons (car ctl) (mm-dissect-multipart ctl)))
+          (let ((mm-dissect-default-type (if (equal subtype "digest")
+                                             "message/rfc822"
+                                           "text/plain")))
+            (cons (car ctl) (mm-dissect-multipart ctl))))
          (t
           (mm-dissect-singlepart
            ctl
index ba1a65e..1302ad8 100644 (file)
@@ -72,6 +72,8 @@ 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")
+
 (defun mml-parse ()
   "Parse the current buffer as an MML document."
   (goto-char (point-min))
@@ -287,7 +289,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
@@ -351,6 +354,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)
@@ -420,7 +426,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."))
index 06b6c5e..374b565 100644 (file)
@@ -87,6 +87,7 @@ from the document.")
      (article-transform-function . nndoc-transform-clari-briefs))
     (mime-digest
      (article-begin . "")
+     (head-begin . "^ ?\n")
      (head-end . "^ ?$")
      (body-end . "")
      (file-end . "")
@@ -527,10 +528,11 @@ from the document.")
            nil t)
           (match-beginning 1))
       (setq boundary-id (match-string 1)
-           b-delimiter (concat "\n--" boundary-id "[\n \t]+"))
+           b-delimiter (concat "\n--" boundary-id "[ \t]*$"))
       (setq entry (assq 'mime-digest nndoc-type-alist))
       (setcdr entry
              (list
+              (cons 'head-begin "^ ?\n")
               (cons 'head-end "^ ?$")
               (cons 'body-begin "^ ?\n")
               (cons 'article-begin b-delimiter)