changeset 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 f2c73ebe4013
files lisp/mail/mailalias.el
diffstat 1 files changed, 24 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/mail/mailalias.el	Sun Jun 19 19:42:17 1994 +0000
+++ b/lisp/mail/mailalias.el	Sun Jun 19 19:52:02 1994 +0000
@@ -151,7 +151,8 @@
 	      (end-of-line)
 	      (define-mail-alias
 		name
-		(buffer-substring start (point)))))
+		(buffer-substring start (point))
+		t)))
 	  mail-aliases)
       (if buffer (kill-buffer buffer))
       (set-buffer obuf))))
@@ -159,7 +160,7 @@
 ;; Always autoloadable in case the user wants to define aliases
 ;; interactively or in .emacs.
 ;;;###autoload
-(defun define-mail-alias (name definition)
+(defun define-mail-alias (name definition &optional from-mailrc-file)
   "Define NAME as a mail alias that translates to DEFINITION.
 This means that sending a message to NAME will actually send to DEFINITION.
 DEFINITION can be one or more mail addresses separated by spaces.
@@ -176,22 +177,27 @@
       (setq definition (substring definition (match-end 0))))
   (if (string-match "[ \t\n,]+\\'" definition)
       (setq definition (substring definition 0 (match-beginning 0))))
-  (let ((first (aref definition 0))
-	(last (aref definition (1- (length definition))))
-	tem)
-    (if (and (= first last) (memq first '(?\' ?\")))
-	;; Strip quotation marks.
-	(setq definition (substring definition 1 (1- (length definition))))
-      ;; ~/.mailrc contains addresses separated by spaces.
-      ;; Mailers should expect addresses separated by commas.
-      (while (setq tem (string-match "[^ \t,][ \t,]+" definition tem))
-	(if (= (match-end 0) (length definition))
-	    (setq definition (substring definition 0 (1+ tem)))
-	  (setq definition (concat (substring definition
-					      0 (1+ tem))
-				   ", "
-				   (substring definition (match-end 0))))
-	  (setq tem (+ 3 tem)))))
+  (let ((result '())
+	(start 0)
+	(L (length definition))
+	end tem)
+    (while start
+      ;; If we're reading from the mailrc file, then addresses are delimited
+      ;; by spaces, and addresses with embedded spaces must be surrounded by
+      ;; double-quotes.  Otherwise, addresses are separated by commas.
+      (if from-mailrc-file
+	  (if (eq ?\" (aref definition start))
+	      (setq start (1+ start)
+		    end (string-match "\"[ \t,]*" definition start))
+	      (setq end (string-match "[ \t,]+" definition start)))
+	  (setq end (string-match "[ \t\n,]*,[ \t\n,]*" definition start)))
+      (setq result (cons (substring definition start end) result))
+      (setq start (and end
+		       (/= (match-end 0) L)
+		       (match-end 0))))
+    (setq definition (mapconcat (function identity)
+				(nreverse result)
+				", "))
     (setq tem (assoc name mail-aliases))
     (if tem
 	(rplacd tem definition)