Mercurial > emacs
annotate lisp/mail/mailalias.el @ 110563:5b5c2cab9a6a
Merge changes made in Gnus.tranck
gnus-art.el: Remove useless gnus-treat-translate.
gnus-gravatar.el (gnus-gravatar-transform-address): Use gnus-gravatar-size.
gnus.el: Remove useless gnus-local-domain.
mml-smime.el: Remove useless mml-smime-verbose.
mml2015.el: Remove useless mml2015-verbose.
author | Katsumi Yamaoka <yamaoka@jpl.org> |
---|---|
date | Sat, 25 Sep 2010 12:49:02 +0000 |
parents | 1d1d5d9bd884 |
children | 4db798bcd48b 376148b31b5e |
rev | line source |
---|---|
14551
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
1 ;;; mailalias.el --- expand and complete mailing address aliases |
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
474
diff
changeset
|
2 |
74509 | 3 ;; Copyright (C) 1985, 1987, 1995, 1996, 1997, 2001, 2002, 2003, |
106815 | 4 ;; 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
811
diff
changeset
|
5 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
6 ;; Maintainer: FSF |
811
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
807
diff
changeset
|
7 ;; Keywords: mail |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
8 |
53 | 9 ;; This file is part of GNU Emacs. |
10 | |
94674
ef65fa4dca3b
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
11 ;; GNU Emacs is free software: you can redistribute it and/or modify |
53 | 12 ;; it under the terms of the GNU General Public License as published by |
94674
ef65fa4dca3b
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
13 ;; the Free Software Foundation, either version 3 of the License, or |
ef65fa4dca3b
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
14 ;; (at your option) any later version. |
53 | 15 |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
94674
ef65fa4dca3b
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
53 | 23 |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1448
diff
changeset
|
24 ;;; Commentary: |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1448
diff
changeset
|
25 |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1448
diff
changeset
|
26 ;; Basic functions for defining and expanding mail aliases. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1448
diff
changeset
|
27 ;; These seal off the interface to the alias-definition parts of a |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1448
diff
changeset
|
28 ;; .mailrc file formatted for BSD's Mail or USL's mailx. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1448
diff
changeset
|
29 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
30 ;;; Code: |
53 | 31 |
8801
eee06aef6f56
Require sendmail. Delete redundant defvar.
Karl Heuer <kwzh@gnu.org>
parents:
8494
diff
changeset
|
32 (require 'sendmail) |
1448
99fb20ef1a17
(mail-aliases): Add definition here.
Richard M. Stallman <rms@gnu.org>
parents:
1434
diff
changeset
|
33 |
18161 | 34 (defgroup mailalias nil |
64036
f76eec5e4eee
(mailalias): Finish `defgroup' description with period.
Juanma Barranquero <lekktu@gmail.com>
parents:
62620
diff
changeset
|
35 "Expanding mail aliases." |
18161 | 36 :group 'mail) |
37 | |
38 (defcustom mail-passwd-files '("/etc/passwd") | |
102561
352aa67bded9
Remove leading `*' from defcustom docs.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
39 "List of files from which to determine valid user names." |
18161 | 40 :type '(repeat string) |
41 :group 'mailalias) | |
42 | |
43 (defcustom mail-passwd-command nil | |
102561
352aa67bded9
Remove leading `*' from defcustom docs.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
44 "Shell command to retrieve text to add to `/etc/passwd', or nil." |
18161 | 45 :type '(choice string (const nil)) |
46 :group 'mailalias) | |
47 | |
48 (defvar mail-directory-names t | |
49 "Alist of mail address directory entries. | |
50 When t this still needs to be initialized.") | |
51 | |
52 (defvar mail-address-field-regexp | |
53 "^\\(Resent-\\)?\\(To\\|From\\|CC\\|BCC\\|Reply-to\\):") | |
54 | |
55 (defcustom mail-complete-alist | |
18607
a7dd2801b909
(mail-complete-alist): Don't use backquote.
Richard M. Stallman <rms@gnu.org>
parents:
18168
diff
changeset
|
56 ;; Don't use backquote here; we don't want backquote to get loaded |
a7dd2801b909
(mail-complete-alist): Don't use backquote.
Richard M. Stallman <rms@gnu.org>
parents:
18168
diff
changeset
|
57 ;; just because of loading this file. |
21752
122b15805e79
(mail-complete-alist): Don't refer to mail-address-field-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
20810
diff
changeset
|
58 ;; Don't refer to mail-address-field-regexp here; |
122b15805e79
(mail-complete-alist): Don't refer to mail-address-field-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
20810
diff
changeset
|
59 ;; that confuses some things such as cus-dep.el. |
122b15805e79
(mail-complete-alist): Don't refer to mail-address-field-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
20810
diff
changeset
|
60 (cons '("^\\(Resent-\\)?\\(To\\|From\\|CC\\|BCC\\|Reply-to\\):" |
122b15805e79
(mail-complete-alist): Don't refer to mail-address-field-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
20810
diff
changeset
|
61 . (mail-get-names pattern)) |
18607
a7dd2801b909
(mail-complete-alist): Don't use backquote.
Richard M. Stallman <rms@gnu.org>
parents:
18168
diff
changeset
|
62 '(("Newsgroups:" . (if (boundp 'gnus-active-hashtb) |
a7dd2801b909
(mail-complete-alist): Don't use backquote.
Richard M. Stallman <rms@gnu.org>
parents:
18168
diff
changeset
|
63 gnus-active-hashtb |
a7dd2801b909
(mail-complete-alist): Don't use backquote.
Richard M. Stallman <rms@gnu.org>
parents:
18168
diff
changeset
|
64 (if (boundp news-group-article-assoc) |
a7dd2801b909
(mail-complete-alist): Don't use backquote.
Richard M. Stallman <rms@gnu.org>
parents:
18168
diff
changeset
|
65 news-group-article-assoc))) |
a7dd2801b909
(mail-complete-alist): Don't use backquote.
Richard M. Stallman <rms@gnu.org>
parents:
18168
diff
changeset
|
66 ("Followup-To:" . (mail-sentto-newsgroups)) |
a7dd2801b909
(mail-complete-alist): Don't use backquote.
Richard M. Stallman <rms@gnu.org>
parents:
18168
diff
changeset
|
67 ;;("Distribution:" ???) |
a7dd2801b909
(mail-complete-alist): Don't use backquote.
Richard M. Stallman <rms@gnu.org>
parents:
18168
diff
changeset
|
68 )) |
102561
352aa67bded9
Remove leading `*' from defcustom docs.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
69 "Alist of header field and expression to return alist for completion. |
18161 | 70 The expression may reference the variable `pattern' |
71 which will hold the string being completed. | |
72 If not on matching header, `mail-complete-function' gets called instead." | |
24172
0e451bef1fe0
(mail-complete-alist): Use alist as customize
Andreas Schwab <schwab@suse.de>
parents:
23356
diff
changeset
|
73 :type 'alist |
18161 | 74 :group 'mailalias) |
75 (put 'mail-complete-alist 'risky-local-variable t) | |
76 | |
77 ;;;###autoload | |
78 (defcustom mail-complete-style 'angles | |
102561
352aa67bded9
Remove leading `*' from defcustom docs.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
79 "Specifies how \\[mail-complete] formats the full name when it completes. |
18161 | 80 If `nil', they contain just the return address like: |
81 king@grassland.com | |
82 If `parens', they look like: | |
83 king@grassland.com (Elvis Parsley) | |
84 If `angles', they look like: | |
85 Elvis Parsley <king@grassland.com>" | |
86 :type '(choice (const angles) (const parens) (const nil)) | |
87 :group 'mailalias) | |
88 | |
89 (defcustom mail-complete-function 'ispell-complete-word | |
102561
352aa67bded9
Remove leading `*' from defcustom docs.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
90 "Function to call when completing outside `mail-complete-alist'-header." |
18161 | 91 :type '(choice function (const nil)) |
92 :group 'mailalias) | |
93 | |
94 (defcustom mail-directory-function nil | |
102561
352aa67bded9
Remove leading `*' from defcustom docs.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
95 "Function to get completions from directory service or nil for none. |
18161 | 96 See `mail-directory-requery'." |
97 :type '(choice function (const nil)) | |
98 :group 'mailalias) | |
99 | |
100 ;; This is for when the directory is huge, or changes frequently. | |
101 (defcustom mail-directory-requery nil | |
102561
352aa67bded9
Remove leading `*' from defcustom docs.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
102 "When non-nil call `mail-directory-function' for each completion. |
18161 | 103 In that case, one argument gets passed to the function, the partial string |
104 entered so far." | |
105 :type 'boolean | |
106 :group 'mailalias) | |
107 | |
108 (defcustom mail-directory-process nil | |
102561
352aa67bded9
Remove leading `*' from defcustom docs.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
109 "Shell command to get the list of names from a mail directory. |
18161 | 110 This value is used when the value of `mail-directory-function' |
111 is `mail-directory-process'. The value should be a list | |
112 of the form (COMMAND ARG ...), where each of the list elements | |
60964
0b933f58d514
(mail-directory-process): Do nothing if mail-directory-process is an atom.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
113 is evaluated. COMMAND should evaluate to a string. When |
0b933f58d514
(mail-directory-process): Do nothing if mail-directory-process is an atom.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
114 `mail-directory-requery' is non-nil, during evaluation of these |
0b933f58d514
(mail-directory-process): Do nothing if mail-directory-process is an atom.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
115 elements, the variable `pattern' contains the partial input being |
0b933f58d514
(mail-directory-process): Do nothing if mail-directory-process is an atom.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
116 completed. `pattern' is nil when `mail-directory-requery' is nil. |
18161 | 117 |
118 The value might look like this: | |
119 | |
120 '(remote-shell-program \"HOST\" \"-nl\" \"USER\" \"COMMAND\") | |
121 | |
122 or like this: | |
123 | |
124 '(remote-shell-program \"HOST\" \"-n\" \"COMMAND '^\" pattern \"'\")" | |
125 :type 'sexp | |
126 :group 'mailalias) | |
127 (put 'mail-directory-process 'risky-local-variable t) | |
128 | |
129 (defcustom mail-directory-stream nil | |
102561
352aa67bded9
Remove leading `*' from defcustom docs.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
130 "List of (HOST SERVICE) for stream connection to mail directory." |
18161 | 131 :type 'sexp |
132 :group 'mailalias) | |
133 (put 'mail-directory-stream 'risky-local-variable t) | |
134 | |
135 (defcustom mail-directory-parser nil | |
102561
352aa67bded9
Remove leading `*' from defcustom docs.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
136 "How to interpret the output of `mail-directory-function'. |
18161 | 137 Three types of values are possible: |
138 | |
139 - nil means to gather each line as one name | |
140 - regexp means first \\(grouping\\) in successive matches is name | |
141 - function called at beginning of buffer that returns an alist of names" | |
18168
0fa57e6872f0
(mail-directory-parser): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents:
18161
diff
changeset
|
142 :type '(choice (const nil) regexp function) |
18161 | 143 :group 'mailalias) |
144 (put 'mail-directory-parser 'risky-local-variable t) | |
145 | |
146 ;; Internal variables. | |
147 | |
14551
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
148 (defvar mail-names t |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
149 "Alist of local users, aliases and directory entries as available. |
17310
9c0ece61d60a
(mail-complete-style): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17210
diff
changeset
|
150 Elements have the form (MAILNAME) or (MAILNAME . FULLNAME). |
9c0ece61d60a
(mail-complete-style): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17210
diff
changeset
|
151 If the value means t, it means the real value should be calculated |
60964
0b933f58d514
(mail-directory-process): Do nothing if mail-directory-process is an atom.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
152 for the next use. This is used in `mail-complete'.") |
14551
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
153 |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
154 (defvar mail-local-names t |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
155 "Alist of local users. |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
156 When t this still needs to be initialized.") |
18161 | 157 |
14551
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
158 |
53 | 159 ;; Called from sendmail-send-it, or similar functions, |
160 ;; only if some mail aliases are defined. | |
17797
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
161 ;;;###autoload |
53 | 162 (defun expand-mail-aliases (beg end &optional exclude) |
163 "Expand all mail aliases in suitable header fields found between BEG and END. | |
21867
ccda1e80b153
(expand-mail-aliases): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
21752
diff
changeset
|
164 If interactive, expand in header fields. |
11856
abf2dbc46f7d
(expand-mail-aliases): Expand aliases in
Karl Heuer <kwzh@gnu.org>
parents:
11639
diff
changeset
|
165 Suitable header fields are `To', `From', `CC' and `BCC', `Reply-to', and |
abf2dbc46f7d
(expand-mail-aliases): Expand aliases in
Karl Heuer <kwzh@gnu.org>
parents:
11639
diff
changeset
|
166 their `Resent-' variants. |
abf2dbc46f7d
(expand-mail-aliases): Expand aliases in
Karl Heuer <kwzh@gnu.org>
parents:
11639
diff
changeset
|
167 |
221
ce8e0192266e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
219
diff
changeset
|
168 Optional second arg EXCLUDE may be a regular expression defining text to be |
ce8e0192266e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
219
diff
changeset
|
169 removed from alias expansions." |
17797
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
170 (interactive |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
171 (save-excursion |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
172 (list (goto-char (point-min)) |
21867
ccda1e80b153
(expand-mail-aliases): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
21752
diff
changeset
|
173 (mail-header-end)))) |
14038
49642146f16c
(expand-mail-aliases, define-mail-alias): Fix calls to `sendmail-sync-aliases'
Karl Heuer <kwzh@gnu.org>
parents:
13653
diff
changeset
|
174 (sendmail-sync-aliases) |
17797
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
175 (when (eq mail-aliases t) |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
176 (setq mail-aliases nil) |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
177 (build-mail-aliases)) |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
178 (save-excursion |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
179 (goto-char beg) |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
180 (setq end (set-marker (make-marker) end)) |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
181 (let ((case-fold-search nil)) |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
182 (while (let ((case-fold-search t)) |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
183 (re-search-forward mail-address-field-regexp end t)) |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
184 (skip-chars-forward " \t") |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
185 (let ((beg1 (point)) |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
186 end1 pos epos seplen |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
187 ;; DISABLED-ALIASES records aliases temporarily disabled |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
188 ;; while we scan text that resulted from expanding those aliases. |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
189 ;; Each element is (ALIAS . TILL-WHEN), where TILL-WHEN |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
190 ;; is where to reenable the alias (expressed as number of chars |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
191 ;; counting from END1). |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
192 (disabled-aliases nil)) |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
193 (re-search-forward "^[^ \t]" end 'move) |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
194 (beginning-of-line) |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
195 (skip-chars-backward " \t\n") |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
196 (setq end1 (point-marker)) |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
197 (goto-char beg1) |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
198 (while (< (point) end1) |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
199 (setq pos (point)) |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
200 ;; Reenable any aliases which were disabled for ranges |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
201 ;; that we have passed out of. |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
202 (while (and disabled-aliases |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
203 (> pos (- end1 (cdr (car disabled-aliases))))) |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
204 (setq disabled-aliases (cdr disabled-aliases))) |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
205 ;; EPOS gets position of end of next name; |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
206 ;; SEPLEN gets length of whitespace&separator that follows it. |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
207 (if (re-search-forward "[ \t]*[\n,][ \t]*" end1 t) |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
208 (setq epos (match-beginning 0) |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
209 seplen (- (point) epos)) |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
210 (setq epos (marker-position end1) seplen 0)) |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
211 (let ((string (buffer-substring-no-properties pos epos)) |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
212 translation) |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
213 (if (and (not (assoc string disabled-aliases)) |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
214 (setq translation (cdr (assoc string mail-aliases)))) |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
215 (progn |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
216 ;; This name is an alias. Disable it. |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
217 (setq disabled-aliases (cons (cons string (- end1 epos)) |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
218 disabled-aliases)) |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
219 ;; Replace the alias with its expansion |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
220 ;; then rescan the expansion for more aliases. |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
221 (goto-char pos) |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
222 (insert translation) |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
223 (when exclude |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
224 (let ((regexp (concat "\\b\\(" exclude "\\)\\b")) |
53 | 225 (end (point-marker))) |
226 (goto-char pos) | |
227 (while (re-search-forward regexp end t) | |
228 (replace-match "")) | |
229 (goto-char end))) | |
17797
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
230 (delete-region (point) (+ (point) (- epos pos))) |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
231 (goto-char pos)) |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
232 ;; Name is not an alias. Skip to start of next name. |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
233 (goto-char epos) |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
234 (forward-char seplen)))) |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
235 (set-marker end1 nil))) |
7faea977229c
make expand-mail-aliases interactive
Simon Marshall <simon@gnu.org>
parents:
17310
diff
changeset
|
236 (set-marker end nil)))) |
53 | 237 |
10327
8822b968b11c
Use `mail-personal-alias-file' globally in place of hardwired "~/.mailrc".
Noah Friedman <friedman@splode.com>
parents:
9644
diff
changeset
|
238 ;; Called by mail-setup, or similar functions, only if the file specified |
8822b968b11c
Use `mail-personal-alias-file' globally in place of hardwired "~/.mailrc".
Noah Friedman <friedman@splode.com>
parents:
9644
diff
changeset
|
239 ;; by mail-personal-alias-file (usually `~/.mailrc') exists. |
53 | 240 (defun build-mail-aliases (&optional file) |
10327
8822b968b11c
Use `mail-personal-alias-file' globally in place of hardwired "~/.mailrc".
Noah Friedman <friedman@splode.com>
parents:
9644
diff
changeset
|
241 "Read mail aliases from personal aliases file and set `mail-aliases'. |
8822b968b11c
Use `mail-personal-alias-file' globally in place of hardwired "~/.mailrc".
Noah Friedman <friedman@splode.com>
parents:
9644
diff
changeset
|
242 By default, this is the file specified by `mail-personal-alias-file'." |
8822b968b11c
Use `mail-personal-alias-file' globally in place of hardwired "~/.mailrc".
Noah Friedman <friedman@splode.com>
parents:
9644
diff
changeset
|
243 (setq file (expand-file-name (or file mail-personal-alias-file))) |
20810
55e8d6d2c3b1
(define-mail-alias): If FROM-MAILRC-FILE, don't call sendmail-sync-aliases.
Richard M. Stallman <rms@gnu.org>
parents:
20490
diff
changeset
|
244 ;; In case mail-aliases is t, make sure define-mail-alias |
55e8d6d2c3b1
(define-mail-alias): If FROM-MAILRC-FILE, don't call sendmail-sync-aliases.
Richard M. Stallman <rms@gnu.org>
parents:
20490
diff
changeset
|
245 ;; does not recursively call build-mail-aliases. |
55e8d6d2c3b1
(define-mail-alias): If FROM-MAILRC-FILE, don't call sendmail-sync-aliases.
Richard M. Stallman <rms@gnu.org>
parents:
20490
diff
changeset
|
246 (setq mail-aliases nil) |
104648
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
247 (with-temp-buffer |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
248 (while file |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
249 (cond ((get-file-buffer file) |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
250 (insert (with-current-buffer (get-file-buffer file) |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
251 (buffer-substring-no-properties |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
252 (point-min) (point-max))))) |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
253 ((file-exists-p file) (insert-file-contents file)) |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
254 ((file-exists-p (setq file (expand-file-name file "~/"))) |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
255 (insert-file-contents file)) |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
256 (t (setq file nil))) |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
257 (goto-char (point-min)) |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
258 ;; Delete comments from the contents. |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
259 (while (search-forward "# " nil t) |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
260 (let ((p (- (point) 2))) |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
261 (end-of-line) |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
262 (delete-region p (point)))) |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
263 ;; Don't lose if no final newline. |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
264 (goto-char (point-max)) |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
265 (or (eq (preceding-char) ?\n) (newline)) |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
266 (goto-char (point-min)) |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
267 ;; handle "\\\n" continuation lines |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
268 (while (not (eobp)) |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
269 (end-of-line) |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
270 (if (= (preceding-char) ?\\) |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
271 (progn (delete-char -1) (delete-char 1) (insert ?\ )) |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
272 (forward-char 1))) |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
273 (goto-char (point-min)) |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
274 ;; handle `source' directives -- Eddy/1994/May/25 |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
275 (cond ((re-search-forward "^source[ \t]+" nil t) |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
276 (re-search-forward "\\S-+") |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
277 (setq file (buffer-substring-no-properties |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
278 (match-beginning 0) (match-end 0))) |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
279 (beginning-of-line) |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
280 (insert "# ") ; to ensure we don't re-process this file |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
281 (beginning-of-line)) |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
282 (t (setq file nil)))) |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
283 (goto-char (point-min)) |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
284 (while (re-search-forward |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
285 "^\\(a\\|alias\\|g\\|group\\)[ \t]+\\([^ \t\n]+\\)" nil t) |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
286 (let* ((name (match-string 2)) |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
287 (start (progn (skip-chars-forward " \t") (point))) |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
288 value) |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
289 (end-of-line) |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
290 (setq value (buffer-substring-no-properties start (point))) |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
291 (unless (equal value "") |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
292 (define-mail-alias name value t)))) |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
293 mail-aliases)) |
53 | 294 |
295 ;; Always autoloadable in case the user wants to define aliases | |
296 ;; interactively or in .emacs. | |
99928
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
297 ;; define-mail-abbrev in mailabbrev.el duplicates much of this code. |
256 | 298 ;;;###autoload |
7971
e02c5d5d76cd
(define-mail-alias): Copy parsing code from mailabbrev.el.
Richard M. Stallman <rms@gnu.org>
parents:
7970
diff
changeset
|
299 (defun define-mail-alias (name definition &optional from-mailrc-file) |
221
ce8e0192266e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
219
diff
changeset
|
300 "Define NAME as a mail alias that translates to DEFINITION. |
53 | 301 This means that sending a message to NAME will actually send to DEFINITION. |
12448
7291d1627d2c
(define-mail-alias): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
11856
diff
changeset
|
302 |
7291d1627d2c
(define-mail-alias): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
11856
diff
changeset
|
303 Normally, the addresses in DEFINITION must be separated by commas. |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
39866
diff
changeset
|
304 If FROM-MAILRC-FILE is non-nil, then addresses in DEFINITION |
12448
7291d1627d2c
(define-mail-alias): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
11856
diff
changeset
|
305 can be separated by spaces; an address can contain spaces |
7291d1627d2c
(define-mail-alias): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
11856
diff
changeset
|
306 if it is quoted with double-quotes." |
7291d1627d2c
(define-mail-alias): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
11856
diff
changeset
|
307 |
53 | 308 (interactive "sDefine mail alias: \nsDefine %s as mail alias for: ") |
309 ;; Read the defaults first, if we have not done so. | |
20810
55e8d6d2c3b1
(define-mail-alias): If FROM-MAILRC-FILE, don't call sendmail-sync-aliases.
Richard M. Stallman <rms@gnu.org>
parents:
20490
diff
changeset
|
310 ;; But not if we are doing that already right now. |
55e8d6d2c3b1
(define-mail-alias): If FROM-MAILRC-FILE, don't call sendmail-sync-aliases.
Richard M. Stallman <rms@gnu.org>
parents:
20490
diff
changeset
|
311 (unless from-mailrc-file |
55e8d6d2c3b1
(define-mail-alias): If FROM-MAILRC-FILE, don't call sendmail-sync-aliases.
Richard M. Stallman <rms@gnu.org>
parents:
20490
diff
changeset
|
312 (sendmail-sync-aliases)) |
53 | 313 (if (eq mail-aliases t) |
314 (progn | |
315 (setq mail-aliases nil) | |
10327
8822b968b11c
Use `mail-personal-alias-file' globally in place of hardwired "~/.mailrc".
Noah Friedman <friedman@splode.com>
parents:
9644
diff
changeset
|
316 (if (file-exists-p mail-personal-alias-file) |
53 | 317 (build-mail-aliases)))) |
3743
e67f922b73ed
(define-mail-alias): Remove excess whitespace better.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
318 ;; strip garbage from front and end |
e67f922b73ed
(define-mail-alias): Remove excess whitespace better.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
319 (if (string-match "\\`[ \t\n,]+" definition) |
474 | 320 (setq definition (substring definition (match-end 0)))) |
3743
e67f922b73ed
(define-mail-alias): Remove excess whitespace better.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
321 (if (string-match "[ \t\n,]+\\'" definition) |
474 | 322 (setq definition (substring definition 0 (match-beginning 0)))) |
99928
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
323 |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
324 (let* ((L (length definition)) |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
325 (start (if (> L 0) 0)) |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
326 end this-entry result tem) |
7971
e02c5d5d76cd
(define-mail-alias): Copy parsing code from mailabbrev.el.
Richard M. Stallman <rms@gnu.org>
parents:
7970
diff
changeset
|
327 (while start |
99928
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
328 (cond |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
329 (from-mailrc-file |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
330 ;; If we're reading from the mailrc file, addresses are |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
331 ;; delimited by spaces, and addresses with embedded spaces are |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
332 ;; surrounded by non-escaped double-quotes. |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
333 (if (eq ?\" (aref definition start)) |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
334 (setq start (1+ start) |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
335 end (and (string-match |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
336 "[^\\]\\(\\([\\][\\]\\)*\\)\"[ \t,]*" |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
337 definition start) |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
338 (match-end 1))) |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
339 (setq end (string-match "[ \t,]+" definition start))) |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
340 ;; Extract the address and advance the loop past it. |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
341 (setq this-entry (substring definition start end) |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
342 start (and end (/= (match-end 0) L) (match-end 0))) |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
343 ;; If the full name contains a problem character, quote it. |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
344 (and (string-match "\\(.+?\\)[ \t]*\\(<.*>\\)" this-entry) |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
345 (string-match "[^- !#$%&'*+/0-9=?A-Za-z^_`{|}~]" |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
346 (match-string 1 this-entry)) |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
347 (setq this-entry (replace-regexp-in-string |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
348 "\\(.+?\\)[ \t]*\\(<.*>\\)" |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
349 "\"\\1\" \\2" |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
350 this-entry)))) |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
351 ;; When we are not reading from .mailrc, addresses are |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
352 ;; separated by commas. Try to accept a rfc822-like syntax. |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
353 ;; (Todo: extend rfc822.el to do the work for us.) |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
354 ((equal (string-match |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
355 "[ \t,]*\\(\"\\(?:[^\"]\\|[^\\]\\(?:[\\][\\]\\)*\"\\)*\"[ \t]*\ |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
356 <[-.!#$%&'*+/0-9=?A-Za-z^_`{|}~@]+>\\)[ \t,]*" |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
357 definition start) |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
358 start) |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
359 ;; If an entry has a valid [ "foo bar" <foo@example.com> ] |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
360 ;; form, use it literally . This also allows commas in the |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
361 ;; quoted string, e.g. [ "foo bar, jr" <foo@example.com> ] |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
362 (setq this-entry (match-string 1 definition) |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
363 start (and (/= (match-end 0) L) (match-end 0)))) |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
364 (t |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
365 ;; Otherwise, read the next address by looking for a comma. |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
366 (setq end (string-match "[ \t\n,]*,[ \t\n]*" definition start)) |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
367 (setq this-entry (substring definition start end)) |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
368 ;; Advance the loop past this address. |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
369 (setq start (and end (/= (match-end 0) L) (match-end 0))) |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
370 ;; If the full name contains a problem character, quote it. |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
371 (and (string-match "\\(.+?\\)[ \t]*\\(<.*>\\)" this-entry) |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
372 (string-match "[^- !#$%&'*+/0-9=?A-Za-z^_`{|}~]" |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
373 (match-string 1 this-entry)) |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
374 (setq this-entry (replace-regexp-in-string |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
375 "\\(.+?\\)[ \t]*\\(<.*>\\)" "\"\\1\" \\2" |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
376 this-entry))))) |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
377 (push this-entry result)) |
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
378 |
7971
e02c5d5d76cd
(define-mail-alias): Copy parsing code from mailabbrev.el.
Richard M. Stallman <rms@gnu.org>
parents:
7970
diff
changeset
|
379 (setq definition (mapconcat (function identity) |
99928
ba6d5a708321
(define-mail-alias): Sync code with define-mail-abbrev.
Chong Yidong <cyd@stupidchicken.com>
parents:
94674
diff
changeset
|
380 (nreverse result) ", ")) |
53 | 381 (setq tem (assoc name mail-aliases)) |
382 (if tem | |
383 (rplacd tem definition) | |
14551
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
384 (setq mail-aliases (cons (cons name definition) mail-aliases) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
385 mail-names t)))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
386 |
14678
f77d51b836d0
(mail-complete): Add autoload cookie.
Richard M. Stallman <rms@gnu.org>
parents:
14551
diff
changeset
|
387 ;;;###autoload |
14551
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
388 (defun mail-complete (arg) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
389 "Perform completion on header field or word preceding point. |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
390 Completable headers are according to `mail-complete-alist'. If none matches |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
391 current header, calls `mail-complete-function' and passes prefix arg if any." |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
392 (interactive "P") |
15501
3cc16244b779
Resync mail aliases if necessary.
Simon Marshall <simon@gnu.org>
parents:
14799
diff
changeset
|
393 ;; Read the defaults first, if we have not done so. |
3cc16244b779
Resync mail aliases if necessary.
Simon Marshall <simon@gnu.org>
parents:
14799
diff
changeset
|
394 (sendmail-sync-aliases) |
3cc16244b779
Resync mail aliases if necessary.
Simon Marshall <simon@gnu.org>
parents:
14799
diff
changeset
|
395 (if (eq mail-aliases t) |
3cc16244b779
Resync mail aliases if necessary.
Simon Marshall <simon@gnu.org>
parents:
14799
diff
changeset
|
396 (progn |
3cc16244b779
Resync mail aliases if necessary.
Simon Marshall <simon@gnu.org>
parents:
14799
diff
changeset
|
397 (setq mail-aliases nil) |
3cc16244b779
Resync mail aliases if necessary.
Simon Marshall <simon@gnu.org>
parents:
14799
diff
changeset
|
398 (if (file-exists-p mail-personal-alias-file) |
3cc16244b779
Resync mail aliases if necessary.
Simon Marshall <simon@gnu.org>
parents:
14799
diff
changeset
|
399 (build-mail-aliases)))) |
14551
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
400 (let ((list mail-complete-alist)) |
22621
e017a2c05245
(mail-complete): Fix the test of (mail-heder-end).
Richard M. Stallman <rms@gnu.org>
parents:
22081
diff
changeset
|
401 (if (and (< 0 (mail-header-end)) |
14551
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
402 (save-excursion |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
403 (if (re-search-backward "^[^\t]" nil t) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
404 (while list |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
405 (if (looking-at (car (car list))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
406 (setq arg (cdr (car list)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
407 list ()) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
408 (setq list (cdr list))))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
409 arg)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
410 (let* ((end (point)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
411 (beg (save-excursion |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
412 (skip-chars-backward "^ \t<,:") |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
413 (point))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
414 (pattern (buffer-substring beg end)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
415 completion) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
416 (setq list (eval arg) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
417 completion (try-completion pattern list)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
418 (cond ((eq completion t)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
419 ((null completion) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
420 (message "Can't find completion for \"%s\"" pattern) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
421 (ding)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
422 ((not (string= pattern completion)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
423 (delete-region beg end) |
17310
9c0ece61d60a
(mail-complete-style): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17210
diff
changeset
|
424 (let ((alist-elt (assoc completion mail-names))) |
9c0ece61d60a
(mail-complete-style): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17210
diff
changeset
|
425 (if (cdr alist-elt) |
9c0ece61d60a
(mail-complete-style): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17210
diff
changeset
|
426 (cond ((eq mail-complete-style 'parens) |
9c0ece61d60a
(mail-complete-style): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17210
diff
changeset
|
427 (insert completion " (" (cdr alist-elt) ")")) |
9c0ece61d60a
(mail-complete-style): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17210
diff
changeset
|
428 ((eq mail-complete-style 'angles) |
9c0ece61d60a
(mail-complete-style): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17210
diff
changeset
|
429 (insert (cdr alist-elt) " <" completion ">")) |
9c0ece61d60a
(mail-complete-style): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17210
diff
changeset
|
430 (t |
9c0ece61d60a
(mail-complete-style): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17210
diff
changeset
|
431 (insert completion))) |
9c0ece61d60a
(mail-complete-style): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17210
diff
changeset
|
432 (insert completion)))) |
14551
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
433 (t |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
434 (message "Making completion list...") |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
435 (with-output-to-temp-buffer "*Completions*" |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
436 (display-completion-list |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
437 (all-completions pattern list))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
438 (message "Making completion list...%s" "done")))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
439 (funcall mail-complete-function arg)))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
440 |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
441 (defun mail-get-names (pattern) |
17310
9c0ece61d60a
(mail-complete-style): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17210
diff
changeset
|
442 "Fetch local users and global mail addresses for completion. |
14551
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
443 Consults `/etc/passwd' and a directory service if one is set up via |
17310
9c0ece61d60a
(mail-complete-style): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17210
diff
changeset
|
444 `mail-directory-function'. |
9c0ece61d60a
(mail-complete-style): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17210
diff
changeset
|
445 PATTERN is the string we want to complete." |
14551
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
446 (if (eq mail-local-names t) |
104648
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
447 (with-current-buffer (generate-new-buffer " passwd") |
17210
5c7c572f57f8
(mail-passwd-command): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
15501
diff
changeset
|
448 (let ((files mail-passwd-files)) |
5c7c572f57f8
(mail-passwd-command): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
15501
diff
changeset
|
449 (while files |
5c7c572f57f8
(mail-passwd-command): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
15501
diff
changeset
|
450 (insert-file-contents (car files) nil nil nil t) |
5c7c572f57f8
(mail-passwd-command): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
15501
diff
changeset
|
451 (setq files (cdr files)))) |
5c7c572f57f8
(mail-passwd-command): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
15501
diff
changeset
|
452 (if mail-passwd-command |
5c7c572f57f8
(mail-passwd-command): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
15501
diff
changeset
|
453 (call-process shell-file-name nil t nil |
5c7c572f57f8
(mail-passwd-command): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
15501
diff
changeset
|
454 shell-command-switch mail-passwd-command)) |
62620
564274a2eaa2
(mail-get-names): Avoid beginning-of-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
62402
diff
changeset
|
455 (goto-char (point-min)) |
17210
5c7c572f57f8
(mail-passwd-command): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
15501
diff
changeset
|
456 (setq mail-local-names nil) |
14551
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
457 (while (not (eobp)) |
14799
619266555aec
(mail-get-names): Understand "+username" format for /etc/passwd lines.
Richard M. Stallman <rms@gnu.org>
parents:
14678
diff
changeset
|
458 ;;Recognize lines like |
619266555aec
(mail-get-names): Understand "+username" format for /etc/passwd lines.
Richard M. Stallman <rms@gnu.org>
parents:
14678
diff
changeset
|
459 ;; nobody:*:65534:65534::/: |
619266555aec
(mail-get-names): Understand "+username" format for /etc/passwd lines.
Richard M. Stallman <rms@gnu.org>
parents:
14678
diff
changeset
|
460 ;; +demo::::::/bin/csh |
619266555aec
(mail-get-names): Understand "+username" format for /etc/passwd lines.
Richard M. Stallman <rms@gnu.org>
parents:
14678
diff
changeset
|
461 ;; +ethanb |
619266555aec
(mail-get-names): Understand "+username" format for /etc/passwd lines.
Richard M. Stallman <rms@gnu.org>
parents:
14678
diff
changeset
|
462 ;;while skipping |
619266555aec
(mail-get-names): Understand "+username" format for /etc/passwd lines.
Richard M. Stallman <rms@gnu.org>
parents:
14678
diff
changeset
|
463 ;; +@SOFTWARE |
17310
9c0ece61d60a
(mail-complete-style): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17210
diff
changeset
|
464 ;; The second \(...\) matches the user id. |
9c0ece61d60a
(mail-complete-style): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17210
diff
changeset
|
465 (if (looking-at "\\+?\\([^:@\n+]+\\):[^:\n]*:\\([^\n:]*\\):") |
9c0ece61d60a
(mail-complete-style): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17210
diff
changeset
|
466 (add-to-list 'mail-local-names |
9c0ece61d60a
(mail-complete-style): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17210
diff
changeset
|
467 (cons (match-string 1) |
9c0ece61d60a
(mail-complete-style): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17210
diff
changeset
|
468 (user-full-name |
62402
a7e02ef1e3d6
Replace `string-to-int' by `string-to-number'.
Juanma Barranquero <lekktu@gmail.com>
parents:
60964
diff
changeset
|
469 (string-to-number (match-string 2)))))) |
14551
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
470 (beginning-of-line 2)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
471 (kill-buffer (current-buffer)))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
472 (if (or (eq mail-names t) |
17310
9c0ece61d60a
(mail-complete-style): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17210
diff
changeset
|
473 (eq mail-directory-names t)) |
14551
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
474 (let (directory) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
475 (and mail-directory-function |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
476 (eq mail-directory-names t) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
477 (setq directory |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
478 (mail-directory (if mail-directory-requery pattern)))) |
17310
9c0ece61d60a
(mail-complete-style): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17210
diff
changeset
|
479 (or mail-directory-requery |
9c0ece61d60a
(mail-complete-style): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17210
diff
changeset
|
480 (setq mail-directory-names directory)) |
14551
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
481 (if (or directory |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
482 (eq mail-names t)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
483 (setq mail-names |
17310
9c0ece61d60a
(mail-complete-style): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17210
diff
changeset
|
484 (sort (append (if (consp mail-aliases) |
9c0ece61d60a
(mail-complete-style): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17210
diff
changeset
|
485 (mapcar |
9c0ece61d60a
(mail-complete-style): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17210
diff
changeset
|
486 (function (lambda (a) (list (car a)))) |
9c0ece61d60a
(mail-complete-style): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17210
diff
changeset
|
487 mail-aliases)) |
14551
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
488 (if (consp mail-local-names) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
489 mail-local-names) |
60964
0b933f58d514
(mail-directory-process): Do nothing if mail-directory-process is an atom.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
490 (or directory |
0b933f58d514
(mail-directory-process): Do nothing if mail-directory-process is an atom.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
491 (when (consp mail-directory-names) |
0b933f58d514
(mail-directory-process): Do nothing if mail-directory-process is an atom.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
492 mail-directory-names))) |
14551
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
493 (lambda (a b) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
494 ;; should cache downcased strings |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
495 (string< (downcase (car a)) |
17310
9c0ece61d60a
(mail-complete-style): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17210
diff
changeset
|
496 (downcase (car b))))))))) |
14551
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
497 mail-names) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
498 |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
499 |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
500 (defun mail-directory (pattern) |
60964
0b933f58d514
(mail-directory-process): Do nothing if mail-directory-process is an atom.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
501 "Use mail-directory facility to get user names matching PATTERN. |
0b933f58d514
(mail-directory-process): Do nothing if mail-directory-process is an atom.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
502 If PATTERN is nil, get all the defined user names. |
0b933f58d514
(mail-directory-process): Do nothing if mail-directory-process is an atom.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
503 This function calls `mail-directory-function' to query the directory, |
0b933f58d514
(mail-directory-process): Do nothing if mail-directory-process is an atom.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
504 then uses `mail-directory-parser' to parse the output it returns." |
104648
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
505 (message "Querying directory...") |
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
506 (with-current-buffer (generate-new-buffer " *mail-directory*") |
14551
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
507 (funcall mail-directory-function pattern) |
104648
a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102561
diff
changeset
|
508 (goto-char (point-min)) |
14551
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
509 (let (directory) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
510 (if (stringp mail-directory-parser) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
511 (while (re-search-forward mail-directory-parser nil t) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
512 (setq directory |
17310
9c0ece61d60a
(mail-complete-style): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17210
diff
changeset
|
513 (cons (match-string 1) directory))) |
14551
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
514 (if mail-directory-parser |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
515 (setq directory (funcall mail-directory-parser)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
516 (while (not (eobp)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
517 (setq directory |
17310
9c0ece61d60a
(mail-complete-style): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17210
diff
changeset
|
518 (cons (buffer-substring (point) |
9c0ece61d60a
(mail-complete-style): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17210
diff
changeset
|
519 (progn |
9c0ece61d60a
(mail-complete-style): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17210
diff
changeset
|
520 (forward-line) |
9c0ece61d60a
(mail-complete-style): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17210
diff
changeset
|
521 (if (bolp) |
9c0ece61d60a
(mail-complete-style): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17210
diff
changeset
|
522 (1- (point)) |
9c0ece61d60a
(mail-complete-style): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17210
diff
changeset
|
523 (point)))) |
9c0ece61d60a
(mail-complete-style): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17210
diff
changeset
|
524 directory))))) |
14551
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
525 (kill-buffer (current-buffer)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
526 (message "Querying directory...done") |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
527 directory))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
528 |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
529 |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
530 (defun mail-directory-process (pattern) |
18161 | 531 "Run a shell command to output names in directory. |
14551
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
532 See `mail-directory-process'." |
60964
0b933f58d514
(mail-directory-process): Do nothing if mail-directory-process is an atom.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
533 (when (consp mail-directory-process) |
0b933f58d514
(mail-directory-process): Do nothing if mail-directory-process is an atom.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
534 (apply 'call-process (eval (car mail-directory-process)) nil t nil |
0b933f58d514
(mail-directory-process): Do nothing if mail-directory-process is an atom.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
535 (mapcar 'eval (cdr mail-directory-process))))) |
14551
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
536 |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
537 ;; This should handle a dialog. Currently expects port to spit out names. |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
538 (defun mail-directory-stream (pattern) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
539 "Open a stream to retrieve names in directory. |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
540 See `mail-directory-stream'." |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
541 (let (mailalias-done) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
542 (set-process-sentinel |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
543 (apply 'open-network-stream "mailalias" (current-buffer) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
544 mail-directory-stream) |
39866
a4570786d40d
Do not double variables in the lambda-list.
Pavel Janík <Pavel@Janik.cz>
parents:
24172
diff
changeset
|
545 (lambda (x y) |
14551
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
546 (setq mailalias-done t))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
547 (while (not mailalias-done) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
548 (sit-for .1)))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
549 |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
550 (defun mail-sentto-newsgroups () |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
551 "Return all entries from Newsgroups: header as completion alist." |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
552 (save-excursion |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
553 (if (mail-position-on-field "newsgroups" t) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
554 (let ((point (point)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
555 list) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
556 (while (< (skip-chars-backward "^:, \t\n") 0) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
557 (setq list `((,(buffer-substring (point) point)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
558 ,@list)) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
559 (skip-chars-backward ", \t\n") |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
560 (setq point (point))) |
dc2881fa11ea
(mail-names, mail-local-names, mail-directory-names)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
561 list)))) |
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
474
diff
changeset
|
562 |
923 | 563 (provide 'mailalias) |
564 | |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
79712
diff
changeset
|
565 ;; arch-tag: 1d6a0f87-eb34-4d45-8816-60c1b952cf46 |
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
474
diff
changeset
|
566 ;;; mailalias.el ends here |