2000-11-06 18:17:53 ShengHuo ZHU <zsh@cs.rochester.edu>
authorShengHuo ZHU <zsh@cs.rochester.edu>
Mon, 6 Nov 2000 22:27:12 +0000 (22:27 +0000)
committerShengHuo ZHU <zsh@cs.rochester.edu>
Mon, 6 Nov 2000 22:27:12 +0000 (22:27 +0000)
* gnus-art.el (gnus-article-encrypt): New function.
(gnus-article-encrypt-protocol-alist): New variable.
(gnus-article-encrypt-protocol): New variable.
* mml2015.el (mml2015-self-encrypt): New function.
(mml2015-mailcrypt-encrypt): Set mc-pgp-always-sign.

lisp/ChangeLog
lisp/gnus-art.el
lisp/gnus-sum.el
lisp/mml2015.el

index c0999b5..519d342 100644 (file)
@@ -1,3 +1,11 @@
+2000-11-06 18:17:53  ShengHuo ZHU  <zsh@cs.rochester.edu>
+
+       * gnus-art.el (gnus-article-encrypt): New function.
+       (gnus-article-encrypt-protocol-alist): New variable.
+       (gnus-article-encrypt-protocol): New variable.
+       * mml2015.el (mml2015-self-encrypt): New function.
+       (mml2015-mailcrypt-encrypt): Set mc-pgp-always-sign.
+
 2000-11-06 16:02:52  ShengHuo ZHU  <zsh@cs.rochester.edu>
 
        * mm-uu.el (mm-uu-gpg-key-skip-to-last): New function.
index 3b910c0..0919537 100644 (file)
@@ -966,6 +966,15 @@ See the manual for details."
   :group 'gnus-article-treat
   :type gnus-article-treat-custom)
 
+(defvar gnus-article-encrypt-protocol-alist
+  '(("PGP" . mml2015-self-encrypt)))
+
+(defcustom gnus-article-encrypt-protocol nil
+  "The protocol used for encrypt articles.
+It is a string, such as \"PGP\". If nil, ask user."
+  :type 'string
+  :group 'mime-security)
+
 ;;; Internal variables
 
 (defvar article-goto-body-goes-to-point-min-p nil)
@@ -4894,6 +4903,74 @@ For example:
    (t
     (error "%S is not a valid value" val))))
 
+(defun gnus-article-encrypt (protocol)
+  "Replace the article with encrypted one."
+  (interactive 
+   (list
+    (or gnus-article-encrypt-protocol
+       (completing-read "Encrypt protocol: "
+                        gnus-article-encrypt-protocol-alist 
+                        nil t))))
+  (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
+    (unless func
+      (error (format "Can't find the encrypt protocol %s" protocol)))
+    (if (equal gnus-newsgroup-name "nndraft:drafts")
+       (error "Can't encrypt the article in group nndraft:drafts."))
+    (save-excursion
+      (set-buffer gnus-summary-buffer)
+      (let ((mail-parse-charset gnus-newsgroup-charset)
+           (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
+           (summary-buffer gnus-summary-buffer)
+           references point)
+       (gnus-set-global-variables)
+       (when (gnus-group-read-only-p)
+         (error "The current newsgroup does not support article encrypt"))
+       (gnus-summary-show-article t)
+       (setq references
+             (or (mail-header-references gnus-current-headers) ""))
+       (set-buffer gnus-article-buffer)
+       (let* ((buffer-read-only nil)
+              (headers
+               (mapcar (lambda (field)
+                         (and (save-restriction 
+                                (message-narrow-to-head)
+                                (goto-char (point-min))
+                                (search-forward field nil t))
+                              (prog2
+                                  (message-narrow-to-field)
+                                  (buffer-substring (point-min) (point-max))
+                                (delete-region (point-min) (point-max))
+                                (widen))))
+                       '("Content-Type:" "Content-Transfer-Encoding:"
+                         "Content-Disposition:"))))
+         (message-narrow-to-head)
+         (message-remove-header "MIME-Version")
+         (goto-char (point-max))
+         (setq point (point))
+         (insert (apply 'concat headers))
+         (widen)
+         (narrow-to-region point (point-max))
+         (let ((message-options message-options))
+           (message-options-set 'message-sender user-mail-address)
+           (message-options-set 'message-recipients user-mail-address)
+           (message-options-set 'message-sign-encrypt 'not)
+           (funcall func))
+         (goto-char (point-min))
+         (insert "MIME-Version: 1.0\n")
+         (widen)
+         (gnus-summary-edit-article-done
+          references nil summary-buffer t))
+       (when gnus-keep-backlog
+         (gnus-backlog-remove-article
+          (car gnus-article-current) (cdr gnus-article-current)))
+       (save-excursion
+         (when (get-buffer gnus-original-article-buffer)
+           (set-buffer gnus-original-article-buffer)
+           (setq gnus-original-article nil)))
+       (when gnus-use-cache
+         (gnus-cache-update-article
+          (car gnus-article-current) (cdr gnus-article-current)))))))
+
 (gnus-ems-redefine)
 
 (provide 'gnus-art)
index a151171..6748ce7 100644 (file)
@@ -1654,6 +1654,7 @@ increase the score of each group you read."
     "c" gnus-article-copy-part
     "C" gnus-article-view-part-as-charset
     "e" gnus-article-externalize-part
+    "E" gnus-article-encrypt
     "i" gnus-article-inline-part
     "|" gnus-article-pipe-part))
 
@@ -1713,7 +1714,8 @@ increase the score of each group you read."
              ["QP" gnus-article-de-quoted-unreadable t]
              ["Base64" gnus-article-de-base64-unreadable t]
              ["View all" gnus-mime-view-all-parts t]
-             ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt])
+             ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt]
+             ["Encrypt" gnus-article-encrypt])
              ("Date"
               ["Local" gnus-article-date-local t]
               ["ISO8601" gnus-article-date-iso8601 t]
index 46385b1..dfd62be 100644 (file)
     (goto-char (point-max))))
 
 (defun mml2015-mailcrypt-encrypt (cont)
-  (mc-encrypt-generic 
-   (or (message-options-get 'message-recipients)
-       (message-options-set 'message-recipients
-                           (mc-cleanup-recipient-headers 
-                            (read-string "Recipients: "))))
-   nil nil nil
-   (message-options-get 'message-sender)
-   (or mc-pgp-always-sign
-       (eq t
-          (or (message-options-get 'message-sign-encrypt)
-              (message-options-set 'message-sign-encrypt
-                                   (or (y-or-n-p "Sign the message? ")
-                                       'not))))))
+  (let ((mc-pgp-always-sign
+        (or mc-pgp-always-sign
+            (eq t (or (message-options-get 'message-sign-encrypt)
+                      (message-options-set 
+                       'message-sign-encrypt
+                       (or (y-or-n-p "Sign the message? ")
+                           'not))))
+            'never)))
+    (mc-encrypt-generic 
+     (or (message-options-get 'message-recipients)
+        (message-options-set 'message-recipients
+                             (mc-cleanup-recipient-headers 
+                              (read-string "Recipients: "))))
+     nil nil nil
+     (message-options-get 'message-sender)))
   (let ((boundary 
         (funcall mml-boundary-function (incf mml-multipart-number))))
     (goto-char (point-min))
        (funcall func cont)
       (error "Cannot find sign function."))))
 
+;;;###autoload
+(defun mml2015-self-encrypt ()
+  (mml2015-encrypt nil))
+
 (provide 'mml2015)
 
 ;;; mml2015.el ends here