]> code.delx.au - gnu-emacs/blobdiff - lisp/mail/rmailout.el
Update docs for `customize-mode'
[gnu-emacs] / lisp / mail / rmailout.el
index 63cc26360b7fdc11ad144d1d8eafecf52a67502d..67859361fe225633bfab62a47d7bd49007c1d88d 100644 (file)
@@ -1,9 +1,9 @@
 ;;; rmailout.el --- "RMAIL" mail reader for Emacs: output message to a file
 
-;; Copyright (C) 1985, 1987, 1993-1994, 2001-2012
-;;   Free Software Foundation, Inc.
+;; Copyright (C) 1985, 1987, 1993-1994, 2001-2016 Free Software
+;; Foundation, Inc.
 
-;; Maintainer: FSF
+;; Maintainer: emacs-devel@gnu.org
 ;; Keywords: mail
 ;; Package: rmail
 
@@ -84,10 +84,14 @@ This uses `rmail-output-file-alist'."
                                        (eval (cdar tail))
                                      (error
                                       (display-warning
-                                       :error
-                                       (format "Error evaluating \
-`rmail-output-file-alist' element:\nregexp: %s\naction: %s\nerror: %S\n"
-                                               (caar tail) (cdar tail) err))
+                                       'rmail-output
+                                       (format-message "\
+Error evaluating `rmail-output-file-alist' element:
+regexp: %s
+action: %s
+error: %S\n"
+                                               (caar tail) (cdar tail) err)
+                                        :error)
                                       nil))))
                          (setq tail (cdr tail)))
                        answer))))))
@@ -345,6 +349,7 @@ the text directly to FILE-NAME, and displays a \"Wrote file\" message
 unless NOMSG is a symbol (neither nil nor t).
 AS-SEEN is non-nil if we are copying the message \"as seen\"."
   (let ((case-fold-search t)
+        encrypted-file-name
        from date)
     (goto-char (point-min))
     ;; Preserve the Mail-From and MIME-Version fields
@@ -364,10 +369,45 @@ AS-SEEN is non-nil if we are copying the message \"as seen\"."
     (goto-char (point-min))
     (let ((buf (find-buffer-visiting file-name))
          (tembuf (current-buffer)))
+      (when (string-match "[.]gpg\\'" file-name)
+        (setq encrypted-file-name file-name
+              file-name (substring file-name 0 (match-beginning 0))))
       (if (null buf)
-         (let ((coding-system-for-write 'raw-text-unix))
+         (let ((coding-system-for-write 'raw-text-unix)
+                (coding-system-for-read 'raw-text-unix))
+            ;; If the specified file is encrypted, decrypt it.
+            (when encrypted-file-name
+              (with-temp-buffer
+                (insert-file-contents encrypted-file-name)
+                (write-region 1 (point-max) file-name nil 'nomsg)))
            ;; FIXME should ensure existing file ends with a blank line.
-           (write-region (point-min) (point-max) file-name t nomsg))
+           (write-region (point-min) (point-max) file-name t
+                          (if (or nomsg encrypted-file-name)
+                              'nomsg))
+            ;; If the specified file was encrypted, re-encrypt it.
+            (when encrypted-file-name
+              ;; Save the old encrypted file as a backup.
+              (rename-file encrypted-file-name
+                           (make-backup-file-name encrypted-file-name)
+                           t)
+              (if (= 0
+                     (call-process "gpg" nil nil
+                                   "--use-agent" "--batch" "--no-tty"
+                                   "--encrypt" "-r"
+                                   user-mail-address
+                                   file-name))
+                  ;; Delete the unencrypted file if encryption succeeded.
+                  (delete-file file-name)
+                ;; If encrypting failed, put back the original
+                ;; encrypted file and signal an error.
+                (rename-file (make-backup-file-name encrypted-file-name)
+                             encrypted-file-name
+                             t)
+                (error "Encryption failed; %s unchanged"
+                       encrypted-file-name))
+              (unless nomsg
+                (message "Added to %s" encrypted-file-name)))
+            )
        (if (eq buf (current-buffer))
            (error "Can't output message to same file it's already in"))
        ;; File has been visited, in buffer BUF.