+ (if (not port)
+ (car result)
+ (while (and result
+ (not (netrc-port-equal
+ (or port defaultport "nntp")
+ ;; when port is not given in the netrc file,
+ ;; it should mean "any port"
+ (or (netrc-get (car result) "port")
+ defaultport port))))
+ (pop result))
+ (car result)))))
+
+(defun netrc-machine-user-or-password (mode authinfo-file-or-list machines ports defaults)
+ "Get the user name or password according to MODE from AUTHINFO-FILE-OR-LIST.
+Matches a machine from MACHINES and a port from PORTS, giving
+default ports DEFAULTS to `netrc-machine'.
+
+MODE can be \"login\" or \"password\", suitable for passing to
+`netrc-get'."
+ (let ((authinfo-list (if (stringp authinfo-file-or-list)
+ (netrc-parse authinfo-file-or-list)
+ authinfo-file-or-list))
+ (ports (or ports '(nil)))
+ (defaults (or defaults '(nil)))
+ 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))