From 6c81c36028e041fff2eeaa877fc85e63557cb61d Mon Sep 17 00:00:00 2001 From: hmurata Date: Sat, 3 Jun 2006 10:15:34 +0000 Subject: [PATCH] * wl-util.el (wl-find-region): New function. * wl-mime.el (wl-mime-pgp-decrypt-region): Return the decoded coding system. (wl-message-decrypt-pgp-nonmime): Use wl-find-region. Put text property `wl-mime-decoded-coding-system'. (wl-message-verify-pgp-nonmime): Use wl-find-region. Use text property `wl-mime-decoded-coding-system' to encode text. --- wl/ChangeLog | 9 +++++++++ wl/wl-mime.el | 44 +++++++++++++++++++++++--------------------- wl/wl-util.el | 7 +++++++ 3 files changed, 39 insertions(+), 21 deletions(-) diff --git a/wl/ChangeLog b/wl/ChangeLog index 6512a9d..66c19eb 100644 --- a/wl/ChangeLog +++ b/wl/ChangeLog @@ -1,5 +1,14 @@ 2006-06-03 Hiroya Murata + * wl-util.el (wl-find-region): New function. + + * wl-mime.el (wl-mime-pgp-decrypt-region): Return the decoded + coding system. + (wl-message-decrypt-pgp-nonmime): Use wl-find-region. Put text + property `wl-mime-decoded-coding-system'. + (wl-message-verify-pgp-nonmime): Use wl-find-region. Use text + property `wl-mime-decoded-coding-system' to encode text. + * wl-mime.el (wl-mime-pgp-decrypt-region): Display a progress message. (wl-mime-pgp-verify-region): Ditto. diff --git a/wl/wl-mime.el b/wl/wl-mime.el index a991ba3..c708559 100644 --- a/wl/wl-mime.el +++ b/wl/wl-mime.el @@ -488,7 +488,8 @@ It calls following-method selected from variable (buffer-substring beg end)) (if no-decode 'raw-text wl-cs-autoconv)) (delete-region beg end))) - (message "Decrypting...done")) + (message "Decrypting...done") + last-coding-system-used) (defun wl-mime-pgp-verify-region (beg end &optional coding-system) (require 'epg) @@ -518,7 +519,8 @@ It calls following-method selected from variable (insert-buffer-substring pgg-output-buffer)) (pgg-display-output-buffer beg end status)) (unless status - (error "Decryption is failed")))) + (error "Decryption is failed")) + last-coding-system-used)) (defun wl-mime-pgp-verify-region (beg end &optional coding-system) (require 'pgg) @@ -550,15 +552,19 @@ It calls following-method selected from variable (interactive) (save-excursion (beginning-of-line) - (if (or (re-search-forward "^-+END PGP MESSAGE-+$" nil t) - (re-search-backward "^-+END PGP MESSAGE-+$" nil t)) - (let (beg end status) - (setq end (match-end 0)) - (if (setq beg (re-search-backward "^-+BEGIN PGP MESSAGE-+$" nil t)) - (let ((inhibit-read-only t)) - (wl-mime-pgp-decrypt-region beg end)) - (message "Cannot find pgp encrypted region"))) - (message "Cannot find pgp encrypted region")))) + (let ((region (wl-find-region "^-+BEGIN PGP MESSAGE-+$" + "^-+END PGP MESSAGE-+$")) + (inhibit-read-only t) + coding-system) + (unless region + (error "Cannot find pgp encrypted region")) + (save-restriction + (narrow-to-region (car region) (cdr region)) + (when (setq coding-system + (wl-mime-pgp-decrypt-region (point-min) (point-max))) + (put-text-property (point-min) (point-max) + 'wl-mime-decoded-coding-system + coding-system)))))) (defun wl-message-verify-pgp-nonmime (&optional arg) "Verify PGP signed region. @@ -566,16 +572,12 @@ With ARG, ask coding system and encode the region with it before verifying." (interactive "P") (save-excursion (beginning-of-line) - (let ((message-buffer (current-buffer)) - beg end coding-system success) - (setq end (and (or (re-search-forward "^-+END PGP SIGNATURE-+$" nil t) - (re-search-backward "^-+END PGP SIGNATURE-+$" nil t) - (error "Cannot find pgp signed region")) - (match-end 0))) - (setq beg (or (re-search-backward "^-+BEGIN PGP SIGNED MESSAGE-+$" nil t) - (error "Cannot find pgp signed region"))) + (let ((region (wl-find-region "^-+BEGIN PGP SIGNED MESSAGE-+$" + "^-+END PGP SIGNATURE-+$")) + coding-system) (setq coding-system - (or (let* ((situation (mime-preview-find-boundary-info)) + (or (get-text-property (car region) 'wl-mime-decoded-coding-system) + (let* ((situation (mime-preview-find-boundary-info)) (entity (aref situation 2))) (mime-charset-to-coding-system (mime-content-type-parameter @@ -586,7 +588,7 @@ With ARG, ask coding system and encode the region with it before verifying." (setq coding-system (read-coding-system (format "Coding system (%S): " coding-system) coding-system))) - (wl-mime-pgp-verify-region beg end coding-system)))) + (wl-mime-pgp-verify-region (car region) (cdr region) coding-system)))) ;; XXX: encrypted multipart isn't represented as multipart (defun wl-mime-preview-application/pgp (parent-entity entity situation) diff --git a/wl/wl-util.el b/wl/wl-util.el index 2f2ec54..61d296d 100644 --- a/wl/wl-util.el +++ b/wl/wl-util.el @@ -1121,6 +1121,13 @@ is enclosed by at least one regexp grouping construct." (t (throw 'done nil))))))) +(defun wl-find-region (beg-regexp end-regexp) + (if (or (re-search-forward end-regexp nil t) + (re-search-backward end-regexp nil t)) + (let ((end (match-end 0)) + (beg (re-search-backward beg-regexp nil t))) + (if beg + (cons beg end))))) ;; read multiple strings with completion (defun wl-completing-read-multiple-1 (prompt -- 1.7.10.4