(netrc-credentials): New conveniency function.
authorLars Magne Ingebrigtsen <larsi@quimbies.gnus.org>
Fri, 10 Sep 2010 22:55:44 +0000 (00:55 +0200)
committerLars Magne Ingebrigtsen <larsi@quimbies.gnus.org>
Fri, 10 Sep 2010 22:55:44 +0000 (00:55 +0200)
lisp/ChangeLog
lisp/netrc.el

index 6ff20b6..156c051 100644 (file)
@@ -1,5 +1,7 @@
 2010-09-10  Lars Magne Ingebrigtsen  <larsi@gnus.org>
 
+       * netrc.el (netrc-credentials): New conveniency function.
+
        * gnus-sum.el (gnus-summary-update-hook): Change default to nil, to
        avoid running a hook per line, since this takes a lot of time,
        profiling shows.
index 2306927..408eca9 100644 (file)
  "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 @@ MODE can be \"login\" or \"password\", suitable for passing to
                          (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