Synch with Gnus.
[elisp/gnus.git-] / lisp / mm-uu.el
index 47aa032..d583c5e 100644 (file)
@@ -85,7 +85,7 @@ This can be either \"inline\" or \"attachment\".")
      mm-uu-binhex-filename)
     (shar 
      "^#! */bin/sh"
-     "^exit 0\\|^$"
+     "^exit 0$"
      mm-uu-shar-extract)
     (forward 
 ;;; Thanks to Edward J. Sabol <sabol@alderaan.gsfc.nasa.gov> and 
@@ -104,13 +104,13 @@ This can be either \"inline\" or \"attachment\".")
      "^-----END PGP SIGNATURE-----"
      mm-uu-pgp-signed-extract
      nil
-     mm-uu-pgp-signed-test)
+     nil)
     (pgp-encrypted
      "^-----BEGIN PGP MESSAGE-----"
      "^-----END PGP MESSAGE-----"
      mm-uu-pgp-encrypted-extract
      nil
-     mm-uu-pgp-encrypted-test)
+     nil)
     (pgp-key
      "^-----BEGIN PGP PUBLIC KEY BLOCK-----"
      "^-----END PGP PUBLIC KEY BLOCK-----"
@@ -151,7 +151,7 @@ To disable dissecting shar codes, for instance, add
 (defsubst mm-uu-function-2 (entry)
   (nth 5 entry))
 
-(defun mm-uu-copy-to-buffer (from to)
+(defun mm-uu-copy-to-buffer (&optional from to)
   "Copy the contents of the current buffer to a fresh buffer."
   (save-excursion
     (let ((obuf (current-buffer)))
@@ -246,7 +246,7 @@ To disable dissecting shar codes, for instance, add
     (narrow-to-region (point) end-point)
     (mm-dissect-buffer t)))
 
-(defun mm-uu-pgp-signed-test ()
+(defun mm-uu-pgp-signed-test (&rest rest)
   (and
    mml2015-use
    (mml2015-clear-verify-function)
@@ -256,26 +256,43 @@ To disable dissecting shar codes, for instance, add
     ((eq mm-verify-option 'known) t)
     (t (y-or-n-p "Verify pgp signed part?")))))
 
-(defun mm-uu-pgp-signed-extract ()
-  (or (memq 'signed gnus-article-wash-types)
-      (push 'signed gnus-article-wash-types))
-  (let ((buf (mm-uu-copy-to-buffer start-point end-point)))
+(defun mm-uu-pgp-signed-extract-1 (handles ctl)
+  (let ((buf (mm-uu-copy-to-buffer (point-min) (point-max))))
     (with-current-buffer buf
-      (condition-case err
-         (funcall (mml2015-clear-verify-function))
-       (error
-        (unless (y-or-n-p (format "%s, continue?" err))
-          (kill-buffer buf)
-          (error "Verify failure."))))
+      (if (mm-uu-pgp-signed-test)
+         (progn
+           (mml2015-clean-buffer)
+           (let ((coding-system-for-write (or gnus-newsgroup-charset
+                                              'iso-8859-1)))
+             (funcall (mml2015-clear-verify-function))))
+       (when (and mml2015-use (null (mml2015-clear-verify-function)))
+         (mm-set-handle-multipart-parameter
+          mm-security-handle 'gnus-details 
+          (format "Clear verification not supported by `%s'.\n" mml2015-use))))
       (goto-char (point-min))
       (if (search-forward "\n\n" nil t)
          (delete-region (point-min) (point)))
       (if (re-search-forward mm-uu-pgp-beginning-signature nil t)
          (delete-region (match-beginning 0) (point-max))))
-    (mm-make-handle buf
-                   '("text/plain"  (charset . gnus-decoded)))))
+    (list
+     (mm-make-handle buf
+                    '("text/plain"  (charset . gnus-decoded))))))
 
-(defun mm-uu-pgp-encrypted-test ()
+(defun mm-uu-pgp-signed-extract ()
+  (let ((mm-security-handle (list (format "multipart/signed"))))
+    (mm-set-handle-multipart-parameter 
+     mm-security-handle 'protocol "application/x-gnus-pgp-signature")
+    (save-restriction
+      (narrow-to-region start-point end-point)
+      (add-text-properties 0 (length (car mm-security-handle))
+                          (list 'buffer (mm-uu-copy-to-buffer))
+                          (car mm-security-handle))
+      (setcdr mm-security-handle
+             (mm-uu-pgp-signed-extract-1 nil 
+                                         mm-security-handle)))
+    mm-security-handle))
+
+(defun mm-uu-pgp-encrypted-test (&rest rest)
   (and
    mml2015-use
    (mml2015-clear-decrypt-function)
@@ -285,19 +302,29 @@ To disable dissecting shar codes, for instance, add
     ((eq mm-decrypt-option 'known) t)
     (t (y-or-n-p "Decrypt pgp encrypted part?")))))
 
+(defun mm-uu-pgp-encrypted-extract-1 (handles ctl)
+  (let ((buf (mm-uu-copy-to-buffer (point-min) (point-max))))
+    (if (mm-uu-pgp-encrypted-test)
+       (with-current-buffer buf
+         (mml2015-clean-buffer)
+         (funcall (mml2015-clear-decrypt-function))))
+    (list
+     (mm-make-handle buf
+                    '("text/plain"  (charset . gnus-decoded))))))
+
 (defun mm-uu-pgp-encrypted-extract ()
-  (or (memq 'encrypted gnus-article-wash-types)
-      (push 'encrypted gnus-article-wash-types))
-  (let ((buf (mm-uu-copy-to-buffer start-point end-point)))
-    (with-current-buffer buf
-      (condition-case err
-         (funcall (mml2015-clear-decrypt-function))
-       (error
-        (unless (y-or-n-p (format "%s, continue?" err))
-          (kill-buffer buf)
-          (error "Decrypt failure.")))))
-    (mm-make-handle buf
-                   '("text/plain"  (charset . gnus-decoded)))))
+  (let ((mm-security-handle (list (format "multipart/encrypted"))))
+    (mm-set-handle-multipart-parameter 
+     mm-security-handle 'protocol "application/x-gnus-pgp-encrypted")
+    (save-restriction
+      (narrow-to-region start-point end-point)
+      (add-text-properties 0 (length (car mm-security-handle))
+                          (list 'buffer (mm-uu-copy-to-buffer))
+                          (car mm-security-handle))
+      (setcdr mm-security-handle
+             (mm-uu-pgp-encrypted-extract-1 nil 
+                                            mm-security-handle)))
+    mm-security-handle))
 
 (defun mm-uu-gpg-key-skip-to-last ()
   (let ((point (point))