comparison lisp/mh-e/mh-alias.el @ 67758:6b063593fdad

Follow Emacs coding conventions. Use default setting of emacs-lisp-docstring-fill-column which is 65.
author Bill Wohler <wohler@newt.com>
date Fri, 23 Dec 2005 07:40:40 +0000
parents 7ff92ad99326
children 9c3504ae6060
comparison
equal deleted inserted replaced
67757:488b4dbc7482 67758:6b063593fdad
66 (defvar mh-alias-system-aliases 66 (defvar mh-alias-system-aliases
67 '("/etc/nmh/MailAliases" "/etc/mh/MailAliases" 67 '("/etc/nmh/MailAliases" "/etc/mh/MailAliases"
68 "/usr/lib/mh/MailAliases" "/usr/share/mailutils/mh/MailAliases" 68 "/usr/lib/mh/MailAliases" "/usr/share/mailutils/mh/MailAliases"
69 "/etc/passwd") 69 "/etc/passwd")
70 "*A list of system files which are a source of aliases. 70 "*A list of system files which are a source of aliases.
71 If these files are modified, they are automatically reread. This list need 71 If these files are modified, they are automatically reread. This list
72 include only system aliases and the passwd file, since personal alias files 72 need include only system aliases and the passwd file, since personal
73 listed in your `Aliasfile:' MH profile component are automatically included. 73 alias files listed in your `Aliasfile:' MH profile component are
74 You can update the alias list manually using \\[mh-alias-reload].") 74 automatically included. You can update the alias list manually using
75 \\[mh-alias-reload].")
75 76
76 77
77 78
78 ;;; Alias Loading 79 ;;; Alias Loading
79 80
80 (defun mh-alias-tstamp (arg) 81 (defun mh-alias-tstamp (arg)
81 "Check whether alias files have been modified. 82 "Check whether alias files have been modified.
82 Return t if any file listed in the Aliasfile MH profile component has been 83 Return t if any file listed in the Aliasfile MH profile component has
83 modified since the timestamp. 84 been modified since the timestamp.
84 If ARG is non-nil, set timestamp with the current time." 85 If ARG is non-nil, set timestamp with the current time."
85 (if arg 86 (if arg
86 (let ((time (current-time))) 87 (let ((time (current-time)))
87 (setq mh-alias-tstamp (list (nth 0 time) (nth 1 time)))) 88 (setq mh-alias-tstamp (list (nth 0 time) (nth 1 time))))
88 (let ((stamp)) 89 (let ((stamp))
96 (> (cadr stamp) (cadr mh-alias-tstamp))))))) 97 (> (cadr stamp) (cadr mh-alias-tstamp)))))))
97 (mh-alias-filenames t))))))) 98 (mh-alias-filenames t)))))))
98 99
99 (defun mh-alias-filenames (arg) 100 (defun mh-alias-filenames (arg)
100 "Return list of filenames that contain aliases. 101 "Return list of filenames that contain aliases.
101 The filenames come from the Aliasfile profile component and are expanded. 102 The filenames come from the Aliasfile profile component and are
102 If ARG is non-nil, filenames listed in `mh-alias-system-aliases' are appended." 103 expanded.
104 If ARG is non-nil, filenames listed in `mh-alias-system-aliases' are
105 appended."
103 (or mh-progs (mh-find-path)) 106 (or mh-progs (mh-find-path))
104 (save-excursion 107 (save-excursion
105 (let* ((filename (mh-profile-component "Aliasfile")) 108 (let* ((filename (mh-profile-component "Aliasfile"))
106 (filelist (and filename (split-string filename "[ \t]+"))) 109 (filelist (and filename (split-string filename "[ \t]+")))
107 (userlist 110 (userlist
118 (append userlist mh-alias-system-aliases)) 121 (append userlist mh-alias-system-aliases))
119 userlist)))) 122 userlist))))
120 123
121 (defun mh-alias-gecos-name (gecos-name username comma-separator) 124 (defun mh-alias-gecos-name (gecos-name username comma-separator)
122 "Return a usable address string from a GECOS-NAME and USERNAME. 125 "Return a usable address string from a GECOS-NAME and USERNAME.
123 Use only part of the GECOS-NAME up to the first comma if COMMA-SEPARATOR is 126 Use only part of the GECOS-NAME up to the first comma if
124 non-nil." 127 COMMA-SEPARATOR is non-nil."
125 (let ((res gecos-name)) 128 (let ((res gecos-name))
126 ;; Keep only string until first comma if COMMA-SEPARATOR is t. 129 ;; Keep only string until first comma if COMMA-SEPARATOR is t.
127 (if (and comma-separator 130 (if (and comma-separator
128 (string-match "^\\([^,]+\\)," res)) 131 (string-match "^\\([^,]+\\)," res))
129 (setq res (match-string 1 res))) 132 (setq res (match-string 1 res)))
181 184
182 ;;;###mh-autoload 185 ;;;###mh-autoload
183 (defun mh-alias-reload () 186 (defun mh-alias-reload ()
184 "Reload MH aliases. 187 "Reload MH aliases.
185 188
186 Since aliases are updated frequently, MH-E reloads aliases automatically 189 Since aliases are updated frequently, MH-E reloads aliases
187 whenever an alias lookup occurs if an alias source has changed. Sources 190 automatically whenever an alias lookup occurs if an alias source has
188 include files listed in your `Aliasfile:' profile component and your password 191 changed. Sources include files listed in your `Aliasfile:' profile
189 file if option `mh-alias-local-users' is turned on. However, you can reload 192 component and your password file if option `mh-alias-local-users' is
190 your aliases manually by calling this command directly. 193 turned on. However, you can reload your aliases manually by calling
191 194 this command directly.
192 This function runs `mh-alias-reloaded-hook' after the aliases have been 195
193 loaded." 196 This function runs `mh-alias-reloaded-hook' after the aliases have
197 been loaded."
194 (interactive) 198 (interactive)
195 (save-excursion 199 (save-excursion
196 (message "Loading MH aliases...") 200 (message "Loading MH aliases...")
197 (mh-alias-tstamp t) 201 (mh-alias-tstamp t)
198 (mh-exec-cmd-quiet t "ali" "-nolist" "-nouser") 202 (mh-exec-cmd-quiet t "ali" "-nolist" "-nouser")
236 ;;; Alias Expansion 240 ;;; Alias Expansion
237 241
238 (defun mh-alias-ali (alias &optional user) 242 (defun mh-alias-ali (alias &optional user)
239 "Return ali expansion for ALIAS. 243 "Return ali expansion for ALIAS.
240 ALIAS must be a string for a single alias. 244 ALIAS must be a string for a single alias.
241 If USER is t, then assume ALIAS is an address and call ali -user. 245 If USER is t, then assume ALIAS is an address and call ali -user. ali
242 ali returns the string unchanged if not defined. The same is done here." 246 returns the string unchanged if not defined. The same is done here."
243 (condition-case err 247 (condition-case err
244 (save-excursion 248 (save-excursion
245 (let ((user-arg (if user "-user" "-nouser"))) 249 (let ((user-arg (if user "-user" "-nouser")))
246 (mh-exec-cmd-quiet t "ali" user-arg "-nolist" alias)) 250 (mh-exec-cmd-quiet t "ali" user-arg "-nolist" alias))
247 (goto-char (point-max)) 251 (goto-char (point-max))
320 324
321 ;;; Adding addresses to alias file. 325 ;;; Adding addresses to alias file.
322 326
323 (defun mh-alias-suggest-alias (string &optional no-comma-swap) 327 (defun mh-alias-suggest-alias (string &optional no-comma-swap)
324 "Suggest an alias for STRING. 328 "Suggest an alias for STRING.
325 Don't reverse the order of strings separated by a comma if NO-COMMA-SWAP is 329 Don't reverse the order of strings separated by a comma if
326 non-nil." 330 NO-COMMA-SWAP is non-nil."
327 (cond 331 (cond
328 ((string-match "^<\\(.*\\)>$" string) 332 ((string-match "^<\\(.*\\)>$" string)
329 ;; <somename@foo.bar> -> recurse, stripping brackets. 333 ;; <somename@foo.bar> -> recurse, stripping brackets.
330 (mh-alias-suggest-alias (match-string 1 string) no-comma-swap)) 334 (mh-alias-suggest-alias (match-string 1 string) no-comma-swap))
331 ((string-match "^\\sw+$" string) 335 ((string-match "^\\sw+$" string)
376 (mh-alias-canonicalize-suggestion string)))) 380 (mh-alias-canonicalize-suggestion string))))
377 381
378 (defun mh-alias-canonicalize-suggestion (string) 382 (defun mh-alias-canonicalize-suggestion (string)
379 "Process STRING to replace spaces by periods. 383 "Process STRING to replace spaces by periods.
380 First all spaces and commas are replaced by periods. Then every run of 384 First all spaces and commas are replaced by periods. Then every run of
381 consecutive periods are replaced with a single period. Finally the string 385 consecutive periods are replaced with a single period. Finally the
382 is converted to lower case." 386 string is converted to lower case."
383 (with-temp-buffer 387 (with-temp-buffer
384 (insert string) 388 (insert string)
385 ;; Replace spaces with periods 389 ;; Replace spaces with periods
386 (goto-char (point-min)) 390 (goto-char (point-min))
387 (while (re-search-forward " +" nil t) 391 (while (re-search-forward " +" nil t)
415 (setq the-list (cdr the-list))))) 419 (setq the-list (cdr the-list)))))
416 found))) 420 found)))
417 421
418 (defun mh-alias-insert-file (&optional alias) 422 (defun mh-alias-insert-file (&optional alias)
419 "Return filename which should be used to add ALIAS. 423 "Return filename which should be used to add ALIAS.
420 The value of the option `mh-alias-insert-file' is used if non-nil\; otherwise 424 The value of the option `mh-alias-insert-file' is used if non-nil\;
421 the value of the `Aliasfile:' profile component is used. 425 otherwise the value of the `Aliasfile:' profile component is used.
422 If the alias already exists, try to return the name of the file that contains 426 If the alias already exists, try to return the name of the file that
423 it." 427 contains it."
424 (cond 428 (cond
425 ((and mh-alias-insert-file (listp mh-alias-insert-file)) 429 ((and mh-alias-insert-file (listp mh-alias-insert-file))
426 (if (not (elt mh-alias-insert-file 1)) ; Only one entry, use it 430 (if (not (elt mh-alias-insert-file 1)) ; Only one entry, use it
427 (car mh-alias-insert-file) 431 (car mh-alias-insert-file)
428 (if (or (not alias) 432 (if (or (not alias)
486 (and from-header 490 (and from-header
487 (mh-alias-address-to-alias from-header)))))) 491 (mh-alias-address-to-alias from-header))))))
488 492
489 (defun mh-alias-add-alias-to-file (alias address &optional file) 493 (defun mh-alias-add-alias-to-file (alias address &optional file)
490 "Add ALIAS for ADDRESS in alias FILE without alias check or prompts. 494 "Add ALIAS for ADDRESS in alias FILE without alias check or prompts.
491 Prompt for alias file if not provided and there is more than one candidate. 495 Prompt for alias file if not provided and there is more than one
492 496 candidate.
493 If the alias exists already, you will have the choice of inserting the new 497
494 alias before or after the old alias. In the former case, this alias will be 498 If the alias exists already, you will have the choice of
495 used when sending mail to this alias. In the latter case, the alias serves as 499 inserting the new alias before or after the old alias. In the
496 an additional folder name hint when filing messages." 500 former case, this alias will be used when sending mail to this
501 alias. In the latter case, the alias serves as an additional
502 folder name hint when filing messages."
497 (if (not file) 503 (if (not file)
498 (setq file (mh-alias-insert-file alias))) 504 (setq file (mh-alias-insert-file alias)))
499 (save-excursion 505 (save-excursion
500 (set-buffer (find-file-noselect file)) 506 (set-buffer (find-file-noselect file))
501 (goto-char (point-min)) 507 (goto-char (point-min))
541 (save-buffer))) 547 (save-buffer)))
542 548
543 ;;;###mh-autoload 549 ;;;###mh-autoload
544 (defun mh-alias-add-alias (alias address) 550 (defun mh-alias-add-alias (alias address)
545 "*Add ALIAS for ADDRESS in personal alias file. 551 "*Add ALIAS for ADDRESS in personal alias file.
546 This function prompts you for an alias and address. If the alias exists 552 This function prompts you for an alias and address. If the alias
547 already, you will have the choice of inserting the new alias before or after 553 exists already, you will have the choice of inserting the new
548 the old alias. In the former case, this alias will be used when sending mail 554 alias before or after the old alias. In the former case, this
549 to this alias. In the latter case, the alias serves as an additional folder 555 alias will be used when sending mail to this alias. In the latter
550 name hint when filing messages." 556 case, the alias serves as an additional folder name hint when
557 filing messages."
551 (interactive "P\nP") 558 (interactive "P\nP")
552 (mh-alias-reload-maybe) 559 (mh-alias-reload-maybe)
553 (setq alias (completing-read "Alias: " mh-alias-alist nil nil alias)) 560 (setq alias (completing-read "Alias: " mh-alias-alist nil nil alias))
554 (if (and address (string-match "^<\\(.*\\)>$" address)) 561 (if (and address (string-match "^<\\(.*\\)>$" address))
555 (setq address (match-string 1 address))) 562 (setq address (match-string 1 address)))