summaryrefslogtreecommitdiff
path: root/lisp/gnus/auth-source.el
diff options
context:
space:
mode:
authorMiles Bader <miles@gnu.org>2008-04-21 07:13:33 +0000
committerMiles Bader <miles@gnu.org>2008-04-21 07:13:33 +0000
commitd55fe5bb3eb98fc19dbab064b5adfbe3a16a6c1b (patch)
tree8c0226d557585842b73cbe2d49f3c511dace6576 /lisp/gnus/auth-source.el
parentd48c50ae86ec3b5bd6d40fbdb1357a56cb347b9a (diff)
downloademacs-d55fe5bb3eb98fc19dbab064b5adfbe3a16a6c1b.tar.gz
Merge from gnus--devo--0
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-1118
Diffstat (limited to 'lisp/gnus/auth-source.el')
-rw-r--r--lisp/gnus/auth-source.el62
1 files changed, 42 insertions, 20 deletions
diff --git a/lisp/gnus/auth-source.el b/lisp/gnus/auth-source.el
index f37e0368845..9883eb64acc 100644
--- a/lisp/gnus/auth-source.el
+++ b/lisp/gnus/auth-source.el
@@ -28,6 +28,19 @@
;; authenticate in a single place. Simplicity is the goal. Instead
;; of providing 5000 options, we'll stick to simple, easy to
;; understand options.
+
+;; Easy setup:
+;; (require 'auth-source)
+;; (customize-variable 'auth-sources) ;; optional
+
+;; now, whatever sources you've defined for password have to be available
+
+;; if you want encrypted sources, which is strongly recommended, do
+;; (require 'epa-file)
+;; (epa-file-mode)
+
+;; before you put some data in ~/.authinfo.gpg (the default place)
+
;;; Code:
(eval-when-compile (require 'cl))
@@ -73,10 +86,15 @@ Each entry is the authentication type with optional properties."
(list :tag "Source definition"
(const :format "" :value :source)
(string :tag "Authentication Source")
+ (const :format "" :value :server)
+ (choice :tag "Server (logical name) choice"
+ (const :tag "Any" t)
+ (regexp :tag "Server regular expression (TODO)")
+ (const :tag "Fallback" nil))
(const :format "" :value :host)
- (choice :tag "Host choice"
+ (choice :tag "Host (machine) choice"
(const :tag "Any" t)
- (regexp :tag "Host regular expression (TODO)")
+ (regexp :tag "Host (machine) regular expression (TODO)")
(const :tag "Fallback" nil))
(const :format "" :value :protocol)
(choice :tag "Protocol"
@@ -100,16 +118,20 @@ Each entry is the authentication type with optional properties."
;; (auth-source-user-or-password-imap "password" "imap.myhost.com")
;; (auth-source-protocol-defaults 'imap)
-(defun auth-source-pick (host protocol &optional fallback)
- "Parse `auth-sources' for HOST and PROTOCOL matches.
+(defun auth-source-pick (server host protocol &optional fallback)
+ "Parse `auth-sources' for SERVER, HOST, and PROTOCOL matches.
-Returns fallback choices (where PROTOCOL or HOST are nil) with FALLBACK t."
+Returns fallback choices (where SERVER. PROTOCOL or HOST are nil) with FALLBACK t."
(interactive "sHost: \nsProtocol: \n") ;for testing
(let (choices)
(dolist (choice auth-sources)
- (let ((h (plist-get choice :host))
+ (let ((s (plist-get choice :server))
+ (h (plist-get choice :host))
(p (plist-get choice :protocol)))
(when (and
+ (or (equal t s)
+ (and (stringp s) (string-match s server))
+ (and fallback (equal s nil)))
(or (equal t h)
(and (stringp h) (string-match h host))
(and fallback (equal h nil)))
@@ -120,12 +142,12 @@ Returns fallback choices (where PROTOCOL or HOST are nil) with FALLBACK t."
(if choices
choices
(unless fallback
- (auth-source-pick host protocol t)))))
+ (auth-source-pick server host protocol t)))))
-(defun auth-source-user-or-password (mode host protocol)
- "Find user or password (from the string MODE) matching HOST and PROTOCOL."
+(defun auth-source-user-or-password (mode server host protocol)
+ "Find user or password (from the string MODE) matching SERVER, HOST, and PROTOCOL."
(let (found)
- (dolist (choice (auth-source-pick host protocol))
+ (dolist (choice (auth-source-pick server host protocol))
(setq found (netrc-machine-user-or-password
mode
(plist-get choice :source)
@@ -139,20 +161,20 @@ Returns fallback choices (where PROTOCOL or HOST are nil) with FALLBACK t."
"Return a list of default ports and names for PROTOCOL."
(cdr-safe (assoc protocol auth-source-protocols)))
-(defun auth-source-user-or-password-imap (mode host)
- (auth-source-user-or-password mode host 'imap))
+(defun auth-source-user-or-password-imap (mode server host)
+ (auth-source-user-or-password mode server host 'imap))
-(defun auth-source-user-or-password-pop3 (mode host)
- (auth-source-user-or-password mode host 'pop3))
+(defun auth-source-user-or-password-pop3 (mode server host)
+ (auth-source-user-or-password mode server host 'pop3))
-(defun auth-source-user-or-password-ssh (mode host)
- (auth-source-user-or-password mode host 'ssh))
+(defun auth-source-user-or-password-ssh (mode server host)
+ (auth-source-user-or-password mode server host 'ssh))
-(defun auth-source-user-or-password-sftp (mode host)
- (auth-source-user-or-password mode host 'sftp))
+(defun auth-source-user-or-password-sftp (mode server host)
+ (auth-source-user-or-password mode server host 'sftp))
-(defun auth-source-user-or-password-smtp (mode host)
- (auth-source-user-or-password mode host 'smtp))
+(defun auth-source-user-or-password-smtp (mode server host)
+ (auth-source-user-or-password mode server host 'smtp))
(provide 'auth-source)