]> code.delx.au - gnu-emacs/commitdiff
(sendmail-send-it): If mail-from-style is parens,
authorRichard M. Stallman <rms@gnu.org>
Sat, 1 Jul 1995 00:33:52 +0000 (00:33 +0000)
committerRichard M. Stallman <rms@gnu.org>
Sat, 1 Jul 1995 00:33:52 +0000 (00:33 +0000)
don't escape all parentheses; escape only the nonmatching ones.

lisp/mail/sendmail.el

index f30581cbb2a00c6a14169f8f119055ab989a65a3..f54b52cb4b5008c06c889a271d6e29f7a2a33ffe 100644 (file)
@@ -537,12 +537,24 @@ the user from the mailer."
                                 (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")))))