Synch to No Gnus 200406292138.
[elisp/gnus.git-] / lisp / mml.el
index 40b4a0d..68370d6 100644 (file)
   (autoload 'gnus-setup-posting-charset "gnus-msg")
   (autoload 'gnus-make-local-hook "gnus-util")
   (autoload 'message-fetch-field "message")
+  (autoload 'message-mark-active-p "message")
   (autoload 'fill-flowed-encode "flow-fill")
-  (autoload 'message-posting-charset "message"))
+  (autoload 'message-posting-charset "message")
+  (autoload 'x-dnd-get-local-file-name "x-dnd"))
 
 (defcustom mml-content-type-parameters
   '(name access-type expiration size permission format)
@@ -130,7 +132,7 @@ one charsets.")
 
 (defun mml-destroy-buffers ()
   (let (kill-buffer-hook)
-    (mapcar 'kill-buffer mml-buffer-list)
+    (mapc 'kill-buffer mml-buffer-list)
     (setq mml-buffer-list nil)))
 
 (defun mml-parse ()
@@ -441,6 +443,7 @@ If MML is non-nil, return the buffer up till the correspondent mml tag."
                    ;; actually are hard newlines in the text.
                    (let (use-hard-newlines)
                      (when (and (string= type "text/plain")
+                                (not (string= (cdr (assq 'sign cont)) "pgp"))
                                 (or (null (assq 'format cont))
                                     (string= (cdr (assq 'format cont))
                                              "flowed"))
@@ -548,7 +551,8 @@ If MML is non-nil, return the buffer up till the correspondent mml tag."
            (message-options-set 'message-sender sender))
          (if (setq recipients (cdr (assq 'recipients cont)))
              (message-options-set 'message-recipients recipients))
-         (let ((style (mml-signencrypt-style (first (or sign-item encrypt-item)))))
+         (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.
@@ -582,7 +586,7 @@ If MML is non-nil, return the buffer up till the correspondent mml tag."
          (insert-buffer-substring (cdr (assq 'buffer cont))))
         ((and (setq filename (cdr (assq 'filename cont)))
               (not (equal (cdr (assq 'nofile cont)) "yes")))
-         (mm-insert-file-contents filename))
+         (mm-insert-file-contents filename nil nil nil nil t))
         (t
          (insert (cdr (assq 'contents cont)))))
        (goto-char (point-min))
@@ -592,7 +596,7 @@ If MML is non-nil, return the buffer up till the correspondent mml tag."
                                      (incf mml-multipart-number)))
          (throw 'not-unique nil))))
      ((eq (car cont) 'multipart)
-      (mapcar 'mml-compute-boundary-1 (cddr cont))))
+      (mapc 'mml-compute-boundary-1 (cddr cont))))
     t))
 
 (defun mml-make-boundary (number)
@@ -845,33 +849,36 @@ If HANDLES is non-nil, use it instead reparsing the buffer."
     main))
 
 (easy-menu-define
- mml-menu mml-mode-map ""
- `("Attachments"
-   ["Attach File..." mml-attach-file
-    ,@(if (featurep 'xemacs) '(t)
-       '(:help "Attach a file at point"))]
-   ["Attach Buffer..." mml-attach-buffer t]
-   ["Attach External..." mml-attach-external t]
-   ["Insert Part..." mml-insert-part t]
-   ["Insert Multipart..." mml-insert-multipart t]
-   ["PGP/MIME Sign" mml-secure-message-sign-pgpmime t]
-   ["PGP/MIME Encrypt" mml-secure-message-encrypt-pgpmime t]
-   ["PGP Sign" mml-secure-message-sign-pgp t]
-   ["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]
-   ("Secure MIME part"
-    ["PGP/MIME Sign Part" mml-secure-sign-pgpmime t]
-    ["PGP/MIME Encrypt Part" mml-secure-encrypt-pgpmime t]
-    ["PGP Sign Part" mml-secure-sign-pgp t]
-    ["PGP Encrypt Part" mml-secure-encrypt-pgp t]
-    ["S/MIME Sign Part" mml-secure-sign-smime t]
-    ["S/MIME Encrypt Part" mml-secure-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]
-   ["Preview" mml-preview t]))
+  mml-menu mml-mode-map ""
+  `("Attachments"
+    ["Attach File..." mml-attach-file
+     ,@(if (featurep 'xemacs) '(t)
+        '(:help "Attach a file at point"))]
+    ["Attach Buffer..." mml-attach-buffer t]
+    ["Attach External..." mml-attach-external t]
+    ["Insert Part..." mml-insert-part t]
+    ["Insert Multipart..." mml-insert-multipart t]
+    ["PGP/MIME Sign" mml-secure-message-sign-pgpmime t]
+    ["PGP/MIME Encrypt" mml-secure-message-encrypt-pgpmime t]
+    ["PGP Sign" mml-secure-message-sign-pgp t]
+    ["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]
+    ("Secure MIME part"
+     ["PGP/MIME Sign Part" mml-secure-sign-pgpmime t]
+     ["PGP/MIME Encrypt Part" mml-secure-encrypt-pgpmime t]
+     ["PGP Sign Part" mml-secure-sign-pgp t]
+     ["PGP Encrypt Part" mml-secure-encrypt-pgp t]
+     ["S/MIME Sign Part" mml-secure-sign-smime t]
+     ["S/MIME Encrypt Part" mml-secure-encrypt-smime t])
+    ["Encrypt/Sign off" mml-unsecure-message t]
+    ;;["Narrow" mml-narrow-to-part t]
+    ["Quote MML" mml-quote-region
+     :active (message-mark-active-p)
+     ,@(if (featurep 'xemacs) nil
+        '(:help "Quote MML tags in region"))]
+    ["Validate MML" mml-validate t]
+    ["Preview" mml-preview t]))
 
 (defvar mml-mode nil
   "Minor mode for editing MML.")
@@ -888,6 +895,11 @@ See Info node `(emacs-mime)Composing'.
               (> (prefix-numeric-value arg) 0)))
     (add-minor-mode 'mml-mode " MML" mml-mode-map)
     (easy-menu-add mml-menu mml-mode-map)
+    (when (boundp 'x-dnd-protocol-alist)
+      (set (make-local-variable 'x-dnd-protocol-alist)
+          '(("^file:///" . mml-x-dnd-attach-file)
+            ("^file://"  . x-dnd-open-file)
+            ("^file:"    . mml-x-dnd-attach-file))))
     (run-hooks 'mml-mode-hook)))
 
 ;;;
@@ -1005,6 +1017,15 @@ description of the attachment."
                        'disposition (or disposition "attachment")
                        'description description))
 
+(defun mml-x-dnd-attach-file (uri action)
+  "Attach a drag and drop file."
+  (let ((file (x-dnd-get-local-file-name uri t)))
+    (when (and file (file-regular-p file))
+      (let* ((type (mml-minibuffer-read-type file))
+           (description (mml-minibuffer-read-description))
+           (disposition (mml-minibuffer-read-disposition type)))
+       (mml-attach-file file type description disposition)))))
+
 (defun mml-attach-buffer (buffer &optional type description)
   "Attach a buffer to the outgoing MIME message.
 See `mml-attach-file' for details of operation."