(require 'mime-view)
(require 'signature)
(require 'alist)
+(require 'epa)
-(defvar mime-edit-pgp-use
- (condition-case nil
- (progn
- (require 'epg-config)
- (epg-check-configuration (epg-configuration))
- (autoload 'epg-make-context "epg")
- 'epg)
- (error
- (require 'pgg-def)
- (require 'pgg-parse)
- (autoload 'pgg-encrypt-region "pgg"
- "PGP encryption of current region." t)
- (autoload 'pgg-sign-region "pgg"
- "PGP signature of current region." t)
- (autoload 'pgg-insert-key "pgg"
- "Insert PGP public key at point." t)
- 'pgg))
- "Which PGG library to be used in MIME-Edit.")
;;; @ version
;;;
") "
(if (fboundp 'apel-version)
(concat (apel-version) " "))
- (if (eq mime-edit-pgp-use 'epg)
- (concat "EasyPG/" epg-version-number " "))
+ "EasyPG/" epg-version-number " "
(if (featurep 'xemacs)
(concat (cond ((and (featurep 'chise)
(boundp 'xemacs-chise-version))
(cond ((string-equal type "quote")
(mime-edit-enquote-region bb eb))
((string-equal type "pgp-signed")
- (if (eq mime-edit-pgp-use 'epg)
- (mime-edit-sign-pgp-mime-with-epg bb eb boundary)
- (mime-edit-sign-pgp-mime-with-pgg bb eb boundary)))
+ (mime-edit-sign-pgp-mime bb eb boundary))
((string-equal type "pgp-encrypted")
- (if (eq mime-edit-pgp-use 'epg)
- (mime-edit-encrypt-pgp-mime-with-epg bb eb boundary)
- (mime-edit-encrypt-pgp-mime-with-pgg bb eb boundary)))
+ (mime-edit-encrypt-pgp-mime bb eb boundary))
((string-equal type "kazu-signed")
- (if (eq mime-edit-pgp-use 'epg)
- (mime-edit-sign-pgp-kazu-with-epg bb eb boundary)
- (mime-edit-sign-pgp-kazu-with-pgg bb eb boundary)))
+ (mime-edit-sign-pgp-kazu bb eb boundary))
((string-equal type "kazu-encrypted")
- (if (eq mime-edit-pgp-use 'epg)
- (mime-edit-encrypt-pgp-kazu-with-epg bb eb boundary)
- (mime-edit-encrypt-pgp-kazu-with-pgg bb eb boundary)))
+ (mime-edit-encrypt-pgp-kazu bb eb boundary))
((string-equal type "smime-signed")
(mime-edit-sign-smime bb eb boundary))
((string-equal type "smime-encrypted")
(while (re-search-forward "[ \t]+$" nil t)
(delete-region (match-beginning 0) (match-end 0))))))
-(defun mime-edit-sign-pgp-mime-with-epg (beg end boundary)
+(defun mime-edit-sign-pgp-mime (beg end boundary)
(save-excursion
(save-restriction
(let* ((from (std11-field-body "From" mail-header-separator))
(goto-char (point-max))
(insert (format "\n--%s--\n" pgp-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))
- (ret (progn
- (narrow-to-region beg end)
- (mime-edit-translate-region beg end boundary)))
- (ctype (car ret))
- (encoding (nth 1 ret))
- (pgp-boundary (concat "pgp-sign-" boundary))
- micalg)
- (mime-edit-delete-trailing-whitespace) ; RFC3156
- (goto-char beg)
- (insert (format "Content-Type: %s\n" ctype))
- (if encoding
- (insert (format "Content-Transfer-Encoding: %s\n" encoding)))
- (insert "\n")
- (or (let ((pgg-default-user-id
- (or mime-edit-pgp-user-id
- (if from
- (nth 1 (std11-extract-address-components from))
- pgg-default-user-id))))
- (pgg-sign-region (point-min)(point-max)))
- (throw 'mime-edit-error 'pgp-error))
- (setq micalg
- (cdr (assq 'hash-algorithm
- (cdar (with-current-buffer pgg-output-buffer
- (pgg-parse-armor-region
- (point-min)(point-max))))))
- micalg
- (if micalg
- (concat "; micalg=pgp-" (downcase (symbol-name micalg)))
- ""))
- (goto-char beg)
- (insert (format "--[[multipart/signed;
- boundary=\"%s\"%s;
- protocol=\"application/pgp-signature\"][7bit]]
---%s
-" pgp-boundary micalg pgp-boundary))
- (goto-char (point-max))
- (insert (format "\n--%s
-Content-Type: application/pgp-signature
-Content-Transfer-Encoding: 7bit
-
-" pgp-boundary))
- (insert-buffer-substring pgg-output-buffer)
- (goto-char (point-max))
- (insert (format "\n--%s--\n" pgp-boundary))))))
-
(defvar mime-edit-encrypt-recipient-fields-list '("To" "cc"))
(defun mime-edit-make-encrypt-recipient-header ()
values (cdr values)))
(vector from recipients header)))
-(defun mime-edit-encrypt-pgp-mime-with-epg (beg end boundary)
+(defun mime-edit-encrypt-pgp-mime (beg end boundary)
(save-excursion
(save-restriction
(let (recipients header)
(goto-char (point-max))
(insert (format "\n--%s--\n" pgp-boundary)))))))
-(defun mime-edit-encrypt-pgp-mime-with-pgg (beg end boundary)
- (save-excursion
- (save-restriction
- (let (from recipients header)
- (let ((ret (mime-edit-make-encrypt-recipient-header)))
- (setq from (aref ret 0)
- recipients (aref ret 1)
- header (aref ret 2)))
- (narrow-to-region beg end)
- (let* ((ret
- (mime-edit-translate-region beg end boundary))
- (ctype (car ret))
- (encoding (nth 1 ret))
- (pgp-boundary (concat "pgp-" boundary)))
- (goto-char beg)
- (insert header)
- (insert (format "Content-Type: %s\n" ctype))
- (if encoding
- (insert (format "Content-Transfer-Encoding: %s\n" encoding)))
- (insert "\n")
- (mime-encode-header-in-buffer)
- (or (let ((pgg-default-user-id
- (or mime-edit-pgp-user-id
- (if from
- (nth 1 (std11-extract-address-components from))
- pgg-default-user-id))))
- (pgg-encrypt-region
- (point-min) (point-max)
- (mapcar (lambda (recipient)
- (nth 1 (std11-extract-address-components
- recipient)))
- (split-string recipients
- "\\([ \t\n]*,[ \t\n]*\\)+"))))
- (throw 'mime-edit-error 'pgp-error))
- (delete-region (point-min)(point-max))
- (goto-char beg)
- (insert (format "--[[multipart/encrypted;
- boundary=\"%s\";
- protocol=\"application/pgp-encrypted\"][7bit]]
---%s
-Content-Type: application/pgp-encrypted
-
---%s
-Content-Type: application/octet-stream
-Content-Transfer-Encoding: 7bit
-
-" pgp-boundary pgp-boundary pgp-boundary))
- (insert-buffer-substring pgg-output-buffer)
- (goto-char (point-max))
- (insert (format "\n--%s--\n" pgp-boundary)))))))
-
-(defun mime-edit-sign-pgp-kazu-with-epg (beg end boundary)
+(defun mime-edit-sign-pgp-kazu (beg end boundary)
(save-excursion
(save-restriction
(narrow-to-region beg end)
"--[[application/pgp; format=mime][7bit]]\n" signature)
))))
-(defun mime-edit-sign-pgp-kazu-with-pgg (beg end boundary)
- (save-excursion
- (save-restriction
- (narrow-to-region beg end)
- (let* ((ret
- (mime-edit-translate-region beg end boundary))
- (ctype (car ret))
- (encoding (nth 1 ret)))
- (goto-char beg)
- (insert (format "Content-Type: %s\n" ctype))
- (if encoding
- (insert (format "Content-Transfer-Encoding: %s\n" encoding)))
- (insert "\n")
- (or (pgg-sign-region beg (point-max) 'clearsign)
- (throw 'mime-edit-error 'pgp-error))
- (goto-char beg)
- (insert
- "--[[application/pgp; format=mime][7bit]]\n")
- ))))
-
-(defun mime-edit-encrypt-pgp-kazu-with-epg (beg end boundary)
+(defun mime-edit-encrypt-pgp-kazu (beg end boundary)
(save-excursion
(let (recipients header)
(let ((ret (mime-edit-make-encrypt-recipient-header)))
"--[[application/pgp; format=mime][7bit]]\n" cipher)
)))))
-(defun mime-edit-encrypt-pgp-kazu-with-pgg (beg end boundary)
- (save-excursion
- (let (recipients header)
- (let ((ret (mime-edit-make-encrypt-recipient-header)))
- (setq recipients (aref ret 1)
- header (aref ret 2)))
- (save-restriction
- (narrow-to-region beg end)
- (let* ((ret
- (mime-edit-translate-region beg end boundary))
- (ctype (car ret))
- (encoding (nth 1 ret)))
- (goto-char beg)
- (insert header)
- (insert (format "Content-Type: %s\n" ctype))
- (if encoding
- (insert (format "Content-Transfer-Encoding: %s\n" encoding)))
- (insert "\n")
- (or (pgg-encrypt-region beg (point-max) recipients)
- (throw 'mime-edit-error 'pgp-error))
- (goto-char beg)
- (insert
- "--[[application/pgp; format=mime][7bit]]\n")
- )))))
-
(defun mime-edit-convert-lbt-string (string)
(let ((index 0))
(while (setq index (string-match "\n" string index))
;;; Code:
(require 'mime-play)
-
-(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.")
+(require 'epg)
+(require 'epa)
;;; @ Internal method for multipart/signed
;;;
;;;
;;; It is based on draft-kazu-pgp-mime-00.txt (PGP-kazu).
-(defun mime-view-application/pgp-with-epg (entity situation)
+(defun mime-view-application/pgp (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))))
- (if (eq mime-pgp-use 'epg)
- (mime-view-application/pgp-with-epg orig-entity situation)
- (mime-view-application/pgp-with-pgg orig-entity situation))))
+ (mime-view-application/pgp 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
;;;