comparison lisp/mail/mailalias.el @ 7971:e02c5d5d76cd

(define-mail-alias): Copy parsing code from mailabbrev.el. New arg from-mailrc-file. (build-mail-aliases): Pass t as new arg.
author Richard M. Stallman <rms@gnu.org>
date Sun, 19 Jun 1994 19:52:02 +0000
parents d8bede4feaed
children ae554ccf4fb5
comparison
equal deleted inserted replaced
7970:d8bede4feaed 7971:e02c5d5d76cd
149 (let* ((name (buffer-substring (match-beginning 0) (match-end 0))) 149 (let* ((name (buffer-substring (match-beginning 0) (match-end 0)))
150 (start (progn (skip-chars-forward " \t") (point)))) 150 (start (progn (skip-chars-forward " \t") (point))))
151 (end-of-line) 151 (end-of-line)
152 (define-mail-alias 152 (define-mail-alias
153 name 153 name
154 (buffer-substring start (point))))) 154 (buffer-substring start (point))
155 t)))
155 mail-aliases) 156 mail-aliases)
156 (if buffer (kill-buffer buffer)) 157 (if buffer (kill-buffer buffer))
157 (set-buffer obuf)))) 158 (set-buffer obuf))))
158 159
159 ;; Always autoloadable in case the user wants to define aliases 160 ;; Always autoloadable in case the user wants to define aliases
160 ;; interactively or in .emacs. 161 ;; interactively or in .emacs.
161 ;;;###autoload 162 ;;;###autoload
162 (defun define-mail-alias (name definition) 163 (defun define-mail-alias (name definition &optional from-mailrc-file)
163 "Define NAME as a mail alias that translates to DEFINITION. 164 "Define NAME as a mail alias that translates to DEFINITION.
164 This means that sending a message to NAME will actually send to DEFINITION. 165 This means that sending a message to NAME will actually send to DEFINITION.
165 DEFINITION can be one or more mail addresses separated by spaces. 166 DEFINITION can be one or more mail addresses separated by spaces.
166 An address can contain spaces if it is quoted with double-quotes." 167 An address can contain spaces if it is quoted with double-quotes."
167 (interactive "sDefine mail alias: \nsDefine %s as mail alias for: ") 168 (interactive "sDefine mail alias: \nsDefine %s as mail alias for: ")
174 ;; strip garbage from front and end 175 ;; strip garbage from front and end
175 (if (string-match "\\`[ \t\n,]+" definition) 176 (if (string-match "\\`[ \t\n,]+" definition)
176 (setq definition (substring definition (match-end 0)))) 177 (setq definition (substring definition (match-end 0))))
177 (if (string-match "[ \t\n,]+\\'" definition) 178 (if (string-match "[ \t\n,]+\\'" definition)
178 (setq definition (substring definition 0 (match-beginning 0)))) 179 (setq definition (substring definition 0 (match-beginning 0))))
179 (let ((first (aref definition 0)) 180 (let ((result '())
180 (last (aref definition (1- (length definition)))) 181 (start 0)
181 tem) 182 (L (length definition))
182 (if (and (= first last) (memq first '(?\' ?\"))) 183 end tem)
183 ;; Strip quotation marks. 184 (while start
184 (setq definition (substring definition 1 (1- (length definition)))) 185 ;; If we're reading from the mailrc file, then addresses are delimited
185 ;; ~/.mailrc contains addresses separated by spaces. 186 ;; by spaces, and addresses with embedded spaces must be surrounded by
186 ;; Mailers should expect addresses separated by commas. 187 ;; double-quotes. Otherwise, addresses are separated by commas.
187 (while (setq tem (string-match "[^ \t,][ \t,]+" definition tem)) 188 (if from-mailrc-file
188 (if (= (match-end 0) (length definition)) 189 (if (eq ?\" (aref definition start))
189 (setq definition (substring definition 0 (1+ tem))) 190 (setq start (1+ start)
190 (setq definition (concat (substring definition 191 end (string-match "\"[ \t,]*" definition start))
191 0 (1+ tem)) 192 (setq end (string-match "[ \t,]+" definition start)))
192 ", " 193 (setq end (string-match "[ \t\n,]*,[ \t\n,]*" definition start)))
193 (substring definition (match-end 0)))) 194 (setq result (cons (substring definition start end) result))
194 (setq tem (+ 3 tem))))) 195 (setq start (and end
196 (/= (match-end 0) L)
197 (match-end 0))))
198 (setq definition (mapconcat (function identity)
199 (nreverse result)
200 ", "))
195 (setq tem (assoc name mail-aliases)) 201 (setq tem (assoc name mail-aliases))
196 (if tem 202 (if tem
197 (rplacd tem definition) 203 (rplacd tem definition)
198 (setq mail-aliases (cons (cons name definition) mail-aliases))))) 204 (setq mail-aliases (cons (cons name definition) mail-aliases)))))
199 205