;;; auth-source.el --- authentication sources for Gnus and Emacs
-;; Copyright (C) 2008 Free Software Foundation, Inc.
+;; Copyright (C) 2008, 2009 Free Software Foundation, Inc.
;; Author: Ted Zlatanov <tzz@lifelogs.com>
;; Keywords: news
;; if you want encrypted sources, which is strongly recommended, do
;; (require 'epa-file)
-;; (epa-file-mode)
+;; (epa-file-enable)
;; (setq epa-file-cache-passphrase-for-symmetric-encryption t) ; VERY important
;; before you put some data in ~/.authinfo.gpg (the default place)
(interactive "slogin/password: \nsHost: \nsProtocol: \n") ;for testing
(remhash (format "%s %s:%s" mode host protocol) auth-source-cache))
+(defun auth-source-forget-all-cached ()
+ "Forget all cached auth-source authentication tokens."
+ (interactive)
+ (setq auth-source-cache (make-hash-table :test 'equal)))
+
(defun auth-source-user-or-password (mode host protocol)
- "Find user or password (from the string MODE) matching HOST and PROTOCOL."
+ "Find MODE (string or list of strings) matching HOST and PROTOCOL.
+MODE can be \"login\" or \"password\" for example."
(gnus-message 9
"auth-source-user-or-password: get %s for %s (%s)"
mode host protocol)
- (let* ((cname (format "%s %s:%s" mode host protocol))
+ (let* ((listy (listp mode))
+ (mode (if listy mode (list mode)))
+ (cname (format "%s %s:%s" mode host protocol))
(found (gethash cname auth-source-cache)))
(if found
(progn
"auth-source-user-or-password: cached %s=%s for %s (%s)"
mode
;; don't show the password
- (if (equal mode "password") "SECRET" found)
+ (if (member "password" mode) "SECRET" found)
host protocol)
found)
(dolist (choice (auth-source-pick host protocol))
"auth-source-user-or-password: found %s=%s for %s (%s)"
mode
;; don't show the password
- (if (equal mode "password") "SECRET" found)
+ (if (member "password" mode) "SECRET" found)
host protocol)
+ (setq found (if listy found (car-safe found)))
(when auth-source-do-cache
(puthash cname found auth-source-cache)))
(return found)))))