From 7edf58ba32a5c0ae637347b881fe0ef85544e757 Mon Sep 17 00:00:00 2001 From: ueno Date: Sun, 31 Dec 2006 08:45:38 +0000 Subject: [PATCH] * epa.el (epa--find-coding-system-for-mime-charset): New function. (epa-decrypt-armor-in-region): Use it. --- ChangeLog | 2 ++ epa.el | 25 +++++++++++++++++-------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index d42ea99..db6dd1d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,8 @@ (epa--mail-mode-p): New function. (epa-sign): Use it. (epa-encrypt): Use it. + (epa--find-coding-system-for-mime-charset): New function. + (epa-decrypt-armor-in-region): Use it. 2006-12-31 Daiki Ueno diff --git a/epa.el b/epa.el index 35b3582..ac10d7f 100644 --- a/epa.el +++ b/epa.el @@ -766,6 +766,17 @@ Don't use this command in Lisp programs!" (epa-display-info (epg-verify-result-to-string (epg-context-result-for context 'verify))))))) +(defun epa--find-coding-system-for-mime-charset (mime-charset) + (if (featurep 'xemacs) + (if (fboundp 'find-coding-system) + (find-coding-system mime-charset)) + (let ((pointer (coding-system-list))) + (while (and pointer + (eq (coding-system-get (car pointer) 'mime-charset) + mime-charset)) + (setq pointer (cdr pointer))) + pointer))) + ;;;###autoload (defun epa-decrypt-armor-in-region (start end) "Decrypt OpenPGP armors in the current region between START and END. @@ -776,7 +787,7 @@ Don't use this command in Lisp programs!" (save-restriction (narrow-to-region start end) (goto-char start) - (let (armor-start armor-end charset coding-system) + (let (armor-start armor-end coding-system) (while (re-search-forward "-----BEGIN PGP MESSAGE-----$" nil t) (setq armor-start (match-beginning 0) armor-end (re-search-forward "^-----END PGP MESSAGE-----$" @@ -785,13 +796,11 @@ Don't use this command in Lisp programs!" (error "No armor tail")) (goto-char armor-start) (if (re-search-forward "^Charset: \\(.*\\)" armor-end t) - (setq charset (match-string 1))) - (if coding-system-for-read - (setq coding-system coding-system-for-read) - (if charset - (setq coding-system (intern (downcase charset))) - (setq coding-system 'utf-8))) - (let ((coding-system-for-read coding-system)) + (setq coding-system (epa--find-coding-system-for-mime-charset + (intern (downcase (match-string 1)))))) + (let ((coding-system-for-read + (or coding-system-for-read + coding-system))) (epa-decrypt-region armor-start armor-end))))))) ;;;###autoload -- 1.7.10.4