+;;; netrc.el --- .netrc parsing functionality
+;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002
+;; Free Software Foundation, Inc.
+;; Author: Lars Magne Ingebrigtsen <email@example.com>
+;; Modularized by Ted Zlatanov <firstname.lastname@example.org>
+;; when it was part of Gnus.
+;; This file is part of XEmacs.
+;; XEmacs is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; XEmacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+;; You should have received a copy of the GNU General Public License
+;; along with XEmacs; see the file COPYING. If not, write to the
+;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
+;; Just the .netrc parsing functionality, abstracted so other packages
+;; besides Gnus can use it.
+;;; .netrc and .authinforc parsing
+ (if (fboundp 'point-at-eol)
+(defun netrc-parse (file)
+ "Parse FILE and return an list of all entries in the file."
+ (when (file-exists-p file)
+ (let ((tokens '("machine" "default" "login"
+ "password" "account" "macdef" "force"
+ alist elem result pair)
+ (insert-file-contents file)
+ (goto-char (point-min))
+ ;; Go through the file, line by line.
+ (narrow-to-region (point) (netrc-point-at-eol))
+ ;; For each line, get the tokens and values.
+ (skip-chars-forward "\t ")
+ ;; Skip lines that begin with a "#".
+ (if (eq (char-after) ?#)
+ (goto-char (point-max))
+ (if (= (following-char) ?\")
+ (read (current-buffer))
+ (point) (progn (skip-chars-forward "^\t ")
+ ;; We skip past the macro definition.
+ (while (and (zerop (forward-line 1))
+ (narrow-to-region (point) (point)))
+ ;; Tokens that don't have a following value are ignored,
+ (when (and pair (or (cdr pair)
+ (equal (car pair) "default")))
+ (setq pair (list elem)))
+ ;; Values that haven't got a preceding token are ignored.
+ (push (nreverse alist) result))
+(defun netrc-machine (list machine &optional port defaultport)
+ "Return the netrc values from LIST for MACHINE or for the default entry.
+If PORT specified, only return entries with matching port tokens.
+Entries without port tokens default to DEFAULTPORT."
+ (when (equal (cdr (assoc "machine" (car list))) machine)
+ (push (car list) result))
+ ;; No machine name matches, so we look for default entries.
+ (when (assoc "default" (car rest))
+ (push (car rest) result))
+ (setq result (nreverse result))
+ (not (equal (or port defaultport "nntp")
+ (or (netrc-get (car result) "port")
+(defun netrc-get (alist type)
+ "Return the value of token TYPE from ALIST."
+ (cdr (assoc type alist)))