* mime-pgp.el (mime-pgp-use): New variable. emiko-1_14_1-epg-0_0_5
authorueno <ueno>
Sun, 3 Sep 2006 03:34:23 +0000 (03:34 +0000)
committerueno <ueno>
Sun, 3 Sep 2006 03:34:23 +0000 (03:34 +0000)
(mime-view-application/pgp-with-epg): Renamed from
mime-view-application/pgp.
(mime-view-application/pgp-with-pgg): Revived for backward
compatibility.
(mime-verify-application/*-signature-with-epg): Renamed from
mime-verify-application/*-signature.
(mime-verify-application/*-signature-with-pgg): Revived for
backward compatibility.
(mime-add-application/pgp-keys-with-epg): Renamed from
mime-add-application/pgp-keys.
(mime-add-application/pgp-keys-with-pgg): Revived for backward
compatibility.

* mime-edit.el (mime-edit-pgp-use): New variable.
(mime-edit-sign-pgp-mime-with-epg): Renamed from
mime-edit-sign-pgp-mime.
(mime-edit-sign-pgp-mime-with-pgg): Revived for backward
compatibility.
(mime-edit-encrypt-pgp-mime-with-epg): Renamed from
mime-edit-encrypt-pgp-mime.
(mime-edit-encrypt-pgp-mime-with-pgg): Revived for backward
compatibility.
(mime-edit-sign-pgp-kazu-with-epg): Renamed from
mime-edit-sign-pgp-kazu.
(mime-edit-sign-pgp-kazu-with-pgg): Revived for backward
compatibility.
(mime-edit-encrypt-pgp-kazu-with-epg): Renamed from
mime-edit-encrypt-pgp-kazu.
(mime-edit-encrypt-pgp-kazu-with-pgg): Revived for backward
compatibility.

ChangeLog
mime-edit.el
mime-pgp.el

index 67ec0dd..8db0c0d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,19 +1,36 @@
 2006-09-03  Daiki Ueno  <ueno@unixuser.org>
 
+       * mime-pgp.el (mime-pgp-use): New variable.
+       (mime-view-application/pgp-with-epg): Renamed from
+       mime-view-application/pgp.
+       (mime-view-application/pgp-with-pgg): Revived for backward
+       compatibility.
+       (mime-verify-application/*-signature-with-epg): Renamed from
+       mime-verify-application/*-signature.
+       (mime-verify-application/*-signature-with-pgg): Revived for
+       backward compatibility.
+       (mime-add-application/pgp-keys-with-epg): Renamed from
+       mime-add-application/pgp-keys.
+       (mime-add-application/pgp-keys-with-pgg): Revived for backward
+       compatibility.
+
        * mime-edit.el (mime-edit-pgp-use): New variable.
-       (mime-edit-epg-sign-pgp-mime): Renamed from
+       (mime-edit-sign-pgp-mime-with-epg): Renamed from
        mime-edit-sign-pgp-mime.
-       (mime-edit-pgg-sign-pgp-mime): Revived for backward compatibility.
-       (mime-edit-epg-encrypt-pgp-mime): Renamed from
+       (mime-edit-sign-pgp-mime-with-pgg): Revived for backward
+       compatibility.
+       (mime-edit-encrypt-pgp-mime-with-epg): Renamed from
        mime-edit-encrypt-pgp-mime.
-       (mime-edit-pgg-encrypt-pgp-mime): Revived for backward
+       (mime-edit-encrypt-pgp-mime-with-pgg): Revived for backward
        compatibility.
-       (mime-edit-epg-sign-pgp-kazu): Renamed from
+       (mime-edit-sign-pgp-kazu-with-epg): Renamed from
        mime-edit-sign-pgp-kazu.
-       (mime-edit-pgg-sign-pgp-kazu): Revived for backward compatibility.
-       (mime-edit-epg-encrypt-pgp-kazu): Renamed from
+       (mime-edit-sign-pgp-kazu-with-pgg): Revived for backward
+       compatibility.
+       (mime-edit-encrypt-pgp-kazu-with-epg): Renamed from
        mime-edit-encrypt-pgp-kazu.
-       (mime-edit-pgg-encrypt-pgp-kazu): Revived for backward compatibility.
+       (mime-edit-encrypt-pgp-kazu-with-pgg): Revived for backward
+       compatibility.
 
 2006-07-04  Daiki Ueno  <ueno@unixuser.org>
 
index e8d5961..f3b6638 100644 (file)
@@ -1625,20 +1625,20 @@ Parameter must be '(PROMPT CHOICE1 (CHOICE2...))."
                 (mime-edit-enquote-region bb eb))
                ((string-equal type "pgp-signed")
                 (if (eq mime-edit-pgp-use 'epg)
-                    (mime-edit-epg-sign-pgp-mime bb eb boundary)
-                  (mime-edit-pgg-sign-pgp-mime bb eb boundary)))
+                    (mime-edit-sign-pgp-mime-with-epg bb eb boundary)
+                  (mime-edit-sign-pgp-mime-with-pgg bb eb boundary)))
                ((string-equal type "pgp-encrypted")
                 (if (eq mime-edit-pgp-use 'epg)
-                    (mime-edit-epg-encrypt-pgp-mime bb eb boundary)
-                  (mime-edit-pgg-encrypt-pgp-mime bb eb boundary)))
+                    (mime-edit-encrypt-pgp-mime-with-epg bb eb boundary)
+                  (mime-edit-encrypt-pgp-mime-with-pgg bb eb boundary)))
                ((string-equal type "kazu-signed")
                 (if (eq mime-edit-pgp-use 'epg)
-                    (mime-edit-epg-sign-pgp-kazu bb eb boundary)
-                  (mime-edit-pgg-sign-pgp-kazu bb eb boundary)))
+                    (mime-edit-sign-pgp-kazu-with-epg bb eb boundary)
+                  (mime-edit-sign-pgp-kazu-with-pgg bb eb boundary)))
                ((string-equal type "kazu-encrypted")
                 (if (eq mime-edit-pgp-use 'epg)
-                    (mime-edit-epg-encrypt-pgp-kazu bb eb boundary)
-                  (mime-edit-pgg-encrypt-pgp-kazu bb eb boundary)))
+                    (mime-edit-encrypt-pgp-kazu-with-epg bb eb boundary)
+                  (mime-edit-encrypt-pgp-kazu-with-pgg bb eb boundary)))
                ((string-equal type "smime-signed")
                 (mime-edit-sign-smime bb eb boundary))
                ((string-equal type "smime-encrypted")
@@ -1682,7 +1682,7 @@ Parameter must be '(PROMPT CHOICE1 (CHOICE2...))."
       (while (re-search-forward "[ \t]+$" nil t)
        (delete-region (match-beginning 0) (match-end 0))))))
 
-(defun mime-edit-epg-sign-pgp-mime (beg end boundary)
+(defun mime-edit-sign-pgp-mime-with-epg (beg end boundary)
   (save-excursion
     (save-restriction
       (let* ((from (std11-field-body "From" mail-header-separator))
@@ -1745,7 +1745,7 @@ Content-Description: OpenPGP Digital Signature
        (goto-char (point-max))
        (insert (format "\n--%s--\n" pgp-boundary))))))
 
-(defun mime-edit-pgg-sign-pgp-mime (beg end boundary)
+(defun mime-edit-sign-pgp-mime-with-pgg (beg end boundary)
   (save-excursion
     (save-restriction
       (let* ((from (std11-field-body "From" mail-header-separator))
@@ -1823,7 +1823,7 @@ Content-Transfer-Encoding: 7bit
            values (cdr values)))
     (vector from recipients header)))
 
-(defun mime-edit-epg-encrypt-pgp-mime (beg end boundary)
+(defun mime-edit-encrypt-pgp-mime-with-epg (beg end boundary)
   (save-excursion
     (save-restriction
       (let (recipients header)
@@ -1879,7 +1879,7 @@ Content-Transfer-Encoding: 7bit
          (goto-char (point-max))
          (insert (format "\n--%s--\n" pgp-boundary)))))))
 
-(defun mime-edit-pgg-encrypt-pgp-mime (beg end boundary)
+(defun mime-edit-encrypt-pgp-mime-with-pgg (beg end boundary)
   (save-excursion
     (save-restriction
       (let (from recipients header)
@@ -1930,7 +1930,7 @@ Content-Transfer-Encoding: 7bit
          (goto-char (point-max))
          (insert (format "\n--%s--\n" pgp-boundary)))))))
 
-(defun mime-edit-epg-sign-pgp-kazu (beg end boundary)
+(defun mime-edit-sign-pgp-kazu-with-epg (beg end boundary)
   (save-excursion
     (save-restriction
       (narrow-to-region beg end)
@@ -1956,7 +1956,7 @@ Content-Transfer-Encoding: 7bit
         "--[[application/pgp; format=mime][7bit]]\n" signature)
        ))))
 
-(defun mime-edit-pgg-sign-pgp-kazu (beg end boundary)
+(defun mime-edit-sign-pgp-kazu-with-pgg (beg end boundary)
   (save-excursion
     (save-restriction
       (narrow-to-region beg end)
@@ -1976,7 +1976,7 @@ Content-Transfer-Encoding: 7bit
         "--[[application/pgp; format=mime][7bit]]\n")
        ))))
 
-(defun mime-edit-epg-encrypt-pgp-kazu (beg end boundary)
+(defun mime-edit-encrypt-pgp-kazu-with-epg (beg end boundary)
   (save-excursion
     (let (recipients header)
       (let ((ret (mime-edit-make-encrypt-recipient-header)))
@@ -2018,7 +2018,7 @@ If no one is selected, symmetric encryption will be performed.  "
           "--[[application/pgp; format=mime][7bit]]\n" cipher)
          )))))
 
-(defun mime-edit-pgg-encrypt-pgp-kazu (beg end boundary)
+(defun mime-edit-encrypt-pgp-kazu-with-pgg (beg end boundary)
   (save-excursion
     (let (recipients header)
       (let ((ret (mime-edit-make-encrypt-recipient-header)))
index aafe5fd..c607fa3 100644 (file)
 ;;; Code:
 
 (require 'mime-play)
-(require 'epg)
-(require 'epa)
+
+(defvar mime-pgp-use
+  (condition-case nil
+      (progn
+       (require 'epg-config)
+       (epg-check-configuration (epg-configuration))
+       (autoload 'epg-make-context "epg")
+       'epg)
+    (error
+     (require 'pgg-def)
+     (autoload 'pgg-decrypt-region "pgg"
+       "PGP decryption of current region." t)
+     (autoload 'pgg-verify-region "pgg"
+       "PGP verification of current region." t)
+     (autoload 'pgg-snarf-keys-region "pgg"
+       "Snarf PGP public keys in current region." t)
+     'pgg))
+  "Which PGG library to be used.")
 
 ;;; @ Internal method for multipart/signed
 ;;;
@@ -70,7 +86,7 @@
 ;;;
 ;;; It is based on draft-kazu-pgp-mime-00.txt (PGP-kazu).
 
-(defun mime-view-application/pgp (entity situation)
+(defun mime-view-application/pgp-with-epg (entity situation)
   (let* ((p-win (or (get-buffer-window (current-buffer))
                    (get-largest-window)))
         (new-name
             (epg-context-result-for context 'verify))
        (epa-display-verify-result (epg-context-result-for context 'verify)))))
 
+(defun mime-view-application/pgp-with-pgg (entity situation)
+  (let* ((p-win (or (get-buffer-window (current-buffer))
+                   (get-largest-window)))
+        (new-name
+         (format "%s-%s" (buffer-name) (mime-entity-number entity)))
+        (mother (current-buffer))
+        (preview-buffer (concat "*Preview-" (buffer-name) "*"))
+        representation-type message-buf)
+    (set-buffer (setq message-buf (get-buffer-create new-name)))
+    (erase-buffer)
+    (mime-insert-entity entity)
+    (cond ((progn
+            (goto-char (point-min))
+            (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE-+$" nil t))
+          (pgg-verify-region (match-beginning 0)(point-max) nil 'fetch)
+          (goto-char (point-min))
+          (delete-region
+           (point-min)
+           (and
+            (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE-+\n\n")
+            (match-end 0)))
+          (delete-region
+           (and (re-search-forward "^-+BEGIN PGP SIGNATURE-+")
+                (match-beginning 0))
+           (point-max))
+          (goto-char (point-min))
+          (while (re-search-forward "^- -" nil t)
+            (replace-match "-"))
+          (setq representation-type (if (mime-entity-cooked-p entity)
+                                        'cooked)))
+         ((progn
+            (goto-char (point-min))
+            (re-search-forward "^-+BEGIN PGP MESSAGE-+$" nil t))
+          (pgg-decrypt-region (point-min)(point-max))
+          (delete-region (point-min)(point-max))
+          (insert-buffer pgg-output-buffer)
+          (setq representation-type 'binary)))
+    (setq major-mode 'mime-show-message-mode)
+    (save-window-excursion
+      (mime-view-buffer nil preview-buffer mother
+                       nil representation-type)
+      (make-local-variable 'mime-view-temp-message-buffer)
+      (setq mime-view-temp-message-buffer message-buf))
+    (set-window-buffer p-win preview-buffer)))
+
 
 (defun mime-verify-application/*-signature (entity situation)
+  (if (eq mime-pgp-use 'epg)
+      (mime-verify-application/*-signature-with-epg entity situation)
+    (mime-verify-application/*-signature-with-pgg entity situation)))
+
+(defun mime-verify-application/*-signature-with-epg (entity situation)
   (let* ((entity-node-id (mime-entity-node-id entity))
         (mother (mime-entity-parent entity))
         (knum (car entity-node-id))
     (if (epg-context-result-for context 'verify)
        (epa-display-verify-result (epg-context-result-for context 'verify)))))
 
+(defun mime-verify-application/*-signature-with-pgg (entity situation)
+  (let* ((entity-node-id (mime-entity-node-id entity))
+        (mother (mime-entity-parent entity))
+        (knum (car entity-node-id))
+        (onum (if (> knum 0)
+                  (1- knum)
+                (1+ knum)))
+        (orig-entity (nth onum (mime-entity-children mother)))
+        (protocol (cdr (assoc "protocol" (mime-entity-parameters mother))))
+        (sig-file (make-temp-file "tm" nil ".asc")))
+    (unless (equal protocol "application/pgp-signature")
+      (error "Not supported protocol: %s" protocol))
+    (save-excursion 
+      (mime-show-echo-buffer)
+      (set-buffer mime-echo-buffer-name)
+      (set-window-start 
+       (get-buffer-window mime-echo-buffer-name)
+       (point-max)))
+    (mime-write-entity-content entity sig-file)
+    (unwind-protect
+       (with-temp-buffer
+         (mime-insert-entity orig-entity)
+         (goto-char (point-min))
+         (while (progn (end-of-line) (not (eobp)))
+           (insert "\r")
+           (forward-line 1))
+         (pgg-verify-region (point-min)(point-max) 
+                            sig-file 'fetch)
+         (save-excursion 
+           (set-buffer mime-echo-buffer-name)
+           (insert-buffer-substring pgg-errors-buffer)))
+      (delete-file sig-file))))
+
 
 ;;; @ Internal method for application/pgp-encrypted
 ;;;
                   (1- knum)
                 (1+ knum)))
         (orig-entity (nth onum (mime-entity-children mother))))
-    (mime-view-application/pgp orig-entity situation)))
+    (if (eq mime-pgp-use 'epg)
+       (mime-view-application/pgp-with-epg orig-entity situation)
+      (mime-view-application/pgp-with-pgg orig-entity situation))))
 
 
 ;;; @ Internal method for application/pgp-keys
 ;;; draft-ietf-openpgp-mime-02.txt (OpenPGP/MIME).
 
 (defun mime-add-application/pgp-keys (entity situation)
+  (if (eq mime-pgp-use 'epg)
+      (mime-add-application/pgp-keys-with-epg entity situation)
+    (mime-add-application/pgp-keys-with-pgg entity situation)))
+
+(defun mime-add-application/pgp-keys-with-epg (entity situation)
   (epg-import-keys-from-string (epg-make-context)
                               (mime-entity-content entity)))
 
+(defun mime-add-application/pgp-keys-with-pgg (entity situation)
+  (save-excursion 
+    (mime-show-echo-buffer)
+    (set-buffer mime-echo-buffer-name)
+    (set-window-start 
+     (get-buffer-window mime-echo-buffer-name)
+     (point-max)))
+  (with-temp-buffer
+    (mime-insert-entity-content entity)
+    (mime-decode-region (point-min) (point-max)
+                        (cdr (assq 'encoding situation)))
+    (pgg-snarf-keys-region (point-min)(point-max))
+    (save-excursion 
+      (set-buffer mime-echo-buffer-name)
+      (insert-buffer-substring pgg-errors-buffer))))
 
 ;;; @ Internal method for application/pkcs7-mime
 ;;;