* gnus-art.el (gnus-header-from, gnus-header-subject, gnus-header-name)
[gnus] / lisp / encrypt.el
index 0e14ca9..493c730 100644 (file)
@@ -19,8 +19,8 @@
 
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;;; Commentary:
 
 ;;; grouping declarations and documentation relating to each
 ;;; particular aspect.
 
+;;; Use in Gnus like this:
+;;; (setq
+;;;   nnimap-authinfo-file "~/.authinfo.enc"
+;;;   nntp-authinfo-file "~/.authinfo.enc"
+;;;   smtpmail-auth-credentials "~/.authinfo.enc"
+;;;   ;; using the AES256 cipher, feel free to use your own favorite
+;;;   encrypt-file-alist (quote (("~/.authinfo.enc" (gpg "AES256"))))
+;;;   password-cache-expiry 600)
+
+;;; Then write ~/.authinfo.enc:
+
+;;; 1) open the old authinfo
+;;; C-x C-f ~/.authinfo
+
+;;; 2) write the new authinfo.enc
+;;; M-x encrypt-file-contents ~/.authinfo.enc
+
+;;; 3) verify the new authinfo is correct (this will show the contents in the minibuffer)
+;;; M-: (encrypt-get-file-contents "~/.authinfo.enc")
+
+
 ;;; Code:
 
 ;; autoload password
@@ -36,7 +57,8 @@
 
 (defgroup encrypt '((password-cache custom-variable)
                    (password-cache-expiry custom-variable))
-  "File encryption configuration.")
+  "File encryption configuration."
+  :group 'applications)
 
 (defcustom encrypt-file-alist nil
   "List of file names or regexes matched with encryptions.
@@ -107,8 +129,8 @@ Format example:
                               (symbol-name method) cipher file))
         (passphrase
          (password-read-and-add
-          (format "%s password for cipher %s? "
-                  (symbol-name method) cipher)
+          (format "%s password for cipher %s (file %s)? "
+                  file (symbol-name method) cipher)
           password-key))
          (buffer-file-coding-system 'binary)
         (coding-system-for-read 'binary)
@@ -125,8 +147,8 @@ Format example:
 
     (if outdata
        (progn
-         (gnus-message 9 "%s was decrypted with %s (cipher %s)"
-                       file (symbol-name method) cipher)
+         (message "%s was decrypted with %s (cipher %s)"
+                  file (symbol-name method) cipher)
          (delete-region (point-min) (point-max))
          (goto-char (point-min))
          (insert outdata))
@@ -150,38 +172,40 @@ Format example:
 
 (defun encrypt-write-file-contents (file &optional model)
   "Encrypt the current buffer to FILE, then continue normally."
-  (interactive "fFile to write: ")
-  (let* ((model (or model (encrypt-find-model file)))
-        (method (nth 0 model))
-        (cipher (nth 1 model))
-        (password-key (format "encrypt-password-%s-%s %s"
-                              (symbol-name method) cipher file))
-        (passphrase
-         (password-read
-          (format "%s password for cipher %s? "
-                  (symbol-name method) cipher)
-          password-key))
-        outdata)
-
-    (cond
-     ((eq method 'gpg)
-      (setq outdata (encrypt-gpg-encode-buffer passphrase cipher)))
-     ((eq method 'encrypt-xor)
-      (setq outdata (encrypt-xor-encode-buffer passphrase cipher))))
-
-    (if outdata
-       (progn
-         (gnus-message 9 "%s was encrypted with %s (cipher %s)"
-                       file (symbol-name method) cipher)
-         (delete-region (point-min) (point-max))
-         (goto-char (point-min))
-         (insert outdata)
-         ;; do not confirm overwrites
-         (write-file file nil))
-      ;; the decryption failed, alas
-      (password-cache-remove password-key)
-      (gnus-error 5 "%s was NOT encrypted with %s (cipher %s)"
-                 file (symbol-name method) cipher))))
+  (interactive "sFile to write: ")
+  (setq model (or model (encrypt-find-model file)))
+  (if model
+      (let* ((method (nth 0 model))
+            (cipher (nth 1 model))
+            (password-key (format "encrypt-password-%s-%s %s"
+                                  (symbol-name method) cipher file))
+            (passphrase
+             (password-read
+              (format "%s password for cipher %s? "
+                      (symbol-name method) cipher)
+              password-key))
+            outdata)
+
+       (cond
+        ((eq method 'gpg)
+         (setq outdata (encrypt-gpg-encode-buffer passphrase cipher)))
+        ((eq method 'encrypt-xor)
+         (setq outdata (encrypt-xor-encode-buffer passphrase cipher))))
+
+       (if outdata
+           (progn
+             (message "%s was encrypted with %s (cipher %s)"
+                      file (symbol-name method) cipher)
+             (delete-region (point-min) (point-max))
+             (goto-char (point-min))
+             (insert outdata)
+             ;; do not confirm overwrites
+             (write-file file nil))
+         ;; the decryption failed, alas
+         (password-cache-remove password-key)
+         (gnus-error 5 "%s was NOT encrypted with %s (cipher %s)"
+                     file (symbol-name method) cipher)))
+    (gnus-error 1 "%s has no associated encryption model!  See encrypt-file-alist." file)))
 
 (defun encrypt-xor-encode-buffer (passphrase cipher)
   (encrypt-xor-process-buffer passphrase cipher t))
@@ -212,7 +236,7 @@ Format example:
        (progn
          (setq new-list (reverse (split-string bs)))
          (dolist (x new-list)
-           (setq x (string-to-int x))
+           (setq x (string-to-number x))
            (insert (format "%c" (logxor x passphrase-sum))))))
       (buffer-substring-no-properties (point-min) (point-max)))))