(rmail-dont-reply-to): Understand
authorRichard M. Stallman <rms@gnu.org>
Tue, 7 Jul 1998 20:47:36 +0000 (20:47 +0000)
committerRichard M. Stallman <rms@gnu.org>
Tue, 7 Jul 1998 20:47:36 +0000 (20:47 +0000)
about doublequotes; don't be fooled by commas inside them.

lisp/mail/mail-utils.el

index 849fb51..cc71c1a 100644 (file)
@@ -184,22 +184,40 @@ Usenet paths ending in an element that matches are removed also."
                        "")
                    (concat (regexp-quote (user-login-name))
                            "\\>"))))
-  (let ((match (concat "\\(^\\|,\\)[ \t\n]*\\([^,\n]*[!<]\\|\\)\\("
-                      rmail-dont-reply-to-names
-                      "\\|[^\,.<]*<\\(" rmail-dont-reply-to-names "\\)"
+  (let ((match (concat "\\(^\\|,\\)[ \t\n]*"
+                      ;; Can anyone figure out what this is for?
+                      ;; Is it an obsolete remnant of another way of
+                      ;; handling Foo Bar <foo@machine>?
+                      "\\([^,\n]*[!<]\\|\\)"
+                      "\\("
+                            rmail-dont-reply-to-names
+                      "\\|"
+                            ;; Include the human name that precedes <foo@bar>.
+                            "\\([^\,.<\"]\\|\"[^\"]*\"\\)*"
+                            "<\\(" rmail-dont-reply-to-names "\\)"
                       "\\)"))
        (case-fold-search t)
        pos epos)
-    (while (setq pos (string-match match userids))
+    (while (setq pos (string-match match userids pos))
       (if (> pos 0) (setq pos (match-beginning 2)))
       (setq epos
            ;; Delete thru the next comma, plus whitespace after.
            (if (string-match ",[ \t\n]*" userids (match-end 0))
                (match-end 0)
              (length userids)))
-      (setq userids
-           (mail-string-delete
-             userids pos epos)))
+      ;; Count the double-quotes since the beginning of the list.
+      ;; Reject this match if it is inside a pair of doublequotes.
+      (let (quote-pos inside-quotes)
+       (while (and (setq quote-pos (string-match "\"" userids quote-pos))
+                   (< quote-pos pos))
+         (setq quote-pos (1+ quote-pos))
+         (setq inside-quotes (not inside-quotes)))
+       (if inside-quotes
+           ;; Advance to next even-parity quote, and scan from there.
+           (setq pos (string-match "\"" userids pos))
+         (setq userids
+               (mail-string-delete
+                userids pos epos)))))
     ;; get rid of any trailing commas
     (if (setq pos (string-match "[ ,\t\n]*\\'" userids))
        (setq userids (substring userids 0 pos)))