Function: rfc822-addresses-1
rfc822-addresses-1 is a byte-compiled function defined in
rfc822.el.gz.
Signature
(rfc822-addresses-1 &optional ALLOW-GROUPS)
Source Code
;; Defined in /usr/src/emacs/lisp/mail/rfc822.el.gz
;; return either an address (a string) or a list of addresses
(defun rfc822-addresses-1 (&optional allow-groups)
;; Looking for an rfc822 `address'
;; Either a group (1*word ":" [#mailbox] ";")
;; or a mailbox (addr-spec | 1*word route-addr)
;; addr-spec is (local-part "@" domain)
;; route-addr is ("<" [1#("@" domain) ":"] addr-spec ">")
;; local-part is (word *("." word))
;; word is (atom | quoted-string)
;; quoted-string is ("\([^\"\\n]\|\\.\|\\\n\)")
;; atom is [^\000-\037\177 ()<>@,;:\".[]]+
;; domain is sub-domain *("." sub-domain)
;; sub-domain is domain-ref | domain-literal
;; domain-literal is "[" *(dtext | quoted-pair) "]"
;; dtext is "[^][\\n"
;; domain-ref is atom
(let ((rfc822-address-start (point))
(n 0))
(catch 'address
;; optimize common cases:
;; foo
;; foo.bar@bar.zap
;; followed by "\\'\\|,\\|([^()\\]*)\\'"
;; other common cases are:
;; foo bar <foo.bar@baz.zap>
;; "foo bar" <foo.bar@baz.zap>
;; those aren't hacked yet.
(if (and (rfc822-looking-at "[^][\000-\037 ()<>@,;:\\\"]+\\(\\|@[^][\000-\037 ()<>@,;:\\\"]+\\)" t)
(progn (or (eobp)
(rfc822-looking-at ?,))))
(progn
;; rfc822-looking-at may have inserted a space
(or (bobp) (/= (preceding-char) ?\ ) (delete-char -1))
;; relying on the fact that rfc822-looking-at <char>
;; doesn't mung match-data
(throw 'address (buffer-substring rfc822-address-start (match-end 0)))))
(goto-char rfc822-address-start)
(while t
(cond ((and (= n 1) (rfc822-looking-at ?@))
;; local-part@domain
(rfc822-snarf-domain)
(throw 'address
(buffer-substring rfc822-address-start (point))))
((rfc822-looking-at ?:)
(cond ((not allow-groups)
(rfc822-bad-address "A group name may not appear here"))
((= n 0)
(rfc822-bad-address "No name for :...; group")))
;; group
(throw 'address
;; return a list of addresses
(rfc822-snarf-frob-list ":...; group" ?\, ?\;
'rfc822-addresses-1 t)))
((rfc822-looking-at ?<)
(let ((start (point))
(strip t))
(cond ((rfc822-looking-at ?>)
;; empty path
())
((and (not (eobp)) (= (following-char) ?\@))
;; <@foo.bar,@baz:quux@abcd.efg>
(rfc822-snarf-frob-list "<...> address" ?\, ?\:
(lambda ()
(if (rfc822-looking-at ?\@)
(rfc822-snarf-domain)
(rfc822-bad-address
"Gubbish in route-addr"))))
(rfc822-snarf-words)
(or (rfc822-looking-at ?@)
(rfc822-bad-address "Malformed <..@..> address"))
(rfc822-snarf-domain)
(setq strip nil))
((progn (rfc822-snarf-words) (rfc822-looking-at ?@))
; allow <foo> (losing unix seems to do this)
(rfc822-snarf-domain)))
(let ((end (point)))
(if (rfc822-looking-at ?\>)
(throw 'address
(buffer-substring (if strip start (1- start))
(if strip end (1+ end))))
(rfc822-bad-address "Unterminated <...> address")))))
((looking-at "[^][\000-\037 ()<>@,;:\\.]")
;; this allows "." to be part of the words preceding
;; an addr-spec, since many broken mailers output
;; "Hern K. Herklemeyer III
;; <yank@megadeath.dod.gods-own-country>"
(let ((again t))
(while again
(or (= n 0) (bobp) (= (preceding-char) ?\ )
(insert ?\ ))
(rfc822-snarf-words)
(setq n (1+ n))
(setq again (or (rfc822-looking-at ?.)
(looking-at "[^][\000-\037 ()<>@,;:\\.]"))))))
((= n 0)
(throw 'address nil))
((= n 1) ; allow "foo" (losing unix seems to do this)
(throw 'address
(buffer-substring rfc822-address-start (point))))
((> n 1)
(rfc822-bad-address "Missing comma between addresses or badly-formatted address"))
((or (eobp) (= (following-char) ?,))
(rfc822-bad-address "Missing comma or route-spec"))
(t
(rfc822-bad-address "Strange character or missing comma")))))))