aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/mail
diff options
context:
space:
mode:
authorRichard M. Stallman2000-07-19 21:53:51 +0000
committerRichard M. Stallman2000-07-19 21:53:51 +0000
commit82d221935c6d173b4e84ca80fd04ebcc2b85470d (patch)
tree8e57a9e99eb87f1c86cb87123fb3b1d53d0a9886 /lisp/mail
parent30729019bed29ab72a3252eb13c29ecba75ef4a5 (diff)
downloademacs-82d221935c6d173b4e84ca80fd04ebcc2b85470d.tar.gz
emacs-82d221935c6d173b4e84ca80fd04ebcc2b85470d.zip
(mail-strip-quoted-names): Handle case where <...> appears inside "...".
Use replace-match to edit the string more simply. (rmail-dont-reply-to): Cope with an unmatched ".
Diffstat (limited to 'lisp/mail')
-rw-r--r--lisp/mail/mail-utils.el41
1 files changed, 22 insertions, 19 deletions
diff --git a/lisp/mail/mail-utils.el b/lisp/mail/mail-utils.el
index 8af7e0a0f32..a5d7a6b248c 100644
--- a/lisp/mail/mail-utils.el
+++ b/lisp/mail/mail-utils.el
@@ -147,8 +147,7 @@ Return a modified address list."
147 ;; Detect nested comments. 147 ;; Detect nested comments.
148 (if (string-match "[ \t]*(\\([^)\\]\\|\\\\.\\|\\\\\n\\)*(" address) 148 (if (string-match "[ \t]*(\\([^)\\]\\|\\\\.\\|\\\\\n\\)*(" address)
149 ;; Strip nested comments. 149 ;; Strip nested comments.
150 (save-excursion 150 (with-current-buffer (get-buffer-create " *temp*")
151 (set-buffer (get-buffer-create " *temp*"))
152 (erase-buffer) 151 (erase-buffer)
153 (insert address) 152 (insert address)
154 (set-syntax-table lisp-mode-syntax-table) 153 (set-syntax-table lisp-mode-syntax-table)
@@ -170,9 +169,7 @@ Return a modified address list."
170 ;; `(xyzzy (foo) whinge)' properly. Big deal. 169 ;; `(xyzzy (foo) whinge)' properly. Big deal.
171 "[ \t]*(\\([^)\\]\\|\\\\.\\|\\\\\n\\)*)" 170 "[ \t]*(\\([^)\\]\\|\\\\.\\|\\\\\n\\)*)"
172 address)) 171 address))
173 (setq address 172 (setq address (replace-match "" nil nil address 0))))
174 (mail-string-delete address
175 pos (match-end 0)))))
176 173
177 ;; strip surrounding whitespace 174 ;; strip surrounding whitespace
178 (string-match "\\`[ \t\n]*" address) 175 (string-match "\\`[ \t\n]*" address)
@@ -184,23 +181,20 @@ Return a modified address list."
184 ;; strip `quoted' names (This is supposed to hack `"Foo Bar" <bar@host>') 181 ;; strip `quoted' names (This is supposed to hack `"Foo Bar" <bar@host>')
185 (setq pos 0) 182 (setq pos 0)
186 (while (setq pos (string-match 183 (while (setq pos (string-match
187 "\\([ \t]?\\)[ \t]*\"\\([^\"\\]\\|\\\\.\\|\\\\\n\\)*\"[ \t\n]*" 184 "\\([ \t]?\\)\\([ \t]*\"\\([^\"\\]\\|\\\\.\\|\\\\\n\\)*\"[ \t\n]*\\)"
188 address pos)) 185 address pos))
189 ;; If the next thing is "@", we have "foo bar"@host. Leave it. 186 ;; If the next thing is "@", we have "foo bar"@host. Leave it.
190 (if (and (> (length address) (match-end 0)) 187 (if (and (> (length address) (match-end 0))
191 (= (aref address (match-end 0)) ?@)) 188 (= (aref address (match-end 0)) ?@))
192 (setq pos (match-end 0)) 189 (setq pos (match-end 0))
193 (setq address 190 ;; Otherwise discard the "..." part.
194 (mail-string-delete address 191 (setq address (replace-match "" nil nil address 2))))
195 (match-end 1) (match-end 0))))) 192 ;; If this address contains <...>, replace it with just
196 ;; Retain only part of address in <> delims, if there is such a thing. 193 ;; the part between the <...>.
197 (while (setq pos (string-match "\\(,\\s-*\\|\\`\\)[^,]*<\\([^>,:]*>\\)" 194 (while (setq pos (string-match "\\(,\\s-*\\|\\`\\)\\([^,]*<\\([^>,:]*\\)>[^,]*\\)\\(\\s-*,\\|\\'\\)"
198 address)) 195 address))
199 (let ((junk-beg (match-end 1)) 196 (setq address (replace-match (match-string 3 address)
200 (junk-end (match-beginning 2)) 197 nil nil address 2)))
201 (close (match-end 0)))
202 (setq address (mail-string-delete address (1- close) close))
203 (setq address (mail-string-delete address junk-beg junk-end))))
204 address)))) 198 address))))
205 199
206; rmail-dont-reply-to-names is defined in loaddefs 200; rmail-dont-reply-to-names is defined in loaddefs
@@ -233,15 +227,24 @@ Usenet paths ending in an element that matches are removed also."
233 ;; If there's a match, it starts at the beginning of the string, 227 ;; If there's a match, it starts at the beginning of the string,
234 ;; or with `,'. We must delete from that position to the 228 ;; or with `,'. We must delete from that position to the
235 ;; end of the user-id which starts at match-beginning 2. 229 ;; end of the user-id which starts at match-beginning 2.
236 (let (inside-quotes quote-pos) 230 (let (inside-quotes quote-pos last-quote-pos)
237 (save-match-data 231 (save-match-data
238 (while (and (setq quote-pos (string-match "\"" userids quote-pos)) 232 (while (and (setq quote-pos (string-match "\"" userids quote-pos))
239 (< quote-pos pos)) 233 (< quote-pos pos))
234 (setq last-quote-pos quote-pos)
240 (setq quote-pos (1+ quote-pos)) 235 (setq quote-pos (1+ quote-pos))
241 (setq inside-quotes (not inside-quotes)))) 236 (setq inside-quotes (not inside-quotes))))
242 (if inside-quotes 237 (if inside-quotes
243 ;; Advance to next even-parity quote, and scan from there. 238 (if (string-match "\"" userids pos)
244 (setq pos (string-match "\"" userids pos)) 239 (setq pos (string-match "\"" userids pos))
240 ;; If the open-quote has no close-quote,
241 ;; delete the open-quote to get something well-defined.
242 ;; This case is not valid, but it can happen if things
243 ;; are weird elsewhere.
244 (setq userids (replace-match "" nil nil userids))
245 (setq userids (concat (substring userids 0 last-quote-pos)
246 (substring userids (1+ last-quote-pos))))
247 (setq pos (1- pos)))
245 (setq userids (replace-match "" nil nil userids))))) 248 (setq userids (replace-match "" nil nil userids)))))
246 ;; get rid of any trailing commas 249 ;; get rid of any trailing commas
247 (if (setq pos (string-match "[ ,\t\n]*\\'" userids)) 250 (if (setq pos (string-match "[ ,\t\n]*\\'" userids))