((require 'epg nil t)
(defun wl-mime-pgp-decrypt-region (beg end &optional no-decode)
(require 'epg)
- (let ((plain (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)
- (insert plain)))
+ (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 ((message-buffer (current-buffer))
- (context (epg-make-context)))
+ (let ((context (epg-make-context)))
+ (message "Verifying...")
(epg-verify-string
context
- (with-temp-buffer
- (insert-buffer-substring message-buffer beg end)
- (when coding-system
- (encode-coding-region (point-min) (point-max) coding-system))
- (goto-char (point-min))
- (while (search-forward "\n" nil t)
- (replace-match "\r\n"))
- (buffer-substring (point-min) (point-max))))
- (message "%s"
- (epg-verify-result-to-string
- (epg-context-result-for context 'verify))))))
+ (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)
(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)
(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
+ (let ((props (text-properties-at (car region))))
+ (narrow-to-region (car region) (cdr region))
+ (when (setq coding-system
+ (wl-mime-pgp-decrypt-region (point-min) (point-max)))
+ (setq props (plist-put props
+ 'wl-mime-decoded-coding-system
+ coding-system)))
+ (set-text-properties (point-min) (point-max) props))))))
(defun wl-message-verify-pgp-nonmime (&optional arg)
"Verify PGP signed region.
(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
(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)