Fix typo.
[gnus] / lisp / auth-source.el
index 64d244b..e5a2e31 100644 (file)
@@ -510,7 +510,7 @@ must call it to obtain the actual value."
                      unless (memq (nth i spec) ignored-keys)
                      collect (nth i spec)))
          (found (auth-source-recall spec))
-         filtered-backends accessor-key found-here goal matches)
+         filtered-backends accessor-key found-here goal matches backend)
 
     (if (and found auth-source-do-cache)
         (auth-source-do-debug
@@ -555,14 +555,15 @@ must call it to obtain the actual value."
       (when (and create
                 (not matches))
        (dolist (backend filtered-backends)
-         (let ((match (apply
-                       (slot-value backend 'search-function)
-                       :backend backend
-                       :create create
-                       :delete delete
-                       spec)))
-           (when match
-             (push (list backend match) matches)))))
+         (unless matches
+           (let ((match (apply
+                         (slot-value backend 'search-function)
+                         :backend backend
+                         :create create
+                         :delete delete
+                         spec)))
+             (when match
+               (push (list backend match) matches))))))
 
       (setq backend (caar matches)
            found-here (cadar matches))
@@ -689,6 +690,17 @@ while \(:host t) would find all host entries."
 
 ;;; Backend specific parsing: netrc/authinfo backend
 
+(defun auth-source-ensure-strings (values)
+  (unless (listp values)
+    (setq values (list values)))
+  (mapcar (lambda (value)
+           (if (numberp value)
+               (format "%s" value)
+             value))
+         values))
+
+(defvar auth-source-netrc-cache nil)
+
 ;;; (auth-source-netrc-parse "~/.authinfo.gpg")
 (defun* auth-source-netrc-parse (&rest
                                  spec
@@ -700,6 +712,7 @@ Note that the MAX parameter is used so we can exit the parse early."
       ;; We got already parsed contents; just return it.
       file
     (when (file-exists-p file)
+      (setq port (auth-source-ensure-strings port))
       (with-temp-buffer
         (let ((tokens '("machine" "host" "default" "login" "user"
                         "password" "account" "macdef" "force"
@@ -707,7 +720,19 @@ Note that the MAX parameter is used so we can exit the parse early."
               (max (or max 5000))       ; sanity check: default to stop at 5K
               (modified 0)
               alist elem result pair)
-          (insert-file-contents file)
+         (if (and auth-source-netrc-cache
+                  (equal (car auth-source-netrc-cache)
+                         (nth 5 (file-attributes file))))
+             (insert (base64-decode-string
+                      (rot13-string (cdr auth-source-netrc-cache))))
+           (insert-file-contents file)
+           (when (string-match "\\.gpg\\'" file)
+             ;; Store the contents of the file heavily encrypted in memory.
+             (setq auth-source-netrc-cache
+                   (cons (nth 5 (file-attributes file))
+                         (rot13-string
+                          (base64-encode-string
+                           (buffer-string)))))))
           (goto-char (point-min))
           ;; Go through the file, line by line.
           (while (and (not (eobp))