changeset 12458:a83478662820

(sendmail-send-it): If mail-from-style is parens, don't escape all parentheses; escape only the nonmatching ones.
author Richard M. Stallman <rms@gnu.org>
date Sat, 01 Jul 1995 00:33:52 +0000
parents 960edccb320d
children d1da7f16002c
files lisp/mail/sendmail.el
diffstat 1 files changed, 18 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/mail/sendmail.el	Fri Jun 30 23:43:45 1995 +0000
+++ b/lisp/mail/sendmail.el	Sat Jul 01 00:33:52 1995 +0000
@@ -537,12 +537,24 @@
 				 (insert "\""))))
 			 (insert " <" login ">\n"))
 			((eq mail-from-style 'parens)
-			 (insert "From: " login " (" fullname)
-			 (let ((fullname-end (point-marker)))
-			   (backward-char (length fullname))
-			   ;; RFC 822 says ()\ must be escaped in comments.
-			   (while (re-search-forward "[()\\]" fullname-end 1)
-			     (replace-match "\\\\\\&" t)))
+			 (insert "From: " login " (")
+			 (let ((fullname-start (point)))
+			   (insert fullname)
+			   (let ((fullname-end (point-marker)))
+			     (goto-char fullname-start)
+			     ;; RFC 822 says \ and nonmatching parentheses
+			     ;; must be escaped in comments.
+			     ;; Escape every instance of ()\ ...
+			     (while (re-search-forward "[()\\]" fullname-end 1)
+			       (replace-match "\\\\\\&" t))
+			     ;; ... then undo escaping of matching parentheses,
+			     ;; including matching nested parentheses.
+			     (goto-char fullname-start)
+			     (while (re-search-forward 
+				     "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
+				     fullname-end 1)
+			       (replace-match "\\1(\\3)" t)
+			       (goto-char fullname-start))))
 			 (insert ")\n"))
 			((null mail-from-style)
 			 (insert "From: " login "\n")))))