* wl-mime.el (wl-define-dummy-functions): New macro.
authorhmurata <hmurata>
Thu, 28 Sep 2006 12:26:30 +0000 (12:26 +0000)
committerhmurata <hmurata>
Thu, 28 Sep 2006 12:26:30 +0000 (12:26 +0000)
(wl-mime-pgp-decrypt-region-with-epg): Renamed from
`wl-mime-pgp-decrypt-region'.
(wl-mime-pgp-verify-region-with-epg): Renamed from
`wl-mime-pgp-verify-region'.
(wl-mime-pgp-decrypt-region-with-pgg): Renamed from
`wl-mime-pgp-decrypt-region'.
(wl-mime-pgp-verify-region-with-pgg): Renamed from
`wl-mime-pgp-verify-region'.
(wl-mime-pgp-decrypt-region): New function; To select dispatch
function at runtime.
(wl-mime-pgp-verify-region): Ditto.

* wl-vars.el (wl-use-pgp-module): New user option.

wl/ChangeLog
wl/wl-mime.el
wl/wl-vars.el

index 4d33206..190c070 100644 (file)
@@ -1,3 +1,20 @@
+2006-09-28  Hiroya Murata  <lapis-lazuli@pop06.odn.ne.jp>
+
+       * wl-mime.el (wl-define-dummy-functions): New macro.
+       (wl-mime-pgp-decrypt-region-with-epg): Renamed from
+       `wl-mime-pgp-decrypt-region'.
+       (wl-mime-pgp-verify-region-with-epg): Renamed from
+       `wl-mime-pgp-verify-region'.
+       (wl-mime-pgp-decrypt-region-with-pgg): Renamed from
+       `wl-mime-pgp-decrypt-region'.
+       (wl-mime-pgp-verify-region-with-pgg): Renamed from
+       `wl-mime-pgp-verify-region'.
+       (wl-mime-pgp-decrypt-region): New function; To select dispatch
+       function at runtime.
+       (wl-mime-pgp-verify-region): Ditto.
+
+       * wl-vars.el (wl-use-pgp-module): New user option.
+
 2006-09-25  Yoichi NAKAYAMA  <yoichi@geiin.org>
 
        * wl-action.el (wl-summary-set-mark): If the cursor is on folded
index 999dfec..86e5eb5 100644 (file)
@@ -476,76 +476,105 @@ It calls following-method selected from variable
          (wl-summary-sync nil "update"))))))
 
 ;; PGP
-(static-cond
- ((require 'epg nil t)
-  (defun wl-mime-pgp-decrypt-region (beg end &optional no-decode)
-    (require 'epg)
-    (message "Decrypting...")
-    (insert (prog1
-               (decode-coding-string
-                (epg-decrypt-string
-                 (epg-make-context)
-                 (buffer-substring beg end))
-                (if no-decode 'raw-text wl-cs-autoconv))
-             (delete-region beg end)))
-    (message "Decrypting...done")
-    last-coding-system-used)
-
-  (defun wl-mime-pgp-verify-region (beg end &optional coding-system)
-    (require 'epg)
-    (let ((context (epg-make-context)))
-      (message "Verifying...")
-      (epg-verify-string
-       context
-       (encode-coding-string
-       (buffer-substring beg end)
-       (if coding-system
-           (coding-system-change-eol-conversion coding-system 'dos)
-         'raw-text-dos)))
-      (message "Verifying...done")
-      (when (epg-context-result-for context 'verify)
-       (epa-display-verify-result
-        (epg-context-result-for context 'verify))))))
-
- ((require 'pgg nil t)
-  (defun wl-mime-pgp-decrypt-region (beg end &optional no-decode)
-    (require 'pgg)
-    (let ((buffer-file-coding-system wl-cs-autoconv)
-         status)
-      (setq status (pgg-decrypt-region beg end))
-      (if no-decode
-         (when status
-           (delete-region beg end)
-           (insert-buffer-substring pgg-output-buffer))
-       (pgg-display-output-buffer beg end status))
-      (unless status
-       (error "Decryption is failed"))
-      last-coding-system-used))
-
-  (defun wl-mime-pgp-verify-region (beg end &optional coding-system)
-    (require 'pgg)
-    (let ((message-buffer (current-buffer))
-         success)
-      (with-temp-buffer
-       (insert-buffer-substring message-buffer beg end)
-       (when coding-system
-         (encode-coding-region (point-min) (point-max) coding-system))
-       (setq success (pgg-verify-region (point-min) (point-max) nil 'fetch)))
-      (mime-show-echo-buffer)
-      (set-buffer mime-echo-buffer-name)
-      (set-window-start
-       (get-buffer-window mime-echo-buffer-name)
-       (point-max))
-      (insert-buffer-substring
-       (if success
-          pgg-output-buffer
-        pgg-errors-buffer)))))
- (t
-  (defun wl-mime-pgp-decrypt-region (beg end &optional no-decode)
-    (error "Does not support PGP decryption"))
-
-  (defun wl-mime-pgp-verify-region (beg end &optional coding-system)
-    (error "Does not support PGP verification"))))
+(eval-when-compile
+  (defmacro wl-define-dummy-functions (&rest symbols)
+    `(dolist (symbol (quote ,symbols))
+       (defalias symbol 'ignore)))
+
+  (condition-case nil
+      (require 'epa)
+    (error
+     (wl-define-dummy-functions epg-make-context
+                               epg-decrypt-string
+                               epg-verify-string
+                               epg-context-result-for
+                               epa-display-verify-result)))
+  (condition-case nil
+      (require 'pgg)
+    (error
+     (wl-define-dummy-functions pgg-decrypt-region
+                               pgg-verify-region
+                               pgg-display-output-buffer))))
+
+(defun wl-mime-pgp-decrypt-region-with-epg (beg end &optional no-decode)
+  (require 'epg)
+  (message "Decrypting...")
+  (insert (prog1
+             (decode-coding-string
+              (epg-decrypt-string
+               (epg-make-context)
+               (buffer-substring beg end))
+              (if no-decode 'raw-text wl-cs-autoconv))
+           (delete-region beg end)))
+  (message "Decrypting...done")
+  last-coding-system-used)
+
+(defun wl-mime-pgp-verify-region-with-epg (beg end &optional coding-system)
+  (require 'epa)
+  (let ((context (epg-make-context)))
+    (message "Verifying...")
+    (epg-verify-string
+     context
+     (encode-coding-string
+      (buffer-substring beg end)
+      (if coding-system
+         (coding-system-change-eol-conversion coding-system 'dos)
+       'raw-text-dos)))
+    (message "Verifying...done")
+    (when (epg-context-result-for context 'verify)
+      (epa-display-verify-result
+       (epg-context-result-for context 'verify)))))
+
+(defun wl-mime-pgp-decrypt-region-with-pgg (beg end &optional no-decode)
+  (require 'pgg)
+  (let ((buffer-file-coding-system wl-cs-autoconv)
+       status)
+    (setq status (pgg-decrypt-region beg end))
+    (if no-decode
+       (when status
+         (delete-region beg end)
+         (insert-buffer-substring pgg-output-buffer))
+      (pgg-display-output-buffer beg end status))
+    (unless status
+      (error "Decryption is failed"))
+    last-coding-system-used))
+
+(defun wl-mime-pgp-verify-region-with-pgg (beg end &optional coding-system)
+  (require 'pgg)
+  (let ((message-buffer (current-buffer))
+       success)
+    (with-temp-buffer
+      (insert-buffer-substring message-buffer beg end)
+      (when coding-system
+       (encode-coding-region (point-min) (point-max) coding-system))
+      (setq success (pgg-verify-region (point-min) (point-max) nil 'fetch)))
+    (mime-show-echo-buffer)
+    (set-buffer mime-echo-buffer-name)
+    (set-window-start
+     (get-buffer-window mime-echo-buffer-name)
+     (point-max))
+    (insert-buffer-substring
+     (if success
+        pgg-output-buffer
+       pgg-errors-buffer))))
+
+(defsubst wl-mime-pgp-decrypt-region (beg end &optional no-decode)
+  (case wl-use-pgp-module
+    (epg
+     (wl-mime-pgp-decrypt-region-with-epg beg end no-decode))
+    (pgg
+     (wl-mime-pgp-decrypt-region-with-pgg beg end no-decode))
+    (t
+     (error "Don't support PGP decryption"))))
+
+(defsubst wl-mime-pgp-verify-region (beg end &optional coding-system)
+  (case wl-use-pgp-module
+    (epg
+     (wl-mime-pgp-verify-region-with-epg beg end coding-system))
+    (pgg
+     (wl-mime-pgp-verify-region-with-pgg beg end coding-system))
+    (t
+     (error "Don't support PGP decryption"))))
 
 (defun wl-message-decrypt-pgp-nonmime ()
   "Decrypt PGP encrypted region"
index 479f744..3466d94 100644 (file)
@@ -2936,6 +2936,19 @@ a symbol `bitmap', `xbm' or `xpm' in order to force the image format."
   :type 'string
   :group 'wl-pref)
 
+(defcustom wl-use-pgp-module
+  (condition-case nil
+      (progn
+       (require 'epg-config)
+       (epg-check-configuration (epg-configuration))
+       'epg)
+    (error 'pgg))
+  "*Which PGG library to be used."
+  :type '(choice (const :tag "EasyPG Library" epg)
+                (const :tag "PGG Library" pgg)
+                (const :tag "Don't use PGP" nil))
+  :group 'wl-pref)
+
 ;;; Internal variables
 (defvar wl-init nil)