Mercurial > emacs
annotate lisp/net/netrc.el @ 111124:eed7831710a5
* src/xdisp.c (syms_of_xdisp) <display-hourglass>: Sync doc with Lisp.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Sat, 23 Oct 2010 14:16:39 -0700 |
parents | 3b9bd3888ee9 |
children | db63bc492d85 |
rev | line source |
---|---|
44810 | 1 ;;; netrc.el --- .netrc parsing functionality |
64701
34bd8e434dd7
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64085
diff
changeset
|
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, |
106815 | 3 ;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. |
44810 | 4 |
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org> | |
6 ;; Keywords: news | |
107390 | 7 ;; |
44810 | 8 ;; Modularized by Ted Zlatanov <tzz@lifelogs.com> |
9 ;; when it was part of Gnus. | |
10 | |
11 ;; This file is part of GNU Emacs. | |
12 | |
94677
91e5880a36c1
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
13 ;; GNU Emacs is free software: you can redistribute it and/or modify |
44810 | 14 ;; it under the terms of the GNU General Public License as published by |
94677
91e5880a36c1
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
15 ;; the Free Software Foundation, either version 3 of the License, or |
91e5880a36c1
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
16 ;; (at your option) any later version. |
44810 | 17 |
18 ;; GNU Emacs is distributed in the hope that it will be useful, | |
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
94677
91e5880a36c1
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
44810 | 21 ;; GNU General Public License for more details. |
22 | |
23 ;; You should have received a copy of the GNU General Public License | |
94677
91e5880a36c1
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
44810 | 25 |
26 ;;; Commentary: | |
27 | |
28 ;; Just the .netrc parsing functionality, abstracted so other packages | |
29 ;; besides Gnus can use it. | |
30 | |
31 ;;; Code: | |
32 | |
33 ;;; | |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
34 ;;; .netrc and .authinfo rc parsing |
44810 | 35 ;;; |
36 | |
37 (defalias 'netrc-point-at-eol | |
38 (if (fboundp 'point-at-eol) | |
39 'point-at-eol | |
40 'line-end-position)) | |
87454 | 41 (eval-when-compile |
42 ;; This is unnecessary in the compiled version as it is a macro. | |
43 (if (fboundp 'bound-and-true-p) | |
44 (defalias 'netrc-bound-and-true-p 'bound-and-true-p) | |
45 (defmacro netrc-bound-and-true-p (var) | |
46 "Return the value of symbol VAR if it is bound, else nil." | |
47 `(and (boundp (quote ,var)) ,var)))) | |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
48 |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
49 (defgroup netrc nil |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
50 "Netrc configuration." |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
51 :group 'comm) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
52 |
110306
838fb634d1b0
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110111
diff
changeset
|
53 (defcustom netrc-file "~/.authinfo" |
838fb634d1b0
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110111
diff
changeset
|
54 "File where user credentials are stored." |
838fb634d1b0
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110111
diff
changeset
|
55 :type 'file |
838fb634d1b0
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110111
diff
changeset
|
56 :group 'netrc) |
838fb634d1b0
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110111
diff
changeset
|
57 |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
58 (defvar netrc-services-file "/etc/services" |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
59 "The name of the services file.") |
44810 | 60 |
110306
838fb634d1b0
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110111
diff
changeset
|
61 (defun netrc-parse (&optional file) |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
62 (interactive "fFile to Parse: ") |
92694 | 63 "Parse FILE and return a list of all entries in the file." |
110306
838fb634d1b0
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110111
diff
changeset
|
64 (unless file |
838fb634d1b0
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110111
diff
changeset
|
65 (setq file netrc-file)) |
99506 | 66 (if (listp file) |
67 file | |
68 (when (file-exists-p file) | |
69 (with-temp-buffer | |
70 (let ((tokens '("machine" "default" "login" | |
71 "password" "account" "macdef" "force" | |
72 "port")) | |
73 alist elem result pair) | |
110489
b3141c4861e2
netrc.el (netrc-parse): Remove encrypt.el mentions.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110410
diff
changeset
|
74 (insert-file-contents file) |
99506 | 75 (goto-char (point-min)) |
76 ;; Go through the file, line by line. | |
44810 | 77 (while (not (eobp)) |
99506 | 78 (narrow-to-region (point) (point-at-eol)) |
79 ;; For each line, get the tokens and values. | |
80 (while (not (eobp)) | |
81 (skip-chars-forward "\t ") | |
82 ;; Skip lines that begin with a "#". | |
83 (if (eq (char-after) ?#) | |
84 (goto-char (point-max)) | |
85 (unless (eobp) | |
86 (setq elem | |
87 (if (= (following-char) ?\") | |
88 (read (current-buffer)) | |
89 (buffer-substring | |
90 (point) (progn (skip-chars-forward "^\t ") | |
91 (point))))) | |
92 (cond | |
93 ((equal elem "macdef") | |
94 ;; We skip past the macro definition. | |
95 (widen) | |
96 (while (and (zerop (forward-line 1)) | |
97 (looking-at "$"))) | |
98 (narrow-to-region (point) (point))) | |
99 ((member elem tokens) | |
100 ;; Tokens that don't have a following value are ignored, | |
101 ;; except "default". | |
102 (when (and pair (or (cdr pair) | |
103 (equal (car pair) "default"))) | |
104 (push pair alist)) | |
105 (setq pair (list elem))) | |
106 (t | |
107 ;; Values that haven't got a preceding token are ignored. | |
108 (when pair | |
109 (setcdr pair elem) | |
110 (push pair alist) | |
111 (setq pair nil))))))) | |
112 (when alist | |
113 (push (nreverse alist) result)) | |
114 (setq alist nil | |
115 pair nil) | |
116 (widen) | |
117 (forward-line 1)) | |
118 (nreverse result)))))) | |
44810 | 119 |
120 (defun netrc-machine (list machine &optional port defaultport) | |
121 "Return the netrc values from LIST for MACHINE or for the default entry. | |
122 If PORT specified, only return entries with matching port tokens. | |
123 Entries without port tokens default to DEFAULTPORT." | |
124 (let ((rest list) | |
125 result) | |
126 (while list | |
127 (when (equal (cdr (assoc "machine" (car list))) machine) | |
128 (push (car list) result)) | |
129 (pop list)) | |
130 (unless result | |
131 ;; No machine name matches, so we look for default entries. | |
132 (while rest | |
133 (when (assoc "default" (car rest)) | |
110666
3b9bd3888ee9
nnimap.el (nnimap-request-accept-article): Get the Message-ID without the \r.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110586
diff
changeset
|
134 (let ((elem (car rest))) |
3b9bd3888ee9
nnimap.el (nnimap-request-accept-article): Get the Message-ID without the \r.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110586
diff
changeset
|
135 (setq elem (delete (assoc "default" elem) elem)) |
3b9bd3888ee9
nnimap.el (nnimap-request-accept-article): Get the Message-ID without the \r.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110586
diff
changeset
|
136 (push elem result))) |
44810 | 137 (pop rest))) |
138 (when result | |
139 (setq result (nreverse result)) | |
110666
3b9bd3888ee9
nnimap.el (nnimap-request-accept-article): Get the Message-ID without the \r.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110586
diff
changeset
|
140 (if (not port) |
3b9bd3888ee9
nnimap.el (nnimap-request-accept-article): Get the Message-ID without the \r.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110586
diff
changeset
|
141 (car result) |
3b9bd3888ee9
nnimap.el (nnimap-request-accept-article): Get the Message-ID without the \r.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110586
diff
changeset
|
142 (while (and result |
3b9bd3888ee9
nnimap.el (nnimap-request-accept-article): Get the Message-ID without the \r.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110586
diff
changeset
|
143 (not (netrc-port-equal |
3b9bd3888ee9
nnimap.el (nnimap-request-accept-article): Get the Message-ID without the \r.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110586
diff
changeset
|
144 (or port defaultport "nntp") |
3b9bd3888ee9
nnimap.el (nnimap-request-accept-article): Get the Message-ID without the \r.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110586
diff
changeset
|
145 ;; when port is not given in the netrc file, |
3b9bd3888ee9
nnimap.el (nnimap-request-accept-article): Get the Message-ID without the \r.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110586
diff
changeset
|
146 ;; it should mean "any port" |
3b9bd3888ee9
nnimap.el (nnimap-request-accept-article): Get the Message-ID without the \r.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110586
diff
changeset
|
147 (or (netrc-get (car result) "port") |
3b9bd3888ee9
nnimap.el (nnimap-request-accept-article): Get the Message-ID without the \r.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110586
diff
changeset
|
148 defaultport port)))) |
3b9bd3888ee9
nnimap.el (nnimap-request-accept-article): Get the Message-ID without the \r.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110586
diff
changeset
|
149 (pop result)) |
3b9bd3888ee9
nnimap.el (nnimap-request-accept-article): Get the Message-ID without the \r.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110586
diff
changeset
|
150 (car result))))) |
44810 | 151 |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
152 (defun netrc-machine-user-or-password (mode authinfo-file-or-list machines ports defaults) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
153 "Get the user name or password according to MODE from AUTHINFO-FILE-OR-LIST. |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
154 Matches a machine from MACHINES and a port from PORTS, giving |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
155 default ports DEFAULTS to `netrc-machine'. |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
156 |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
157 MODE can be \"login\" or \"password\", suitable for passing to |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
158 `netrc-get'." |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
159 (let ((authinfo-list (if (stringp authinfo-file-or-list) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
160 (netrc-parse authinfo-file-or-list) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
161 authinfo-file-or-list)) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
162 (ports (or ports '(nil))) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
163 (defaults (or defaults '(nil))) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
164 info) |
101804 | 165 (if (listp mode) |
110111
5b9f64b04a04
Delete all trailing white space.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110102
diff
changeset
|
166 (setq info |
5b9f64b04a04
Delete all trailing white space.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110102
diff
changeset
|
167 (mapcar |
5b9f64b04a04
Delete all trailing white space.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110102
diff
changeset
|
168 (lambda (mode-element) |
101804 | 169 (netrc-machine-user-or-password |
170 mode-element | |
171 authinfo-list | |
172 machines | |
173 ports | |
174 defaults)) | |
175 mode)) | |
176 (dolist (machine machines) | |
177 (dolist (default defaults) | |
178 (dolist (port ports) | |
179 (let ((alist (netrc-machine authinfo-list machine port default))) | |
180 (setq info (or (netrc-get alist mode) info))))))) | |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
181 info)) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
182 |
44810 | 183 (defun netrc-get (alist type) |
184 "Return the value of token TYPE from ALIST." | |
185 (cdr (assoc type alist))) | |
186 | |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
187 (defun netrc-port-equal (port1 port2) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
188 (when (numberp port1) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
189 (setq port1 (or (netrc-find-service-name port1) port1))) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
190 (when (numberp port2) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
191 (setq port2 (or (netrc-find-service-name port2) port2))) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
192 (equal port1 port2)) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
193 |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
194 (defun netrc-parse-services () |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
195 (when (file-exists-p netrc-services-file) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
196 (let ((services nil)) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
197 (with-temp-buffer |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
198 (insert-file-contents netrc-services-file) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
199 (while (search-forward "#" nil t) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
200 (delete-region (1- (point)) (point-at-eol))) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
201 (goto-char (point-min)) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
202 (while (re-search-forward |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
203 "^ *\\([^ \n\t]+\\)[ \t]+\\([0-9]+\\)/\\([^ \t\n]+\\)" nil t) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
204 (push (list (match-string 1) (string-to-number (match-string 2)) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
205 (intern (downcase (match-string 3)))) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
206 services)) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
207 (nreverse services))))) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
208 |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
209 (defun netrc-find-service-name (number &optional type) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
210 (let ((services (netrc-parse-services)) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
211 service) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
212 (setq type (or type 'tcp)) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
213 (while (and (setq service (pop services)) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
214 (not (and (= number (cadr service)) |
86963
d549ccffa35b
(top-level): Don't load `encrypt' features.
Glenn Morris <rgm@gnu.org>
parents:
85712
diff
changeset
|
215 (eq type (car (cddr service))))))) |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
216 (car service))) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
217 |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
218 (defun netrc-find-service-number (name &optional type) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
219 (let ((services (netrc-parse-services)) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
220 service) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
221 (setq type (or type 'tcp)) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
222 (while (and (setq service (pop services)) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
223 (not (and (string= name (car service)) |
86963
d549ccffa35b
(top-level): Don't load `encrypt' features.
Glenn Morris <rgm@gnu.org>
parents:
85712
diff
changeset
|
224 (eq type (car (cddr service))))))) |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
225 (cadr service))) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78230
diff
changeset
|
226 |
110586
867180d035b0
auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110489
diff
changeset
|
227 (defun netrc-store-data (file host port user password) |
867180d035b0
auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110489
diff
changeset
|
228 (with-temp-buffer |
867180d035b0
auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110489
diff
changeset
|
229 (when (file-exists-p file) |
867180d035b0
auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110489
diff
changeset
|
230 (insert-file-contents file)) |
867180d035b0
auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110489
diff
changeset
|
231 (goto-char (point-max)) |
867180d035b0
auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110489
diff
changeset
|
232 (unless (bolp) |
867180d035b0
auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110489
diff
changeset
|
233 (insert "\n")) |
867180d035b0
auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110489
diff
changeset
|
234 (insert (format "machine %s login %s password %s port %s\n" |
867180d035b0
auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110489
diff
changeset
|
235 host user password port)) |
867180d035b0
auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110489
diff
changeset
|
236 (write-region (point-min) (point-max) file nil 'silent))) |
867180d035b0
auth-source.el (auth-source-create): Query the user for whether to store the credentials.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110489
diff
changeset
|
237 |
110410
f2e111723c3a
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110306
diff
changeset
|
238 ;;;###autoload |
110306
838fb634d1b0
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110111
diff
changeset
|
239 (defun netrc-credentials (machine &rest ports) |
838fb634d1b0
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110111
diff
changeset
|
240 "Return a user name/password pair. |
838fb634d1b0
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110111
diff
changeset
|
241 Port specifications will be prioritised in the order they are |
838fb634d1b0
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110111
diff
changeset
|
242 listed in the PORTS list." |
838fb634d1b0
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110111
diff
changeset
|
243 (let ((list (netrc-parse)) |
838fb634d1b0
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110111
diff
changeset
|
244 found) |
110666
3b9bd3888ee9
nnimap.el (nnimap-request-accept-article): Get the Message-ID without the \r.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110586
diff
changeset
|
245 (if (not ports) |
3b9bd3888ee9
nnimap.el (nnimap-request-accept-article): Get the Message-ID without the \r.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110586
diff
changeset
|
246 (setq found (netrc-machine list machine)) |
3b9bd3888ee9
nnimap.el (nnimap-request-accept-article): Get the Message-ID without the \r.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110586
diff
changeset
|
247 (while (and ports |
3b9bd3888ee9
nnimap.el (nnimap-request-accept-article): Get the Message-ID without the \r.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110586
diff
changeset
|
248 (not found)) |
3b9bd3888ee9
nnimap.el (nnimap-request-accept-article): Get the Message-ID without the \r.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110586
diff
changeset
|
249 (setq found (netrc-machine list machine (pop ports))))) |
110306
838fb634d1b0
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110111
diff
changeset
|
250 (when found |
838fb634d1b0
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110111
diff
changeset
|
251 (list (cdr (assoc "login" found)) |
838fb634d1b0
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110111
diff
changeset
|
252 (cdr (assoc "password" found)))))) |
838fb634d1b0
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110111
diff
changeset
|
253 |
44810 | 254 (provide 'netrc) |
255 | |
256 ;;; netrc.el ends here |