Add missing version on gnus-group-update-hook
[gnus] / lisp / netrc.el
index e526242..2644659 100644 (file)
@@ -1,9 +1,10 @@
 ;;; netrc.el --- .netrc parsing functionality
 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
-;;   2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;;   2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
 
 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
 ;; Keywords: news
+;;
 ;;  Modularized by Ted Zlatanov <tzz@lifelogs.com>
 ;;  when it was part of Gnus.
 
 ;;; .netrc and .authinfo rc parsing
 ;;;
 
-;; use encrypt if loaded (encrypt-file-alist has to be set as well)
-(autoload 'encrypt-find-model "encrypt")
-(autoload 'encrypt-insert-file-contents "encrypt")
 (defalias 'netrc-point-at-eol
   (if (fboundp 'point-at-eol)
       'point-at-eol
     'line-end-position))
-(defvar encrypt-file-alist)
 (eval-when-compile
   ;; This is unnecessary in the compiled version as it is a macro.
   (if (fboundp 'bound-and-true-p)
  "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)
        (let ((tokens '("machine" "default" "login"
                        "password" "account" "macdef" "force"
                        "port"))
-             (encryption-model (when (netrc-bound-and-true-p encrypt-file-alist)
-                                 (encrypt-find-model file)))
              alist elem result pair)
-         (if encryption-model
-             (encrypt-insert-file-contents file encryption-model)
-           (insert-file-contents file))
+          (insert-file-contents file)
          (goto-char (point-min))
          ;; Go through the file, line by line.
          (while (not (eobp))
@@ -158,11 +158,22 @@ MODE can be \"login\" or \"password\", suitable for passing to
        (ports (or ports '(nil)))
        (defaults (or defaults '(nil)))
        info)
-    (dolist (machine machines)
-      (dolist (default defaults)
-       (dolist (port ports)
-         (let ((alist (netrc-machine authinfo-list machine port default)))
-           (setq info (or (netrc-get alist mode) info))))))
+    (if (listp mode)
+       (setq info
+             (mapcar
+              (lambda (mode-element)
+                (netrc-machine-user-or-password
+                 mode-element
+                 authinfo-list
+                 machines
+                 ports
+                 defaults))
+              mode))
+      (dolist (machine machines)
+       (dolist (default defaults)
+         (dolist (port ports)
+           (let ((alist (netrc-machine authinfo-list machine port default)))
+             (setq info (or (netrc-get alist mode) info)))))))
     info))
 
 (defun netrc-get (alist type)
@@ -209,7 +220,20 @@ MODE can be \"login\" or \"password\", suitable for passing to
                          (eq type (car (cddr service)))))))
     (cadr service)))
 
+;;;###autoload
+(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)
 
-;; arch-tag: af9929cc-2d12-482f-936e-eb4366f9fa55
 ;;; netrc.el ends here