comparison lisp/mail/mail-utils.el @ 44026:55bcbf42cf3f

(rmail-dont-reply-to): Overhaul to correctly apply the regular expressions in the variable `rmail-dont-reply-to-names' to the list of destination addresses. Contributed by lorentey@elte.hu.
author Paul Reilly <pmr@pajato.com>
date Tue, 19 Mar 2002 19:42:46 +0000
parents 16d2187c5524
children 588b5b177b8a
comparison
equal deleted inserted replaced
44025:5766d225ccf3 44026:55bcbf42cf3f
195 address)) 195 address))
196 (setq address (replace-match (match-string 3 address) 196 (setq address (replace-match (match-string 3 address)
197 nil 'literal address 2))) 197 nil 'literal address 2)))
198 address)))) 198 address))))
199 199
200 ; rmail-dont-reply-to-names is defined in loaddefs 200 ;;; The following piece of ugliness is legacy code. The name was an
201 (defun rmail-dont-reply-to (userids) 201 ;;; unfortunate choice --- a flagrant violation of the Emacs Lisp
202 "Returns string of mail addresses USERIDS sans any recipients 202 ;;; coding conventions. `mail-dont-reply-to' would have been
203 that start with matches for `rmail-dont-reply-to-names'. 203 ;;; infinitely better. Also, `rmail-dont-reply-to-names' might have
204 Usenet paths ending in an element that matches are removed also." 204 ;;; been better named `mail-dont-reply-to-names' and sourced from this
205 ;;; file instead of in rmail.el. Yuck. -pmr
206 (defun rmail-dont-reply-to (destinations)
207 "Prune addresses from DESTINATIONS, a list of recipient addresses.
208 All addresses matching `rmail-dont-reply-to-names' are removed from
209 the comma-separated list. The pruned list is returned."
205 (if (null rmail-dont-reply-to-names) 210 (if (null rmail-dont-reply-to-names)
206 (setq rmail-dont-reply-to-names 211 (setq rmail-dont-reply-to-names
207 (concat (if rmail-default-dont-reply-to-names 212 (concat (if rmail-default-dont-reply-to-names
208 (concat rmail-default-dont-reply-to-names "\\|") 213 (concat rmail-default-dont-reply-to-names "\\|")
209 "") 214 "")
210 (concat (regexp-quote (user-login-name)) 215 (if (and user-mail-address
211 "\\>")))) 216 (not (equal user-mail-address user-login-name)))
212 (let ((match (concat "\\(^\\|,\\)[ \t\n]*" 217 (concat (regexp-quote user-mail-address) "\\|")
213 ;; Can anyone figure out what this is for? 218 "")
214 ;; Is it an obsolete remnant of another way of 219 (concat (regexp-quote user-login-name) "\\>"))))
215 ;; handling Foo Bar <foo@machine>? 220 ;; Split up DESTINATIONS and match each element separately.
216 "\\([^,\n]*[!<]\\|\\)" 221 (let ((start-pos 0) (cur-pos 0)
217 "\\(" 222 (case-fold-search t))
218 rmail-dont-reply-to-names 223 (while start-pos
219 "\\|" 224 (setq cur-pos (string-match "[,\"]" destinations cur-pos))
220 ;; Include the human name that precedes <foo@bar>. 225 (if (and cur-pos (equal (match-string 0 destinations) "\""))
221 "\\([^\,.<\"]\\|\"[^\"]*\"\\)*" 226 ;; Search for matching quote.
222 "<\\(" rmail-dont-reply-to-names "\\)" 227 (let ((next-pos (string-match "\"" destinations (1+ cur-pos))))
223 "\\)[^,]*")) 228 (if next-pos
224 (case-fold-search t) 229 (setq cur-pos (1+ next-pos))
225 pos epos)
226 (while (and (setq pos (string-match match userids pos))
227 (> (length userids) 0))
228 ;; If there's a match, it starts at the beginning of the string,
229 ;; or with `,'. We must delete from that position to the
230 ;; end of the user-id which starts at match-beginning 2.
231 (let (inside-quotes quote-pos last-quote-pos)
232 (save-match-data
233 (while (and (setq quote-pos (string-match "\"" userids quote-pos))
234 (< quote-pos pos))
235 (setq last-quote-pos quote-pos)
236 (setq quote-pos (1+ quote-pos))
237 (setq inside-quotes (not inside-quotes))))
238 (if inside-quotes
239 (if (string-match "\"" userids pos)
240 (setq pos (string-match "\"" userids pos))
241 ;; If the open-quote has no close-quote, 230 ;; If the open-quote has no close-quote,
242 ;; delete the open-quote to get something well-defined. 231 ;; delete the open-quote to get something well-defined.
243 ;; This case is not valid, but it can happen if things 232 ;; This case is not valid, but it can happen if things
244 ;; are weird elsewhere. 233 ;; are weird elsewhere.
245 (setq userids (replace-match "" nil nil userids)) 234 (setq destinations (concat (substring destinations 0 cur-pos)
246 (setq userids (concat (substring userids 0 last-quote-pos) 235 (substring destinations (1+ cur-pos))))
247 (substring userids (1+ last-quote-pos)))) 236 (setq cur-pos start-pos)))
248 (setq pos (1- pos))) 237 (let* ((address (substring destinations start-pos cur-pos))
249 (setq userids (replace-match "" nil nil userids))))) 238 (naked-address (mail-strip-quoted-names address)))
250 ;; get rid of any trailing commas 239 (if (string-match rmail-dont-reply-to-names naked-address)
251 (if (setq pos (string-match "[ ,\t\n]*\\'" userids)) 240 (setq destinations (concat (substring destinations 0 start-pos)
252 (setq userids (substring userids 0 pos))) 241 (and cur-pos (substring destinations
253 ;; remove leading spaces. they bother me. 242 (1+ cur-pos))))
254 (if (string-match "\\(\\s \\|,\\)*" userids) 243 cur-pos start-pos)
255 (substring userids (match-end 0)) 244 (setq cur-pos (and cur-pos (1+ cur-pos))
256 userids))) 245 start-pos cur-pos))))))
246 ;; get rid of any trailing commas
247 (if (setq pos (string-match "[ ,\t\n]*\\'" destinations))
248 (setq destinations (substring destinations 0 pos)))
249 ;; remove leading spaces. they bother me.
250 (if (string-match "\\(\\s \\|,\\)*" destinations)
251 (substring destinations (match-end 0))
252 destinations))
257 253
258 254
259 ;;;###autoload 255 ;;;###autoload
260 (defun mail-fetch-field (field-name &optional last all list) 256 (defun mail-fetch-field (field-name &optional last all list)
261 "Return the value of the header field whose type is FIELD-NAME. 257 "Return the value of the header field whose type is FIELD-NAME.