aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1996-02-12 08:09:49 +0000
committerRichard M. Stallman1996-02-12 08:09:49 +0000
commit48919e0ff43dd48bedb1d51fd13f5a681ddf789d (patch)
treedffd435f405a801f70a53bb47b7efcc5bb793ece
parente376f90dd2a33e47fafdfe21abca5d4984fd3006 (diff)
downloademacs-48919e0ff43dd48bedb1d51fd13f5a681ddf789d.tar.gz
emacs-48919e0ff43dd48bedb1d51fd13f5a681ddf789d.zip
(mail-names, mail-local-names, mail-directory-names)
(mail-address-field-regexp, mail-complete-alist) (mail-complete-function, mail-directory-function) (mail-directory-requery, mail-directory-process, mail-directory-stream) (mail-directory-parser): New variables. (expand-mail-aliases): Use `mail-address-field-regexp'. (build-mail-aliases): Use space in buffer-name semantics. (define-mail-alias): Reset `mail-names' to t. (mail-complete): New command. (mail-get-names, mail-directory, mail-directory-process) (mail-directory-stream, mail-sentto-newsgroups): New functions.
-rw-r--r--lisp/mail/mailalias.el224
1 files changed, 218 insertions, 6 deletions
diff --git a/lisp/mail/mailalias.el b/lisp/mail/mailalias.el
index ce1cbf3748f..2dee17ab65f 100644
--- a/lisp/mail/mailalias.el
+++ b/lisp/mail/mailalias.el
@@ -1,6 +1,6 @@
1;;; mailalias.el --- expand mailing address aliases defined in ~/.mailrc. 1;;; mailalias.el --- expand and complete mailing address aliases
2 2
3;; Copyright (C) 1985, 1987 Free Software Foundation, Inc. 3;; Copyright (C) 1985, 1987, 1995, 1996 Free Software Foundation, Inc.
4 4
5;; Maintainer: FSF 5;; Maintainer: FSF
6;; Keywords: mail 6;; Keywords: mail
@@ -32,6 +32,76 @@
32 32
33(require 'sendmail) 33(require 'sendmail)
34 34
35(defvar mail-names t
36 "Alist of local users, aliases and directory entries as available.
37When t this still needs to be initialized.
38This is the basis for `mail-complete'.")
39
40(defvar mail-local-names t
41 "Alist of local users.
42When t this still needs to be initialized.")
43
44(defvar mail-directory-names t
45 "Alist of mail address directory entries.
46When t this still needs to be initialized.")
47
48(defvar mail-address-field-regexp
49 "^\\(Resent-\\)?\\(To\\|From\\|CC\\|BCC\\|Reply-to\\):")
50
51(defvar mail-complete-alist
52 `((,mail-address-field-regexp mail-get-names pattern)
53 ("Newsgroups:" . (if (boundp 'gnus-active-hashtb)
54 gnus-active-hashtb
55 (if (boundp news-group-article-assoc)
56 news-group-article-assoc)))
57 ("Followup-To:" . (mail-sentto-newsgroups))
58 ;;("Distribution:" ???)
59 )
60 "Alist of header field and expression to return alist for completion.
61Expression may reference variable `pattern' which is the string being completed.
62If not on matching header, `mail-complete-function' gets called instead.")
63
64(defvar mail-complete-function 'ispell-complete-word
65 "Function to call when completing outside `mail-complete-alist'-header.")
66
67
68(defvar mail-directory-function nil
69 "Function to get completions from directory service or `nil' for none.
70See `mail-directory-requery'.")
71
72
73;; This is for when the directory is huge, or changes frequently.
74(defvar mail-directory-requery nil
75 "When non-`nil' call `mail-directory-function' for each completion.
76In that case, one argument gets passed to the function, the partial string
77entered so far.")
78
79
80(defvar mail-directory-process nil
81 "Unix command when `mail-directory-function' is `mail-directory-process'.
82This is a list of the form (COMMAND ARG ...), where each of the list elements
83is evaluated. When `mail-directory-requery' is non-`nil', during
84evaluation the variable `pattern' contains the partial input being completed.
85This might look like
86
87 '(remote-shell-program \"HOST\" \"-nl\" \"USER\" \"COMMAND\")
88
89or
90
91 '(remote-shell-program \"HOST\" \"-n\" \"COMMAND '^\" pattern \"'\")")
92
93(defvar mail-directory-stream ()
94 "List of (HOST SERVICE) for stream connection to mail directory.")
95
96(defvar mail-directory-parser nil
97 "How to interpret the output of `mail-directory-function'.
98Three types of values are possible:
99
100 - nil means to gather each line as one name
101 - regexp means first \\(grouping\\) in successive matches is name
102 - function called at beginning of buffer that returns an alist of names")
103
104
35;; Called from sendmail-send-it, or similar functions, 105;; Called from sendmail-send-it, or similar functions,
36;; only if some mail aliases are defined. 106;; only if some mail aliases are defined.
37(defun expand-mail-aliases (beg end &optional exclude) 107(defun expand-mail-aliases (beg end &optional exclude)
@@ -48,7 +118,7 @@ removed from alias expansions."
48 (setq end (set-marker (make-marker) end)) 118 (setq end (set-marker (make-marker) end))
49 (let ((case-fold-search nil)) 119 (let ((case-fold-search nil))
50 (while (let ((case-fold-search t)) 120 (while (let ((case-fold-search t))
51 (re-search-forward "^\\(Resent-\\)?\\(To\\|From\\|CC\\|BCC\\|Reply-to\\):" end t)) 121 (re-search-forward mail-address-field-regexp end t))
52 (skip-chars-forward " \t") 122 (skip-chars-forward " \t")
53 (let ((beg1 (point)) 123 (let ((beg1 (point))
54 end1 pos epos seplen 124 end1 pos epos seplen
@@ -114,8 +184,7 @@ By default, this is the file specified by `mail-personal-alias-file'."
114 (obuf (current-buffer))) 184 (obuf (current-buffer)))
115 (unwind-protect 185 (unwind-protect
116 (progn 186 (progn
117 (setq buffer (generate-new-buffer "mailrc")) 187 (setq buffer (generate-new-buffer " mailrc"))
118 (buffer-disable-undo buffer)
119 (set-buffer buffer) 188 (set-buffer buffer)
120 (while file 189 (while file
121 (cond ((get-file-buffer file) 190 (cond ((get-file-buffer file)
@@ -211,7 +280,150 @@ if it is quoted with double-quotes."
211 (setq tem (assoc name mail-aliases)) 280 (setq tem (assoc name mail-aliases))
212 (if tem 281 (if tem
213 (rplacd tem definition) 282 (rplacd tem definition)
214 (setq mail-aliases (cons (cons name definition) mail-aliases))))) 283 (setq mail-aliases (cons (cons name definition) mail-aliases)
284 mail-names t))))
285
286
287(defun mail-complete (arg)
288 "Perform completion on header field or word preceding point.
289Completable headers are according to `mail-complete-alist'. If none matches
290current header, calls `mail-complete-function' and passes prefix arg if any."
291 (interactive "P")
292 (let ((list mail-complete-alist))
293 (if (and (save-excursion (search-forward
294 (concat "\n" mail-header-separator "\n")
295 nil t))
296 (save-excursion
297 (if (re-search-backward "^[^\t]" nil t)
298 (while list
299 (if (looking-at (car (car list)))
300 (setq arg (cdr (car list))
301 list ())
302 (setq list (cdr list)))))
303 arg))
304 (let* ((end (point))
305 (beg (save-excursion
306 (skip-chars-backward "^ \t<,:")
307 (point)))
308 (pattern (buffer-substring beg end))
309 completion)
310 (setq list (eval arg)
311 completion (try-completion pattern list))
312 (cond ((eq completion t))
313 ((null completion)
314 (message "Can't find completion for \"%s\"" pattern)
315 (ding))
316 ((not (string= pattern completion))
317 (delete-region beg end)
318 (insert completion))
319 (t
320 (message "Making completion list...")
321 (with-output-to-temp-buffer "*Completions*"
322 (display-completion-list
323 (all-completions pattern list)))
324 (message "Making completion list...%s" "done"))))
325 (funcall mail-complete-function arg))))
326
327(defun mail-get-names (pattern)
328 "Fetch local users and global mail adresses for completion.
329Consults `/etc/passwd' and a directory service if one is set up via
330`mail-directory-function'."
331 (if (eq mail-local-names t)
332 (save-excursion
333 (set-buffer (generate-new-buffer " passwd"))
334 (insert-file-contents "/etc/passwd" nil nil nil t)
335 (setq mail-local-names)
336 (while (not (eobp))
337 (setq mail-local-names
338 `((,(buffer-substring (point)
339 (1- (search-forward ":"))))
340 ,@mail-local-names))
341 (beginning-of-line 2))
342 (kill-buffer (current-buffer))))
343 (if (or (eq mail-names t)
344 (eq mail-directory-names t))
345 (let (directory)
346 (and mail-directory-function
347 (eq mail-directory-names t)
348 (setq directory
349 (mail-directory (if mail-directory-requery pattern))))
350 (if (or directory
351 (eq mail-names t))
352 (setq mail-names
353 (sort (append (if (consp mail-aliases) mail-aliases)
354 (if (consp mail-local-names)
355 mail-local-names)
356 directory)
357 (lambda (a b)
358 ;; should cache downcased strings
359 (string< (downcase (car a))
360 (downcase (car b)))))))
361 (or mail-directory-requery
362 (setq mail-directory-names directory))))
363 mail-names)
364
365
366(defun mail-directory (pattern)
367 "Call directory to get names matching PATTERN or all if `nil'.
368Calls `mail-directory-function' and applies `mail-directory-parser' to output."
369 (save-excursion
370 (message "Querying directory...")
371 (set-buffer (generate-new-buffer " *mail-directory*"))
372 (funcall mail-directory-function pattern)
373 (goto-char 1)
374 (let (directory)
375 (if (stringp mail-directory-parser)
376 (while (re-search-forward mail-directory-parser nil t)
377 (setq directory
378 `((,(match-string 1))
379 ,@directory)))
380 (if mail-directory-parser
381 (setq directory (funcall mail-directory-parser))
382 (while (not (eobp))
383 (setq directory
384 `((,(buffer-substring (point)
385 (progn
386 (forward-line)
387 (if (bolp)
388 (1- (point))
389 (point)))))
390 ,@directory)))))
391 (kill-buffer (current-buffer))
392 (message "Querying directory...done")
393 directory)))
394
395
396(defun mail-directory-process (pattern)
397 "Call a Unix process to output names in directory.
398See `mail-directory-process'."
399 (apply 'call-process (eval (car mail-directory-process)) nil t nil
400 (mapcar 'eval (cdr mail-directory-process))))
401
402;; This should handle a dialog. Currently expects port to spit out names.
403(defun mail-directory-stream (pattern)
404 "Open a stream to retrieve names in directory.
405See `mail-directory-stream'."
406 (let (mailalias-done)
407 (set-process-sentinel
408 (apply 'open-network-stream "mailalias" (current-buffer)
409 mail-directory-stream)
410 (lambda (x x)
411 (setq mailalias-done t)))
412 (while (not mailalias-done)
413 (sit-for .1))))
414
415(defun mail-sentto-newsgroups ()
416 "Return all entries from Newsgroups: header as completion alist."
417 (save-excursion
418 (if (mail-position-on-field "newsgroups" t)
419 (let ((point (point))
420 list)
421 (while (< (skip-chars-backward "^:, \t\n") 0)
422 (setq list `((,(buffer-substring (point) point))
423 ,@list))
424 (skip-chars-backward ", \t\n")
425 (setq point (point)))
426 list))))
215 427
216(provide 'mailalias) 428(provide 'mailalias)
217 429