diff options
| author | Richard M. Stallman | 2011-08-15 22:29:15 -0400 |
|---|---|---|
| committer | Richard M. Stallman | 2011-08-15 22:29:15 -0400 |
| commit | 177549d04c917ea9f3de23041b60d3c22a07279b (patch) | |
| tree | 7084e270d1c40aac3e4509e7342e2e26aa1f5165 | |
| parent | 44fede4d8e691afda7fdd35777793e1408fecca1 (diff) | |
| download | emacs-177549d04c917ea9f3de23041b60d3c22a07279b.tar.gz emacs-177549d04c917ea9f3de23041b60d3c22a07279b.zip | |
Add rmail-epa-decrypt command.
| -rw-r--r-- | etc/NEWS | 5 | ||||
| -rw-r--r-- | lisp/ChangeLog | 2 | ||||
| -rw-r--r-- | lisp/mail/rmail.el | 106 |
3 files changed, 112 insertions, 1 deletions
| @@ -820,6 +820,11 @@ on a D-Bus without simultaneously registering a property or a method. | |||
| 820 | *** The option `ange-ftp-binary-file-name-regexp' has changed its | 820 | *** The option `ange-ftp-binary-file-name-regexp' has changed its |
| 821 | default value to "". | 821 | default value to "". |
| 822 | 822 | ||
| 823 | ** Rmail | ||
| 824 | |||
| 825 | *** The command `rmail-epa-decrypt' decrypts OpenPGP data | ||
| 826 | in the Rmail incoming message. | ||
| 827 | |||
| 823 | ** VC and related modes | 828 | ** VC and related modes |
| 824 | 829 | ||
| 825 | *** Support for pulling on distributed version control systems. | 830 | *** Support for pulling on distributed version control systems. |
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 400500998c3..cfa948c6bec 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,7 @@ | |||
| 1 | 2011-08-16 Richard Stallman <rms@gnu.org> | 1 | 2011-08-16 Richard Stallman <rms@gnu.org> |
| 2 | 2 | ||
| 3 | * mail/rmail.el (rmail-epa-decrypt): New command. | ||
| 4 | |||
| 3 | * epa.el (epa-decrypt-region): New arg MAKE-BUFFER-FUNCTION. | 5 | * epa.el (epa-decrypt-region): New arg MAKE-BUFFER-FUNCTION. |
| 4 | Don't bind buffer-read-only, just inhibit-read-only. | 6 | Don't bind buffer-read-only, just inhibit-read-only. |
| 5 | (epa--find-coding-system-for-mime-charset): Fix the non-xemacs case. | 7 | (epa--find-coding-system-for-mime-charset): Fix the non-xemacs case. |
diff --git a/lisp/mail/rmail.el b/lisp/mail/rmail.el index c43ec9e5611..9b4bbf91823 100644 --- a/lisp/mail/rmail.el +++ b/lisp/mail/rmail.el | |||
| @@ -4249,7 +4249,7 @@ TEXT and INDENT are not used." | |||
| 4249 | ;; rmail-output expands non-absolute filenames against rmail-default-file. | 4249 | ;; rmail-output expands non-absolute filenames against rmail-default-file. |
| 4250 | ;; What is the point of that, anyway? | 4250 | ;; What is the point of that, anyway? |
| 4251 | (rmail-output (expand-file-name token)))) | 4251 | (rmail-output (expand-file-name token)))) |
| 4252 | 4252 | ||
| 4253 | ;; Functions for setting, getting and encoding the POP password. | 4253 | ;; Functions for setting, getting and encoding the POP password. |
| 4254 | ;; The password is encoded to prevent it from being easily accessible | 4254 | ;; The password is encoded to prevent it from being easily accessible |
| 4255 | ;; to "prying eyes." Obviously, this encoding isn't "real security," | 4255 | ;; to "prying eyes." Obviously, this encoding isn't "real security," |
| @@ -4300,6 +4300,110 @@ encoded string (and the same mask) will decode the string." | |||
| 4300 | (setq i (1+ i))) | 4300 | (setq i (1+ i))) |
| 4301 | (concat string-vector))) | 4301 | (concat string-vector))) |
| 4302 | 4302 | ||
| 4303 | (defun rmail-epa-decrypt () | ||
| 4304 | "Decrypt OpenPGP armors in current message." | ||
| 4305 | (interactive) | ||
| 4306 | |||
| 4307 | ;; Save the current buffer here for cleanliness, in case we | ||
| 4308 | ;; change it in one of the calls to `epa-decrypt-region'. | ||
| 4309 | |||
| 4310 | (save-excursion | ||
| 4311 | (let (new-buffer not-first-armor) | ||
| 4312 | (goto-char (point-min)) | ||
| 4313 | |||
| 4314 | ;; In case the encrypted data is inside a mime attachment, | ||
| 4315 | ;; show it. This is a kludge; to be clean, it should not | ||
| 4316 | ;; modify the buffer, but I don't see how to do that. | ||
| 4317 | (when (search-forward "octet-stream" nil t) | ||
| 4318 | (beginning-of-line) | ||
| 4319 | (forward-button 1) | ||
| 4320 | (if (looking-at "Show") | ||
| 4321 | (rmail-mime-toggle-hidden))) | ||
| 4322 | |||
| 4323 | ;; Now find all armored messages in the buffer | ||
| 4324 | ;; and decrypt them one by one. | ||
| 4325 | (goto-char (point-min)) | ||
| 4326 | (while (re-search-forward "-----BEGIN PGP MESSAGE-----$" nil t) | ||
| 4327 | (let (armor-start armor-end | ||
| 4328 | (coding-system-for-read coding-system-for-read)) | ||
| 4329 | (setq armor-start (match-beginning 0) | ||
| 4330 | armor-end (re-search-forward "^-----END PGP MESSAGE-----$" | ||
| 4331 | nil t)) | ||
| 4332 | (unless armor-end | ||
| 4333 | (error "Encryption armor beginning has no matching end")) | ||
| 4334 | (goto-char armor-start) | ||
| 4335 | |||
| 4336 | ;; Because epa--find-coding-system-for-mime-charset not autoloaded. | ||
| 4337 | (require 'epa) | ||
| 4338 | |||
| 4339 | ;; Use the charset specified in the armor. | ||
| 4340 | (unless coding-system-for-read | ||
| 4341 | (if (re-search-forward "^Charset: \\(.*\\)" armor-end t) | ||
| 4342 | (setq coding-system-for-read | ||
| 4343 | (epa--find-coding-system-for-mime-charset | ||
| 4344 | (intern (downcase (match-string 1))))))) | ||
| 4345 | |||
| 4346 | ;; Advance over this armor. | ||
| 4347 | (goto-char armor-end) | ||
| 4348 | |||
| 4349 | ;; Decrypt it, maybe in place, maybe making new buffer. | ||
| 4350 | (epa-decrypt-region | ||
| 4351 | armor-start armor-end | ||
| 4352 | ;; Call back this function to prepare the output. | ||
| 4353 | (lambda () | ||
| 4354 | (if (or not-first-armor | ||
| 4355 | (y-or-n-p "Replace the original message? ")) | ||
| 4356 | ;; User wants to decrypt in place, | ||
| 4357 | ;; or this isn't the first armor. | ||
| 4358 | ;; We only ask the question for the first armor. | ||
| 4359 | (let ((inhibit-read-only t)) | ||
| 4360 | (delete-region armor-start armor-end) | ||
| 4361 | (goto-char armor-start) | ||
| 4362 | (current-buffer)) | ||
| 4363 | ;; User says not to replace the original text. | ||
| 4364 | (or new-buffer | ||
| 4365 | (let ((from-buffer | ||
| 4366 | (if (rmail-buffers-swapped-p) | ||
| 4367 | rmail-view-buffer rmail-buffer)) | ||
| 4368 | (from-pruned (rmail-msg-is-pruned)) | ||
| 4369 | (beg (rmail-msgbeg rmail-current-message)) | ||
| 4370 | (end (rmail-msgend rmail-current-message))) | ||
| 4371 | (with-current-buffer (generate-new-buffer "*Decrypt*") | ||
| 4372 | (setq buffer-read-only nil) | ||
| 4373 | (insert-buffer-substring from-buffer beg end) | ||
| 4374 | (rmail-mode) | ||
| 4375 | ;; This should be pruned if the original message was. | ||
| 4376 | (unless from-pruned (rmail-toggle-header)) | ||
| 4377 | (goto-char (point-min)) | ||
| 4378 | |||
| 4379 | ;; Find the first armor in the text we just copied. | ||
| 4380 | ;; What we copied may not be identical | ||
| 4381 | ;; to the initial text. | ||
| 4382 | (re-search-forward "-----BEGIN PGP MESSAGE-----$") | ||
| 4383 | (setq armor-start (match-beginning 0)) | ||
| 4384 | (re-search-forward "^-----END PGP MESSAGE-----$") | ||
| 4385 | (setq armor-end (point)) | ||
| 4386 | ;; Delete it and put point there. | ||
| 4387 | (let ((inhibit-read-only t)) | ||
| 4388 | (delete-region armor-start armor-end)) | ||
| 4389 | (goto-char armor-start) | ||
| 4390 | (setq new-buffer (current-buffer)) | ||
| 4391 | ;; Return; epa-decrypt-region will insert plaintext. | ||
| 4392 | )))))) | ||
| 4393 | |||
| 4394 | (setq not-first-armor t) | ||
| 4395 | |||
| 4396 | ;; If we copied the buffer, switch to the copy | ||
| 4397 | ;; for the rest of this loop. | ||
| 4398 | ;; Point is the only buffer pointer that is live here, | ||
| 4399 | ;; and it was properly set in NEW-BUFFER by `epa-decrypt-region' | ||
| 4400 | ;; when it inserted the decrypted epa | ||
| 4401 | (if new-buffer (set-buffer new-buffer)))) | ||
| 4402 | |||
| 4403 | ;; If we decrypted into a new buffer, show it. | ||
| 4404 | (if new-buffer | ||
| 4405 | (display-buffer new-buffer))))) | ||
| 4406 | |||
| 4303 | ;;;; Desktop support | 4407 | ;;;; Desktop support |
| 4304 | 4408 | ||
| 4305 | (defun rmail-restore-desktop-buffer (desktop-buffer-file-name | 4409 | (defun rmail-restore-desktop-buffer (desktop-buffer-file-name |