[Mew-dist 3049] Re: Why I sometimes cannot decrypt PGP messages?

YAMAGUCHI, Shuhei yamagus at example.com
1997年 12月 2日 (火) 15:54:53 JST


やまぐち@ねっとらぴゅたの住人、です。

>>> In article <19971114222449-373Q.fuji0924 at example.com>,
>>>    OKUNISHI Fujikazu <fuji0924 at example.com> writes:

  fuji0924> ;; Mailcrypt 式のは言及されなかったので対象外なのではないでしょうか。
  fuji0924> ;; それこそ必要な人が書いて contribute されればいいような気がします。(^_^;

というわけで、いい加減ながらも、Mewからmailcryptを使えるようにするコー
ドを書いてみました。
#本当は、この話が出る少し前に作り始めていたのですが、Win32環境で上手
#くmailcryptが動かなかったのです。 ^^;

特にどの辺りがいい加減かといえば、
・mailcryptパッケージが必要。
・Mewのキャッシュを利用しない。
・自動でパスフレーズを聞いてくるなんてことはしない。
・MIME multipartは何も考えていない。
・coding-systemに自信なし。
でしょう。 ^^;

使い方は、
[mew-summary-mode]
 C-c / d --- decode
 C-c / v --- verify
[mew-draft-mode]
 C-c / e --- encrypt
 C-c / s --- sign
です。

なお、Mule for Win32で利用するには、Mule for Win32 MLに流れた、
別所さんによるmailcryptのパッチが必要です。
Message-ID: <199711251523.AAA19961 at example.com>
X-Seqno: 4957

また、Meadowで利用するには、別所さんのパッチを充てた後、
このメールに添付したパッチも充てる必要があります。

でわでわ
-- 
yamagus at example.com / 山口 修平
  yamagus at example.com / やまぐち@ねっとらぴゅたの住人
PGP-Fingerprint: 25 0F 6F E1 57 AD 56 08  3A BC D0 9B 48 AF 31 7A
(会社より)
-------------- next part --------------
;; mew-mailcrypt.el --- Mailcrypt for Mew

;; Author:  "YAMAGUCHI, Shuhei" <yamagus at example.com>
;; Created: Dec  1, 1997

;; To use mew-mailcrypt.el, install mailcrypt package,
;; and, put the following codes in your .emacs.
;;
;; (add-hook
;;  'mew-init-hook
;;  '(lambda () (require 'mew-mailcrypt)))

(defconst mew-mailcrypt-version "mew-mailcrypt.el v0.1")

(require 'mew)
(require 'mailcrypt)

(autoload 'mc-install-write-mode "mailcrypt" nil t)
(autoload 'mc-install-read-mode "mailcrypt" nil t)
(cond
 ((boundp 'MULE)
  (define-program-coding-system nil ".*pgp.*" (cons *autoconv* *junet*))
  (if (fboundp 'mule-for-win32-version)
      (setq mc-passwd-timeout nil)))
 ((string-match "^20" emacs-version)
  (setq process-coding-system-alist
	(cons '("^pgp" . iso-2022-7bit) process-coding-system-alist))))

(setq mc-modes-alist
      (append
       (list
	'(mew-draft-mode (encrypt . mc-mew-encrypt-message)
			 (sign . mc-mew-sign-message))
	'(mew-summary-mode (decrypt . mc-mew-decrypt-message)
			   (verify . mc-mew-verify-signature)
			   (snarf . mc-mew-snarf-keys))
	'(mew-virtual-mode (decrypt . mc-mew-decrypt-message)
			   (verify . mc-mew-verify-signature)
			   (snarf . mc-mew-snarf-keys)))
       mc-modes-alist))

(add-hook 'mew-draft-mode-hook
	  'mc-install-write-mode)
(add-hook 'mew-summary-mode-hook
	  'mc-install-read-mode)
(add-hook 'mew-virtual-mode-hook
	  'mc-install-read-mode)

(defun mc-mew-find-headers-end ()
  (save-excursion
    (goto-char (point-min))
    (re-search-forward
     (concat "^" (regexp-quote mew-header-separator) "\n"))
    (if (looking-at "^::\n")
	(re-search-forward "^\n" nil t))
    (if (looking-at "^##\n")
	(re-search-forward "^\n" nil t))
    (point-marker)))

(defun mc-mew-encrypt-message (&optional recipients scheme start end from sign)
  "*Encrypt a message for RECIPIENTS using the given encryption SCHEME.
RECIPIENTS is a comma separated string. If SCHEME is nil, use the value
of `mc-default-scheme'.  Returns t on success, nil otherwise."
  (save-excursion
    (let ((headers-end (mc-mew-find-headers-end))
	  default-recipients)

      (setq default-recipients
	    (save-restriction
	      (goto-char (point-min))
	      (re-search-forward
	       (concat "^" (regexp-quote mew-header-separator) "$"))
	      (narrow-to-region (point-min) (point))
	      (and (featurep 'mailalias)
		   (not (featurep 'mail-abbrevs))
		   mail-aliases
		   (expand-mail-aliases (point-min) (point-max)))
	      (mc-strip-addresses
	       (mapcar 'cdr
		       (mc-get-fields "to\\|cc\\|bcc")))))

      (if (not from)
	  (save-restriction
	    (goto-char (point-min))
	    (re-search-forward
	     (concat "^" (regexp-quote mew-header-separator) "\n"))
	    (narrow-to-region (point) headers-end)
	    (setq from (mail-fetch-field "From"))))

      (if (not recipients)
	  (setq recipients
		(if mc-use-default-recipients
		    default-recipients
		  (read-from-minibuffer "Recipients: " default-recipients))))
     
      (or start (setq start headers-end))
      (or end (setq end (point-max-marker)))

      (mc-encrypt-generic recipients scheme start end from sign))))

(defun mc-mew-sign-message (&optional withkey scheme start end unclearsig)
  "Clear sign the message."
  (save-excursion
    (let ((headers-end (mc-mew-find-headers-end)))
      (or withkey
	  (progn
	    (goto-char (point-min))
	    (re-search-forward
	     (concat "^" (regexp-quote mew-header-separator) "\n"))
	    (save-restriction
	      (narrow-to-region (point) headers-end)
	      (setq withkey (mail-fetch-field "From")))))
      (or start (setq start headers-end))
      (or end (setq end (point-max-marker)))
      (mc-sign-generic withkey scheme start end unclearsig))))

(defun mc-mew-decrypt-message ()
  "Decrypt the contents of the current Mew message in the message buffer."
  (interactive)
  (cond
   ((eobp) 
    (message "No message"))
   ((not (or (mew-summary-message-number) (mew-summary-part-number)))
    (message "No message"))
   (t
    (let (decrypt-okay)
      (mew-summary-display t)
      (save-excursion
	(set-buffer (mew-buffer-message))
	(toggle-read-only -1)
	(if (setq decrypt-okay (car (mc-decrypt-message)))
	    (progn
	      (goto-char (point-min))
	      (set-buffer-modified-p nil))
	  (message "Decryption failed.")))
      (if (not decrypt-okay)
	  (progn
	    (mew-summary-toggle-disp-msg 'off)
	    (mew-summary-display)))))))

(defun mc-mew-verify-signature ()
  "*Verify the signature in the current Mew message."
  (interactive)
  (cond
   ((eobp) 
    (message "No message"))
   ((not (or (mew-summary-message-number) (mew-summary-part-number)))
    (message "No message"))
   (t
    (mew-summary-display t)
    (save-excursion
      (set-buffer (mew-buffer-message))
      (mc-verify-signature)))))
    

(defun mc-mew-snarf-keys ()
  (interactive)
  (cond
   ((eobp) 
    (message "No message"))
   ((not (or (mew-summary-message-number) (mew-summary-part-number)))
    (message "No message"))
   (t
    (mew-summary-display t)
    (save-excursion
      (set-buffer (mew-buffer-message))
      (mc-snarf-keys)))))


(provide 'mew-mailcrypt)
-------------- next part --------------
--- mailcrypt.el~	Mon Dec 01 12:00:44 1997
+++ mailcrypt.el	Mon Dec 01 11:58:11 1997
@@ -56,10 +56,16 @@
 (defvar mc-kludge-program (expand-file-name "mckludge" exec-directory)
   "Program to redirect STDERR")
 
-(if (or (boundp 'MULE) (boundp 'NEMACS))
-    (define-program-coding-system nil ".*mckludge" (cons *autoconv* *junet*))
-  (set-coding-system-alist 'process mc-kludge-program
-			   (cons coding-category-iso-7 coding-category-iso-7)))
+(cond
+ ((or (boundp 'MULE) (boundp 'NEMACS))
+  (define-program-coding-system nil ".*mckludge" (cons *autoconv* *junet*)))
+ ((string-match "^20" emacs-version)
+  (setq process-coding-system-alist
+	(cons '("^mckludge" . iso-2022-7bit) process-coding-system-alist)))
+ (t
+  (set-coding-system-alist
+   'process mc-kludge-program
+   (cons coding-category-iso-7 coding-category-iso-7))))
 
 
 (autoload 'mc-decrypt "mc-toplev" nil t)


Mew-dist メーリングリストの案内