aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Stallman2015-08-12 11:23:11 -0400
committerRichard Stallman2015-08-12 11:23:11 -0400
commitfe45243b6ae8129bea99f79acc55c77bfd0d1d22 (patch)
tree5f5bede728b996841f4701b1629106c86929c8f1
parent503058a1d6df415331167ec6ada3559da431bdf8 (diff)
downloademacs-fe45243b6ae8129bea99f79acc55c77bfd0d1d22.tar.gz
emacs-fe45243b6ae8129bea99f79acc55c77bfd0d1d22.zip
Handle encrypted mbox files.
* rmailout.el (rmail-output-as-mbox): Decrypt and reencrypt the mbox file if necessary.
-rw-r--r--lisp/mail/rmailout.el40
1 files changed, 38 insertions, 2 deletions
diff --git a/lisp/mail/rmailout.el b/lisp/mail/rmailout.el
index a00c66c8ed8..6b753b39e17 100644
--- a/lisp/mail/rmailout.el
+++ b/lisp/mail/rmailout.el
@@ -345,6 +345,7 @@ the text directly to FILE-NAME, and displays a \"Wrote file\" message
345unless NOMSG is a symbol (neither nil nor t). 345unless NOMSG is a symbol (neither nil nor t).
346AS-SEEN is non-nil if we are copying the message \"as seen\"." 346AS-SEEN is non-nil if we are copying the message \"as seen\"."
347 (let ((case-fold-search t) 347 (let ((case-fold-search t)
348 encrypted-file-name
348 from date) 349 from date)
349 (goto-char (point-min)) 350 (goto-char (point-min))
350 ;; Preserve the Mail-From and MIME-Version fields 351 ;; Preserve the Mail-From and MIME-Version fields
@@ -364,10 +365,45 @@ AS-SEEN is non-nil if we are copying the message \"as seen\"."
364 (goto-char (point-min)) 365 (goto-char (point-min))
365 (let ((buf (find-buffer-visiting file-name)) 366 (let ((buf (find-buffer-visiting file-name))
366 (tembuf (current-buffer))) 367 (tembuf (current-buffer)))
368 (when (string-match "[.]gpg\\'" file-name)
369 (setq encrypted-file-name file-name
370 file-name (substring file-name 0 (match-beginning 0))))
367 (if (null buf) 371 (if (null buf)
368 (let ((coding-system-for-write 'raw-text-unix)) 372 (let ((coding-system-for-write 'raw-text-unix)
373 (coding-system-for-read 'raw-text-unix))
374 ;; If the specified file is encrypted, decrypt it.
375 (when encrypted-file-name
376 (with-temp-buffer
377 (insert-file-contents encrypted-file-name)
378 (write-region 1 (point-max) file-name nil 'nomsg)))
369 ;; FIXME should ensure existing file ends with a blank line. 379 ;; FIXME should ensure existing file ends with a blank line.
370 (write-region (point-min) (point-max) file-name t nomsg)) 380 (write-region (point-min) (point-max) file-name t
381 (if (or nomsg encrypted-file-name)
382 'nomsg))
383 ;; If the specified file was encrypted, re-encrypt it.
384 (when encrypted-file-name
385 ;; Save the old encrypted file as a backup.
386 (rename-file encrypted-file-name
387 (make-backup-file-name encrypted-file-name)
388 t)
389 (if (= 0
390 (call-process "gpg" nil nil
391 "--use-agent" "--batch" "--no-tty"
392 "--encrypt" "-r"
393 user-mail-address
394 file-name))
395 ;; Delete the unencrypted file if encryption succeeded.
396 (delete-file file-name)
397 ;; If encrypting failed, put back the original
398 ;; encrypted file and signal an error.
399 (rename-file (make-backup-file-name encrypted-file-name)
400 encrypted-file-name
401 t)
402 (error "Encryption failed; %s unchanged"
403 encrypted-file-name))
404 (unless nomsg
405 (message "Added to %s" encrypted-file-name)))
406 )
371 (if (eq buf (current-buffer)) 407 (if (eq buf (current-buffer))
372 (error "Can't output message to same file it's already in")) 408 (error "Can't output message to same file it's already in"))
373 ;; File has been visited, in buffer BUF. 409 ;; File has been visited, in buffer BUF.