* gnus.el (gnus-other-frame-function): New user option.
[gnus] / lisp / mml.el
index bd74610..6065476 100644 (file)
@@ -65,7 +65,7 @@ NAME is a string containing the name of the TWEAK parameter in the MML
 handle.  FUNCTION is a Lisp function which is called with the MML
 handle to tweak the part.")
 
-(defvar mml-tweak-sexp-alist 
+(defvar mml-tweak-sexp-alist
   '((mml-externalize-attachments . mml-tweak-externalize-attachments))
   "A list of (SEXP . FUNCTION) for tweaking MML parts.
 SEXP is a s-expression. If the evaluation of SEXP is non-nil, FUNCTION
@@ -151,7 +151,10 @@ one charsets.")
        (let* (secure-mode
               (taginfo (mml-read-tag))
               (recipients (cdr (assq 'recipients taginfo)))
-              (location (cdr (assq 'tag-location taginfo))))
+              (location (cdr (assq 'tag-location taginfo)))
+              (mode (cdr (assq 'mode taginfo)))
+              (method (cdr (assq 'method taginfo)))
+              tags)
          (save-excursion
            (if
                (re-search-forward
@@ -162,11 +165,16 @@ one charsets.")
            (goto-char location)
            (re-search-forward "<#secure[^\n]*>\n"))
          (delete-region (match-beginning 0) (match-end 0))
-         (mml-insert-tag secure-mode
-                         (cdr (assq 'mode taginfo))
-                         (cdr (assq 'method taginfo))
-                         (and recipients 'recipients)
-                         recipients)
+         (cond ((string= mode "sign")
+                (setq tags (list "sign" method)))
+               ((string= mode "encrypt")
+                (setq tags (list "encrypt" method)))
+               ((string= mode "signencrypt")
+                (setq tags (list "sign" method "encrypt" method))))
+         (eval `(mml-insert-tag ,secure-mode
+                                ,@tags
+                                ,(if recipients 'recipients)
+                                ,recipients))
          ;; restart the parse
          (goto-char location)))
        ((looking-at "<#multipart")
@@ -191,7 +199,7 @@ one charsets.")
                         (list
                          (intern (downcase (cdr (assq 'charset tag))))))
                        (t
-                        (mm-find-mime-charset-region point (point) 
+                        (mm-find-mime-charset-region point (point)
                                                      mm-hack-charsets))))
        (when (and (not raw) (memq nil charsets))
          (if (or (memq 'unknown-encoding mml-confirmation-set)
@@ -433,7 +441,8 @@ If MML is non-nil, return the buffer up till the correspondent mml tag."
                  (let (use-hard-newlines)
                    (when (and (string= type "text/plain")
                               (or (null (assq 'format cont))
-                                  (string= (assq 'format cont) "flowed"))
+                                  (string= (cdr (assq 'format cont))
+                                           "flowed"))
                               (setq use-hard-newlines
                                     (text-property-any
                                      (point-min) (point-max) 'hard 't)))
@@ -521,22 +530,29 @@ If MML is non-nil, return the buffer up till the correspondent mml tag."
              (insert "\n--" mml-boundary "--\n")))))
        (t
        (error "Invalid element: %S" cont)))
-      (let ((item (assoc (cdr (assq 'sign cont)) mml-sign-alist))
+      ;; handle sign & encrypt tags in a semi-smart way.
+      (let ((sign-item (assoc (cdr (assq 'sign cont)) mml-sign-alist))
+           (encrypt-item (assoc (cdr (assq 'encrypt cont))
+                                mml-encrypt-alist))
            sender recipients)
-       (when item
+       (when (or sign-item encrypt-item)
          (if (setq sender (cdr (assq 'sender cont)))
              (message-options-set 'message-sender sender))
          (if (setq recipients (cdr (assq 'recipients cont)))
              (message-options-set 'message-recipients recipients))
-         (funcall (nth 1 item) cont)))
-      (let ((item (assoc (cdr (assq 'encrypt cont)) mml-encrypt-alist))
-           sender recipients)
-       (when item
-         (if (setq sender (cdr (assq 'sender cont)))
-             (message-options-set 'message-sender sender))
-         (if (setq recipients (cdr (assq 'recipients cont)))
-             (message-options-set 'message-recipients recipients))
-         (funcall (nth 1 item) cont))))))
+         (let ((style (mml-signencrypt-style (first (or sign-item encrypt-item)))))
+           ;; check if: we're both signing & encrypting, both methods
+           ;; are the same (why would they be different?!), and that
+           ;; the signencrypt style allows for combined operation.
+           (if (and sign-item encrypt-item (equal (first sign-item)
+                                                  (first encrypt-item))
+                    (equal style 'combined))
+               (funcall (nth 1 encrypt-item) cont t)
+             ;; otherwise, revert to the old behavior.
+             (when sign-item
+               (funcall (nth 1 sign-item) cont))
+             (when encrypt-item
+               (funcall (nth 1 encrypt-item) cont)))))))))
 
 (defun mml-compute-boundary (cont)
   "Return a unique boundary that does not exist in CONT."
@@ -782,6 +798,7 @@ If HANDLES is non-nil, use it instead reparsing the buffer."
     (define-key encrypt "p" 'mml-secure-message-encrypt-pgpmime)
     (define-key encrypt "o" 'mml-secure-message-encrypt-pgp)
     (define-key encrypt "s" 'mml-secure-message-encrypt-smime)
+    (define-key map "\C-n" 'mml-unsecure-message)
     (define-key map "f" 'mml-attach-file)
     (define-key map "b" 'mml-attach-buffer)
     (define-key map "e" 'mml-attach-external)
@@ -814,6 +831,7 @@ If HANDLES is non-nil, use it instead reparsing the buffer."
     ["PGP Encrypt" mml-secure-message-encrypt-pgp t]
     ["S/MIME Sign" mml-secure-message-sign-smime t]
     ["S/MIME Encrypt" mml-secure-message-encrypt-smime t]
+    ["Encrypt/Sign off" mml-unsecure-message t]
     ;;["Narrow" mml-narrow-to-part t]
     ["Quote MML" mml-quote-region t]
     ["Validate MML" mml-validate t]
@@ -988,6 +1006,13 @@ If RAW, don't highlight the article."
                                   "*MIME preview of ") (buffer-name))))
       (erase-buffer)
       (insert-buffer buf)
+      (let ((message-deletable-headers (if (message-news-p)
+                                          nil
+                                        message-deletable-headers)))
+       (message-generate-headers
+        (copy-sequence (if (message-news-p)
+                           message-required-news-headers
+                         message-required-mail-headers))))
       (if (re-search-forward
           (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
          (replace-match "\n"))
@@ -1003,7 +1028,9 @@ If RAW, don't highlight the article."
        (let ((gnus-newsgroup-charset (car message-posting-charset))
              gnus-article-prepare-hook gnus-original-article-buffer)
          (run-hooks 'gnus-article-decode-hook)
-         (let ((gnus-newsgroup-name "dummy"))
+         (let ((gnus-newsgroup-name "dummy")
+               (gnus-newsrc-hashtb (or gnus-newsrc-hashtb
+                                       (gnus-make-hashtable 5))))
            (gnus-article-prepare-display))))
       ;; Disable article-mode-map.
       (use-local-map nil)
@@ -1046,7 +1073,7 @@ If RAW, don't highlight the article."
 (defun mml-tweak-externalize-attachments (cont)
   "Tweak attached files as external parts."
   (let (filename-cons)
-    (when (and (eq (car cont) 'part) 
+    (when (and (eq (car cont) 'part)
               (not (cdr (assq 'buffer cont)))
               (and (setq filename-cons (assq 'filename cont))
                    (not (equal (cdr (assq 'nofile cont)) "yes"))))