diff lisp/net/netrc.el @ 110306:838fb634d1b0

Merge changes made in Gnus trunk. gnus-sum.el: Avoid calling a hook function per summary line; Call `gnus-summary-highlight-line' directly from all places that used to call it indirectly. netrc.el (netrc-credentials): New conveniency function. gnus-start.el (gnus-read-active-file-1): If gnus-agent isn't set, then do request scans from the backends.
author Katsumi Yamaoka <yamaoka@jpl.org>
date Sat, 11 Sep 2010 00:36:27 +0000
parents 5b9f64b04a04
children f2e111723c3a
line wrap: on
line diff
--- a/lisp/net/netrc.el	Sat Sep 11 01:13:42 2010 +0200
+++ b/lisp/net/netrc.el	Sat Sep 11 00:36:27 2010 +0000
@@ -54,12 +54,19 @@
  "Netrc configuration."
  :group 'comm)
 
+(defcustom netrc-file "~/.authinfo"
+  "File where user credentials are stored."
+  :type 'file
+  :group 'netrc)
+
 (defvar netrc-services-file "/etc/services"
   "The name of the services file.")
 
-(defun netrc-parse (file)
+(defun netrc-parse (&optional file)
   (interactive "fFile to Parse: ")
   "Parse FILE and return a list of all entries in the file."
+  (unless file
+    (setq file netrc-file))
   (if (listp file)
       file
     (when (file-exists-p file)
@@ -221,6 +228,19 @@
 			  (eq type (car (cddr service)))))))
     (cadr service)))
 
+(defun netrc-credentials (machine &rest ports)
+  "Return a user name/password pair.
+Port specifications will be prioritised in the order they are
+listed in the PORTS list."
+  (let ((list (netrc-parse))
+	found)
+    (while (and ports
+		(not found))
+      (setq found (netrc-machine list machine (pop ports))))
+    (when found
+      (list (cdr (assoc "login" found))
+	    (cdr (assoc "password" found))))))
+
 (provide 'netrc)
 
 ;;; netrc.el ends here