mail-extr.el 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177
  1. ;;; mail-extr.el --- extract full name and address from RFC 822 mail header -*- coding: utf-8 -*-
  2. ;; Copyright (C) 1991-1994, 1997, 2001-2012 Free Software Foundation, Inc.
  3. ;; Author: Joe Wells <jbw@cs.bu.edu>
  4. ;; Maintainer: FSF
  5. ;; Keywords: mail
  6. ;; Package: mail-utils
  7. ;; This file is part of GNU Emacs.
  8. ;; GNU Emacs is free software: you can redistribute it and/or modify
  9. ;; it under the terms of the GNU General Public License as published by
  10. ;; the Free Software Foundation, either version 3 of the License, or
  11. ;; (at your option) any later version.
  12. ;; GNU Emacs is distributed in the hope that it will be useful,
  13. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;; GNU General Public License for more details.
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  18. ;;; Commentary:
  19. ;; The entry point of this code is
  20. ;;
  21. ;; mail-extract-address-components: (address &optional all)
  22. ;;
  23. ;; Given an RFC-822 ADDRESS, extract full name and canonical address.
  24. ;; Returns a list of the form (FULL-NAME CANONICAL-ADDRESS).
  25. ;; If no name can be extracted, FULL-NAME will be nil.
  26. ;; ADDRESS may be a string or a buffer. If it is a buffer, the visible
  27. ;; (narrowed) portion of the buffer will be interpreted as the address.
  28. ;; (This feature exists so that the clever caller might be able to avoid
  29. ;; consing a string.)
  30. ;; If ADDRESS contains more than one RFC-822 address, only the first is
  31. ;; returned.
  32. ;;
  33. ;; If ALL is non-nil, that means return info about all the addresses
  34. ;; that are found in ADDRESS. The value is a list of elements of
  35. ;; the form (FULL-NAME CANONICAL-ADDRESS), one per address.
  36. ;;
  37. ;; This code is more correct (and more heuristic) parser than the code in
  38. ;; rfc822.el. And despite its size, it's fairly fast.
  39. ;;
  40. ;; There are two main benefits:
  41. ;;
  42. ;; 1. Higher probability of getting the correct full name for a human than
  43. ;; any other package we know of. (On the other hand, it will cheerfully
  44. ;; mangle non-human names/comments.)
  45. ;; 2. Address part is put in a canonical form.
  46. ;;
  47. ;; The interface is not yet carved in stone; please give us suggestions.
  48. ;;
  49. ;; We have an extensive test-case collection of funny addresses if you want to
  50. ;; work with the code. Developing this code requires frequent testing to
  51. ;; make sure you're not breaking functionality. The test cases aren't included
  52. ;; because they are over 100K.
  53. ;;
  54. ;; If you find an address that mail-extr fails on, please send it to the
  55. ;; maintainer along with what you think the correct results should be. We do
  56. ;; not consider it a bug if mail-extr mangles a comment that does not
  57. ;; correspond to a real human full name, although we would prefer that
  58. ;; mail-extr would return the comment as-is.
  59. ;;
  60. ;; Features:
  61. ;;
  62. ;; * Full name handling:
  63. ;;
  64. ;; * knows where full names can be found in an address.
  65. ;; * avoids using empty comments and quoted text.
  66. ;; * extracts full names from mailbox names.
  67. ;; * recognizes common formats for comments after a full name.
  68. ;; * puts a period and a space after each initial.
  69. ;; * understands & referring to the mailbox name, capitalized.
  70. ;; * strips name prefixes like "Prof.", etc.
  71. ;; * understands what characters can occur in names (not just letters).
  72. ;; * figures out middle initial from mailbox name.
  73. ;; * removes funny nicknames.
  74. ;; * keeps suffixes such as Jr., Sr., III, etc.
  75. ;; * reorders "Last, First" type names.
  76. ;;
  77. ;; * Address handling:
  78. ;;
  79. ;; * parses rfc822 quoted text, comments, and domain literals.
  80. ;; * parses rfc822 multi-line headers.
  81. ;; * does something reasonable with rfc822 GROUP addresses.
  82. ;; * handles many rfc822 noncompliant and garbage addresses.
  83. ;; * canonicalizes addresses (after stripping comments/phrases outside <>).
  84. ;; * converts ! addresses into .UUCP and %-style addresses.
  85. ;; * converts rfc822 ROUTE addresses to %-style addresses.
  86. ;; * truncates %-style addresses at leftmost fully qualified domain name.
  87. ;; * handles local relative precedence of ! vs. % and @ (untested).
  88. ;;
  89. ;; It does almost no string creation. It primarily uses the built-in
  90. ;; parsing routines with the appropriate syntax tables. This should
  91. ;; result in greater speed.
  92. ;;
  93. ;; TODO:
  94. ;;
  95. ;; * handle all test cases. (This will take forever.)
  96. ;; * software to pick the correct header to use (eg., "Senders-Name:").
  97. ;; * multiple addresses in the "From:" header (almost all of the necessary
  98. ;; code is there).
  99. ;; * flag to not treat `,' as an address separator. (This is useful when
  100. ;; there is a "From:" header but no "Sender:" header, because then there
  101. ;; is only allowed to be one address.)
  102. ;; * mailbox name does not necessarily contain full name.
  103. ;; * fixing capitalization when it's all upper or lowercase. (Hard!)
  104. ;; * some of the domain literal handling is missing. (But I've never even
  105. ;; seen one of these in a mail address, so maybe no big deal.)
  106. ;; * arrange to have syntax tables byte-compiled.
  107. ;; * speed hacks.
  108. ;; * delete unused variables.
  109. ;; * arrange for testing with different relative precedences of ! vs. @
  110. ;; and %.
  111. ;; * insert documentation strings!
  112. ;; * handle X.400-gatewayed addresses according to RFC 1148.
  113. ;;; Change Log:
  114. ;;
  115. ;; Thu Feb 17 17:57:33 1994 Jamie Zawinski (jwz@lucid.com)
  116. ;;
  117. ;; * merged with jbw's latest version
  118. ;;
  119. ;; Wed Feb 9 21:56:27 1994 Jamie Zawinski (jwz@lucid.com)
  120. ;;
  121. ;; * high-bit chars in comments weren't treated as word syntax
  122. ;;
  123. ;; Sat Feb 5 03:13:40 1994 Jamie Zawinski (jwz@lucid.com)
  124. ;;
  125. ;; * call replace-match with fixed-case arg
  126. ;;
  127. ;; Thu Dec 16 21:56:45 1993 Jamie Zawinski (jwz@lucid.com)
  128. ;;
  129. ;; * some more cleanup, doc, added provide
  130. ;;
  131. ;; Tue Mar 23 21:23:18 1993 Joe Wells (jbw at csd.bu.edu)
  132. ;;
  133. ;; * Made mail-full-name-prefixes a user-customizable variable.
  134. ;; Allow passing the address as a buffer as well as a string.
  135. ;; Allow [ and ] as name characters (Finnish character set).
  136. ;;
  137. ;; Mon Mar 22 21:20:56 1993 Joe Wells (jbw at bigbird.bu.edu)
  138. ;;
  139. ;; * Handle "null" addresses. Handle = used for spacing in mailbox
  140. ;; name. Fix bug in handling of ROUTE-ADDR-type addresses that are
  141. ;; missing their brackets. Handle uppercase "JR". Extract full
  142. ;; names from X.400 addresses encoded in RFC-822. Fix bug in
  143. ;; handling of multiple addresses where first has trailing comment.
  144. ;; Handle more kinds of telephone extension lead-ins.
  145. ;;
  146. ;; Mon Mar 22 20:16:57 1993 Joe Wells (jbw at bigbird.bu.edu)
  147. ;;
  148. ;; * Handle HZ encoding for embedding GB encoded chinese characters.
  149. ;;
  150. ;; Mon Mar 22 00:46:12 1993 Joe Wells (jbw at bigbird.bu.edu)
  151. ;;
  152. ;; * Fixed too broad matching of ham radio call signs. Fixed bug in
  153. ;; handling an unmatched ' in a name string. Enhanced recognition
  154. ;; of when . in the mailbox name terminates the name portion.
  155. ;; Narrowed conversion of . to space to only the necessary
  156. ;; situation. Deal with VMS's stupid date stamps. Handle a unique
  157. ;; way of introducing an alternate address. Fixed spacing bug I
  158. ;; introduced in switching last name order. Fixed bug in handling
  159. ;; address with ! and % but no @. Narrowed the cases in which
  160. ;; certain trailing words are discarded.
  161. ;;
  162. ;; Sun Mar 21 21:41:06 1993 Joe Wells (jbw at bigbird.bu.edu)
  163. ;;
  164. ;; * Fixed bugs in handling GROUP addresses. Certain words in the
  165. ;; middle of a name no longer terminate it. Handle LISTSERV list
  166. ;; names. Ignore comment field containing mailbox name.
  167. ;;
  168. ;; Sun Mar 21 14:39:38 1993 Joe Wells (jbw at bigbird.bu.edu)
  169. ;;
  170. ;; * Moved variant-method code back into main function. Handle
  171. ;; underscores as spaces in comments. Handle leading nickname. Add
  172. ;; flag to ignore single-word names. Other changes.
  173. ;;
  174. ;; Mon Feb 1 22:23:31 1993 Joe Wells (jbw at bigbird.bu.edu)
  175. ;;
  176. ;; * Added in changes by Rod Whitby and Jamie Zawinski. This
  177. ;; includes the flag mail-extr-guess-middle-initial and the fix for
  178. ;; handling multiple addresses correctly. (Whitby just changed
  179. ;; a > to a <.)
  180. ;;
  181. ;; Mon Apr 6 23:59:09 1992 Joe Wells (jbw at bigbird.bu.edu)
  182. ;;
  183. ;; * Cleaned up some more. Release version 1.0 to world.
  184. ;;
  185. ;; Sun Apr 5 19:39:08 1992 Joe Wells (jbw at bigbird.bu.edu)
  186. ;;
  187. ;; * Cleaned up full name extraction extensively.
  188. ;;
  189. ;; Sun Feb 2 14:45:24 1992 Joe Wells (jbw at bigbird.bu.edu)
  190. ;;
  191. ;; * Total rewrite. Integrated mail-canonicalize-address into
  192. ;; mail-extract-address-components. Now handles GROUP addresses more
  193. ;; or less correctly. Better handling of lots of different cases.
  194. ;;
  195. ;; Fri Jun 14 19:39:50 1991
  196. ;; * Created.
  197. ;;; Code:
  198. (defgroup mail-extr nil
  199. "Extract full name and address from RFC 822 mail header."
  200. :prefix "mail-extr-"
  201. :group 'mail)
  202. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  203. ;;
  204. ;; User configuration variable definitions.
  205. ;;
  206. (defcustom mail-extr-guess-middle-initial nil
  207. "*Whether to try to guess middle initial from mail address.
  208. If true, then when we see an address like \"John Smith <jqs@host.com>\"
  209. we will assume that \"John Q. Smith\" is the fellow's name."
  210. :type 'boolean
  211. :group 'mail-extr)
  212. (defcustom mail-extr-ignore-single-names nil
  213. "*Whether to ignore a name that is just a single word.
  214. If true, then when we see an address like \"Idiot <dumb@stupid.com>\"
  215. we will act as though we couldn't find a full name in the address."
  216. :type 'boolean
  217. :version "22.1"
  218. :group 'mail-extr)
  219. (defcustom mail-extr-ignore-realname-equals-mailbox-name t
  220. "*Whether to ignore a name that is equal to the mailbox name.
  221. If true, then when the address is like \"Single <single@address.com>\"
  222. we will act as though we couldn't find a full name in the address."
  223. :type 'boolean
  224. :group 'mail-extr)
  225. ;; Matches a leading title that is not part of the name (does not
  226. ;; contribute to uniquely identifying the person).
  227. (defcustom mail-extr-full-name-prefixes
  228. (purecopy
  229. "\\(Prof\\|D[Rr]\\|Mrs?\\|Rev\\|Rabbi\\|SysOp\\|LCDR\\)\\.?[ \t\n]")
  230. "*Matches prefixes to the full name that identify a person's position.
  231. These are stripped from the full name because they do not contribute to
  232. uniquely identifying the person."
  233. :type 'regexp
  234. :group 'mail-extr)
  235. (defcustom mail-extr-@-binds-tighter-than-! nil
  236. "*Whether the local mail transport agent looks at ! before @."
  237. :type 'boolean
  238. :group 'mail-extr)
  239. (defcustom mail-extr-mangle-uucp nil
  240. "*Whether to throw away information in UUCP addresses
  241. by translating things like \"foo!bar!baz@host\" into \"baz@bar.UUCP\"."
  242. :type 'boolean
  243. :group 'mail-extr)
  244. ;;----------------------------------------------------------------------
  245. ;; what orderings are meaningful?????
  246. ;;(defvar mail-operator-precedence-list '(?! ?% ?@))
  247. ;; Right operand of a % or a @ must be a domain name, period. No other
  248. ;; operators allowed. Left operand of a @ is an address relative to that
  249. ;; site.
  250. ;; Left operand of a ! must be a domain name. Right operand is an
  251. ;; arbitrary address.
  252. ;;----------------------------------------------------------------------
  253. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  254. ;;
  255. ;; Constant definitions.
  256. ;;
  257. ;; Any character that can occur in a name, not counting characters that
  258. ;; separate parts of a multipart name (hyphen and period).
  259. ;; Yes, there are weird people with digits in their names.
  260. ;; You will also notice the consideration for the
  261. ;; Swedish/Finnish/Norwegian character set.
  262. (defconst mail-extr-all-letters-but-separators
  263. (purecopy "][[:alnum:]{|}'~`"))
  264. ;; Any character that can occur in a name in an RFC822 address including
  265. ;; the separator (hyphen and possibly period) for multipart names.
  266. ;; #### should . be in here?
  267. (defconst mail-extr-all-letters
  268. (purecopy (concat mail-extr-all-letters-but-separators "---")))
  269. ;; Any character that can start a name.
  270. ;; Keep this set as minimal as possible.
  271. (defconst mail-extr-first-letters (purecopy "[:alpha:]"))
  272. ;; Any character that can end a name.
  273. ;; Keep this set as minimal as possible.
  274. (defconst mail-extr-last-letters (purecopy "[:alpha:]`'."))
  275. (defconst mail-extr-leading-garbage "\\W+")
  276. ;; (defconst mail-extr-non-name-chars
  277. ;; (purecopy (concat "^" mail-extr-all-letters ".")))
  278. ;; (defconst mail-extr-non-begin-name-chars
  279. ;; (purecopy (concat "^" mail-extr-first-letters)))
  280. ;; (defconst mail-extr-non-end-name-chars
  281. ;; (purecopy (concat "^" mail-extr-last-letters)))
  282. ;; Matches an initial not followed by both a period and a space.
  283. ;; (defconst mail-extr-bad-initials-pattern
  284. ;; (purecopy
  285. ;; (format "\\(\\([^%s]\\|\\`\\)[%s]\\)\\(\\.\\([^ ]\\)\\| \\|\\([^%s .]\\)\\|\\'\\)"
  286. ;; mail-extr-all-letters mail-extr-first-letters mail-extr-all-letters)))
  287. ;; Matches periods used instead of spaces. Must not match the period
  288. ;; following an initial.
  289. (defconst mail-extr-bad-dot-pattern
  290. (purecopy
  291. (format "\\([%s][%s]\\)\\.+\\([%s]\\)"
  292. mail-extr-all-letters
  293. mail-extr-last-letters
  294. mail-extr-first-letters)))
  295. ;; Matches an embedded or leading nickname that should be removed.
  296. ;; (defconst mail-extr-nickname-pattern
  297. ;; (purecopy
  298. ;; (format "\\([ .]\\|\\`\\)[\"'`\[\(]\\([ .%s]+\\)[\]\"'\)] "
  299. ;; mail-extr-all-letters)))
  300. ;; Matches the occurrence of a generational name suffix, and the last
  301. ;; character of the preceding name. This is important because we want to
  302. ;; keep such suffixes: they help to uniquely identify the person.
  303. ;; *** Perhaps this should be a user-customizable variable. However, the
  304. ;; *** regular expression is fairly tricky to alter, so maybe not.
  305. (defconst mail-extr-full-name-suffix-pattern
  306. (purecopy
  307. (format
  308. "\\(,? ?\\([JjSs][Rr]\\.?\\|V?I+V?\\)\\)\\([^%s]\\([^%s]\\|\\'\\)\\|\\'\\)"
  309. mail-extr-all-letters mail-extr-all-letters)))
  310. (defconst mail-extr-roman-numeral-pattern (purecopy "V?I+V?\\b"))
  311. ;; Matches a trailing uppercase (with other characters possible) acronym.
  312. ;; Must not match a trailing uppercase last name or trailing initial
  313. (defconst mail-extr-weird-acronym-pattern
  314. (purecopy "\\([A-Z]+[-_/]\\|[A-Z][A-Z][A-Z]?\\b\\)"))
  315. ;; Matches a mixed-case or lowercase name (not an initial).
  316. ;; #### Match Latin1 lower case letters here too?
  317. ;; (defconst mail-extr-mixed-case-name-pattern
  318. ;; (purecopy
  319. ;; (format
  320. ;; "\\b\\([a-z][%s]*[%s]\\|[%s][%s]*[a-z][%s]*[%s]\\|[%s][%s]*[a-z]\\)"
  321. ;; mail-extr-all-letters mail-extr-last-letters
  322. ;; mail-extr-first-letters mail-extr-all-letters mail-extr-all-letters
  323. ;; mail-extr-last-letters mail-extr-first-letters mail-extr-all-letters)))
  324. ;; Matches a trailing alternative address.
  325. ;; #### Match Latin1 letters here too?
  326. ;; #### Match _ before @ here too?
  327. (defconst mail-extr-alternative-address-pattern
  328. (purecopy "\\(aka *\\)?[a-zA-Z.]+[!@][a-zA-Z.]"))
  329. ;; Matches a variety of trailing comments not including comma-delimited
  330. ;; comments.
  331. (defconst mail-extr-trailing-comment-start-pattern
  332. (purecopy " [-{]\\|--\\|[+@#></\;]"))
  333. ;; Matches a name (not an initial).
  334. ;; This doesn't force a word boundary at the end because sometimes a
  335. ;; comment is separated by a `-' with no preceding space.
  336. (defconst mail-extr-name-pattern
  337. (purecopy (format "\\b[%s][%s]*[%s]"
  338. mail-extr-first-letters
  339. mail-extr-all-letters
  340. mail-extr-last-letters)))
  341. (defconst mail-extr-initial-pattern
  342. (purecopy (format "\\b[%s]\\([. ]\\|\\b\\)" mail-extr-first-letters)))
  343. ;; Matches a single name before a comma.
  344. ;; (defconst mail-extr-last-name-first-pattern
  345. ;; (purecopy (concat "\\`" mail-extr-name-pattern ",")))
  346. ;; Matches telephone extensions.
  347. (defconst mail-extr-telephone-extension-pattern
  348. (purecopy
  349. "\\(\\([Ee]xt\\|\\|[Tt]ph\\|[Tt]el\\|[Xx]\\).?\\)? *\\+?[0-9][- 0-9]+"))
  350. ;; Matches ham radio call signs.
  351. ;; Help from: Mat Maessen N2NJZ <maessm@rpi.edu>, Mark Feit
  352. ;; <mark@era.com>, Michael Covington <mcovingt@ai.uga.edu>.
  353. ;; Examples: DX504 DX515 K5MRU K8DHK KA9WGN KD3FU KD6EUI KD6HBW
  354. ;; KE9TV KF0NV N1API N3FU N3GZE N3IGS N4KCC N7IKQ N9HHU W4YHF W6ANK WA2SUH
  355. ;; WB7VZI N2NJZ NR3G KJ4KK AB4UM AL7NI KH6OH WN3KBT N4TMI W1A N0NZO
  356. (defconst mail-extr-ham-call-sign-pattern
  357. (purecopy "\\b\\(DX[0-9]+\\|[AKNW][A-Z]?[0-9][A-Z][A-Z]?[A-Z]?\\)"))
  358. ;; Possible trailing suffixes: "\\(/\\(KT\\|A[AEG]\\|[R0-9]\\)\\)?"
  359. ;; /KT == Temporary Technician (has CSC but not "real" license)
  360. ;; /AA == Temporary Advanced
  361. ;; /AE == Temporary Extra
  362. ;; /AG == Temporary General
  363. ;; /R == repeater
  364. ;; /# == stations operating out of home district
  365. ;; I don't include these in the regexp above because I can't imagine
  366. ;; anyone putting them with their name in an e-mail address.
  367. ;; Matches normal single-part name
  368. (defconst mail-extr-normal-name-pattern
  369. (purecopy (format "\\b[%s][%s]+[%s]"
  370. mail-extr-first-letters
  371. mail-extr-all-letters-but-separators
  372. mail-extr-last-letters)))
  373. ;; Matches a single word name.
  374. ;; (defconst mail-extr-one-name-pattern
  375. ;; (purecopy (concat "\\`" mail-extr-normal-name-pattern "\\'")))
  376. ;; Matches normal two names with missing middle initial
  377. ;; The first name is not allowed to have a hyphen because this can cause
  378. ;; false matches where the "middle initial" is actually the first letter
  379. ;; of the second part of the first name.
  380. (defconst mail-extr-two-name-pattern
  381. (purecopy
  382. (concat "\\`\\(" mail-extr-normal-name-pattern
  383. "\\|" mail-extr-initial-pattern
  384. "\\) +\\(" mail-extr-name-pattern "\\)\\(,\\|\\'\\)")))
  385. (defconst mail-extr-listserv-list-name-pattern
  386. (purecopy "Multiple recipients of list \\([-A-Z]+\\)"))
  387. (defconst mail-extr-stupid-vms-date-stamp-pattern
  388. (purecopy
  389. "[0-9][0-9]-[JFMASOND][aepuco][nbrylgptvc]-[0-9][0-9][0-9][0-9] [0-9]+ *"))
  390. ;;; HZ -- GB (PRC Chinese character encoding) in ASCII embedding protocol
  391. ;;
  392. ;; In ASCII mode, a byte is interpreted as an ASCII character, unless a '~' is
  393. ;; encountered. The character '~' is an escape character. By convention, it
  394. ;; must be immediately followed ONLY by '~', '{' or '\n' (<LF>), with the
  395. ;; following special meaning.
  396. ;;
  397. ;; o The escape sequence '~~' is interpreted as a '~'.
  398. ;; o The escape-to-GB sequence '~{' switches the mode from ASCII to GB.
  399. ;; o The escape sequence '~\n' is a line-continuation marker to be consumed
  400. ;; with no output produced.
  401. ;;
  402. ;; In GB mode, characters are interpreted two bytes at a time as (pure) GB
  403. ;; codes until the escape-from-GB code '~}' is read. This code switches the
  404. ;; mode from GB back to ASCII. (Note that the escape-from-GB code '~}'
  405. ;; ($7E7D) is outside the defined GB range.)
  406. (defconst mail-extr-hz-embedded-gb-encoded-chinese-pattern
  407. (purecopy "~{\\([^~].\\|~[^\}]\\)+~}"))
  408. ;; The leading optional lowercase letters are for a bastardized version of
  409. ;; the encoding, as is the optional nature of the final slash.
  410. (defconst mail-extr-x400-encoded-address-pattern
  411. (purecopy "[a-z]?[a-z]?\\(/[A-Za-z]+\\(\\.[A-Za-z]+\\)?=[^/]+\\)+/?\\'"))
  412. (defconst mail-extr-x400-encoded-address-field-pattern-format
  413. (purecopy "/%s=\\([^/]+\\)\\(/\\|\\'\\)"))
  414. (defconst mail-extr-x400-encoded-address-surname-pattern
  415. ;; S stands for Surname (family name).
  416. (purecopy
  417. (format mail-extr-x400-encoded-address-field-pattern-format "[Ss]")))
  418. (defconst mail-extr-x400-encoded-address-given-name-pattern
  419. ;; G stands for Given name.
  420. (purecopy
  421. (format mail-extr-x400-encoded-address-field-pattern-format "[Gg]")))
  422. (defconst mail-extr-x400-encoded-address-full-name-pattern
  423. ;; PN stands for Personal Name. When used it represents the combination
  424. ;; of the G and S fields.
  425. ;; "The one system I used having this field asked it with the prompt
  426. ;; `Personal Name'. But they mapped it into G and S on outgoing real
  427. ;; X.400 addresses. As they mapped G and S into PN on incoming..."
  428. (purecopy
  429. (format mail-extr-x400-encoded-address-field-pattern-format "[Pp][Nn]")))
  430. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  431. ;;
  432. ;; Syntax tables used for quick parsing.
  433. ;;
  434. (defconst mail-extr-address-syntax-table (make-syntax-table))
  435. (defconst mail-extr-address-comment-syntax-table (make-syntax-table))
  436. (defconst mail-extr-address-domain-literal-syntax-table (make-syntax-table))
  437. (defconst mail-extr-address-text-comment-syntax-table (make-syntax-table))
  438. (defconst mail-extr-address-text-syntax-table (make-syntax-table))
  439. (mapc
  440. (lambda (pair)
  441. (let ((syntax-table (symbol-value (car pair))))
  442. (dolist (item (cdr pair))
  443. (if (eq 2 (length item))
  444. ;; modifying syntax of a single character
  445. (modify-syntax-entry (car item) (car (cdr item)) syntax-table)
  446. ;; modifying syntax of a range of characters
  447. (let ((char (nth 0 item))
  448. (bound (nth 1 item))
  449. (syntax (nth 2 item)))
  450. (while (<= char bound)
  451. (modify-syntax-entry char syntax syntax-table)
  452. (setq char (1+ char))))))))
  453. '((mail-extr-address-syntax-table
  454. (?\000 ?\037 "w") ;control characters
  455. (?\040 " ") ;SPC
  456. (?! ?~ "w") ;printable characters
  457. (?\177 "w") ;DEL
  458. (?\t " ")
  459. (?\r " ")
  460. (?\n " ")
  461. (?\( ".")
  462. (?\) ".")
  463. (?< ".")
  464. (?> ".")
  465. (?@ ".")
  466. (?, ".")
  467. (?\; ".")
  468. (?: ".")
  469. (?\\ "\\")
  470. (?\" "\"")
  471. (?. ".")
  472. (?\[ ".")
  473. (?\] ".")
  474. ;; % and ! aren't RFC822 characters, but it is convenient to pretend
  475. (?% ".")
  476. (?! ".") ;; this needs to be word-constituent when not in .UUCP mode
  477. )
  478. (mail-extr-address-comment-syntax-table
  479. (?\000 ?\377 "w")
  480. (?\040 " ")
  481. (?\240 " ")
  482. (?\t " ")
  483. (?\r " ")
  484. (?\n " ")
  485. (?\( "\(\)")
  486. (?\) "\)\(")
  487. (?\\ "\\"))
  488. (mail-extr-address-domain-literal-syntax-table
  489. (?\000 ?\377 "w")
  490. (?\040 " ")
  491. (?\240 " ")
  492. (?\t " ")
  493. (?\r " ")
  494. (?\n " ")
  495. (?\[ "\(\]") ;??????
  496. (?\] "\)\[") ;??????
  497. (?\\ "\\"))
  498. (mail-extr-address-text-comment-syntax-table
  499. (?\000 ?\377 "w")
  500. (?\040 " ")
  501. (?\240 " ")
  502. (?\t " ")
  503. (?\r " ")
  504. (?\n " ")
  505. (?\( "\(\)")
  506. (?\) "\)\(")
  507. (?\[ "\(\]")
  508. (?\] "\)\[")
  509. (?\{ "\(\}")
  510. (?\} "\)\{")
  511. (?\\ "\\")
  512. (?\" "\"")
  513. ;; (?\' "\)\`")
  514. ;; (?\` "\(\'")
  515. )
  516. (mail-extr-address-text-syntax-table
  517. (?\000 ?\177 ".")
  518. (?\200 ?\377 "w")
  519. (?\040 " ")
  520. (?\t " ")
  521. (?\r " ")
  522. (?\n " ")
  523. (?A ?Z "w")
  524. (?a ?z "w")
  525. (?- "w")
  526. (?\} "w")
  527. (?\{ "w")
  528. (?| "w")
  529. (?\' "w")
  530. (?~ "w")
  531. (?0 ?9 "w"))
  532. ))
  533. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  534. ;;
  535. ;; Utility functions and macros.
  536. ;;
  537. ;; Fixme: There are Latin-1 nbsp below. If such characters should be
  538. ;; included, this is the wrong thing to do -- it should use syntax (or
  539. ;; regexp char classes).
  540. (defsubst mail-extr-skip-whitespace-forward ()
  541. ;; v19 fn skip-syntax-forward is more tasteful, but not byte-coded.
  542. (skip-chars-forward " \t\n\r "))
  543. (defsubst mail-extr-skip-whitespace-backward ()
  544. ;; v19 fn skip-syntax-backward is more tasteful, but not byte-coded.
  545. (skip-chars-backward " \t\n\r "))
  546. (defsubst mail-extr-undo-backslash-quoting (beg end)
  547. (save-excursion
  548. (save-restriction
  549. (narrow-to-region beg end)
  550. (goto-char (point-min))
  551. ;; undo \ quoting
  552. (while (search-forward "\\" nil t)
  553. (delete-char -1)
  554. (or (eobp)
  555. (forward-char 1))))))
  556. (defsubst mail-extr-nuke-char-at (pos)
  557. (save-excursion
  558. (goto-char pos)
  559. (delete-char 1)
  560. (insert ?\ )))
  561. (put 'mail-extr-nuke-outside-range
  562. 'edebug-form-spec '(symbolp &optional form form atom))
  563. (defmacro mail-extr-nuke-outside-range (list-symbol
  564. beg-symbol end-symbol
  565. &optional no-replace)
  566. "Delete all elements outside BEG..END in LIST.
  567. LIST-SYMBOL names a variable holding a list of buffer positions
  568. BEG-SYMBOL and END-SYMBOL name variables delimiting a range
  569. Each element of LIST-SYMBOL which lies outside of the range is
  570. deleted from the list.
  571. Unless NO-REPLACE is true, at each of the positions in LIST-SYMBOL
  572. which lie outside of the range, one character at that position is
  573. replaced with a SPC."
  574. (or (memq no-replace '(t nil))
  575. (error "no-replace must be t or nil, evaluable at macroexpand-time"))
  576. `(let ((temp ,list-symbol)
  577. ch)
  578. (while temp
  579. (setq ch (car temp))
  580. (when (or (> ch ,end-symbol)
  581. (< ch ,beg-symbol))
  582. ,@(if no-replace
  583. nil
  584. `((mail-extr-nuke-char-at ch)))
  585. (setcar temp nil))
  586. (setq temp (cdr temp)))
  587. (setq ,list-symbol (delq nil ,list-symbol))))
  588. (defun mail-extr-demarkerize (marker)
  589. ;; if arg is a marker, destroys the marker, then returns the old value.
  590. ;; otherwise returns the arg.
  591. (if (markerp marker)
  592. (let ((temp (marker-position marker)))
  593. (set-marker marker nil)
  594. temp)
  595. marker))
  596. (defun mail-extr-markerize (pos)
  597. ;; coerces pos to a marker if non-nil.
  598. (if (or (markerp pos) (null pos))
  599. pos
  600. (copy-marker pos)))
  601. (defsubst mail-extr-safe-move-sexp (arg)
  602. ;; Safely skip over one balanced sexp, if there is one. Return t if success.
  603. (condition-case error
  604. (progn
  605. (goto-char (or (scan-sexps (point) arg) (point)))
  606. t)
  607. (error
  608. ;; #### kludge kludge kludge kludge kludge kludge kludge !!!
  609. (if (string-equal (nth 1 error) "Unbalanced parentheses")
  610. nil
  611. (while t
  612. (signal (car error) (cdr error)))))))
  613. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  614. ;;
  615. ;; The main function to grind addresses
  616. ;;
  617. (defvar disable-initial-guessing-flag) ; dynamic assignment
  618. (defvar mailextr-cbeg) ; dynamic assignment
  619. (defvar mailextr-cend) ; dynamic assignment
  620. (defvar mail-extr-all-top-level-domains) ; Defined below.
  621. ;;;###autoload
  622. (defun mail-extract-address-components (address &optional all)
  623. "Given an RFC-822 address ADDRESS, extract full name and canonical address.
  624. Returns a list of the form (FULL-NAME CANONICAL-ADDRESS). If no
  625. name can be extracted, FULL-NAME will be nil. Also see
  626. `mail-extr-ignore-single-names' and
  627. `mail-extr-ignore-realname-equals-mailbox-name'.
  628. If the optional argument ALL is non-nil, then ADDRESS can contain zero
  629. or more recipients, separated by commas, and we return a list of
  630. the form ((FULL-NAME CANONICAL-ADDRESS) ...) with one element for
  631. each recipient. If ALL is nil, then if ADDRESS contains more than
  632. one recipients, all but the first is ignored.
  633. ADDRESS may be a string or a buffer. If it is a buffer, the visible
  634. \(narrowed) portion of the buffer will be interpreted as the address.
  635. \(This feature exists so that the clever caller might be able to avoid
  636. consing a string.)"
  637. (let ((canonicalization-buffer (get-buffer-create " *canonical address*"))
  638. (extraction-buffer (get-buffer-create " *extract address components*"))
  639. value-list)
  640. (with-current-buffer (get-buffer-create extraction-buffer)
  641. (fundamental-mode)
  642. (buffer-disable-undo extraction-buffer)
  643. (set-syntax-table mail-extr-address-syntax-table)
  644. (widen)
  645. (erase-buffer)
  646. (setq case-fold-search nil)
  647. ;; Insert extra space at beginning to allow later replacement with <
  648. ;; without having to move markers.
  649. (insert ?\ )
  650. ;; Insert the address itself.
  651. (cond ((stringp address)
  652. (insert address))
  653. ((bufferp address)
  654. (insert-buffer-substring address))
  655. (t
  656. (error "Invalid address: %s" address)))
  657. (set-text-properties (point-min) (point-max) nil)
  658. (with-current-buffer (get-buffer-create canonicalization-buffer)
  659. (fundamental-mode)
  660. (buffer-disable-undo canonicalization-buffer)
  661. (setq case-fold-search nil))
  662. ;; Unfold multiple lines.
  663. (goto-char (point-min))
  664. (while (re-search-forward "\\([^\\]\\(\\\\\\\\\\)*\\)\n[ \t]" nil t)
  665. (replace-match "\\1 " t))
  666. ;; Loop over addresses until we have as many as we want.
  667. (while (and (or all (null value-list))
  668. (progn (goto-char (point-min))
  669. (skip-chars-forward " \t")
  670. (not (eobp))))
  671. (let (char
  672. end-of-address
  673. <-pos >-pos @-pos colon-pos comma-pos !-pos %-pos \;-pos
  674. group-:-pos group-\;-pos route-addr-:-pos
  675. record-pos-symbol
  676. first-real-pos last-real-pos
  677. phrase-beg phrase-end
  678. ;; Dynamically set in mail-extr-voodoo.
  679. mailextr-cbeg mailextr-cend
  680. quote-beg quote-end
  681. atom-beg atom-end
  682. mbox-beg mbox-end
  683. \.-ends-name
  684. temp
  685. ;; name-suffix
  686. fi mi li ; first, middle, last initial
  687. saved-%-pos saved-!-pos saved-@-pos
  688. domain-pos \.-pos insert-point
  689. ;; mailbox-name-processed-flag
  690. disable-initial-guessing-flag) ; dynamically set from -voodoo
  691. (set-syntax-table mail-extr-address-syntax-table)
  692. (goto-char (point-min))
  693. ;; Insert extra space at beginning to allow later replacement with <
  694. ;; without having to move markers.
  695. (or (eq (following-char) ?\ )
  696. (insert ?\ ))
  697. ;; First pass grabs useful information about address.
  698. (while (progn
  699. (mail-extr-skip-whitespace-forward)
  700. (not (eobp)))
  701. (setq char (char-after (point)))
  702. (or first-real-pos
  703. (if (not (eq char ?\())
  704. (setq first-real-pos (point))))
  705. (cond
  706. ;; comment
  707. ((eq char ?\()
  708. (set-syntax-table mail-extr-address-comment-syntax-table)
  709. ;; only record the first non-empty comment's position
  710. (if (and (not mailextr-cbeg)
  711. (save-excursion
  712. (forward-char 1)
  713. (mail-extr-skip-whitespace-forward)
  714. (not (eq ?\) (char-after (point))))))
  715. (setq mailextr-cbeg (point)))
  716. ;; TODO: don't record if unbalanced
  717. (or (mail-extr-safe-move-sexp 1)
  718. (forward-char 1))
  719. (set-syntax-table mail-extr-address-syntax-table)
  720. (if (and mailextr-cbeg
  721. (not mailextr-cend))
  722. (setq mailextr-cend (point))))
  723. ;; quoted text
  724. ((eq char ?\")
  725. ;; only record the first non-empty quote's position
  726. (if (and (not quote-beg)
  727. (save-excursion
  728. (forward-char 1)
  729. (mail-extr-skip-whitespace-forward)
  730. (not (eq ?\" (char-after (point))))))
  731. (setq quote-beg (point)))
  732. ;; TODO: don't record if unbalanced
  733. (or (mail-extr-safe-move-sexp 1)
  734. (forward-char 1))
  735. (if (and quote-beg
  736. (not quote-end))
  737. (setq quote-end (point))))
  738. ;; domain literals
  739. ((eq char ?\[)
  740. (set-syntax-table mail-extr-address-domain-literal-syntax-table)
  741. (or (mail-extr-safe-move-sexp 1)
  742. (forward-char 1))
  743. (set-syntax-table mail-extr-address-syntax-table))
  744. ;; commas delimit addresses when outside < > pairs.
  745. ((and (eq char ?,)
  746. (or (and (null <-pos)
  747. ;; Handle ROUTE-ADDR address that is missing its <.
  748. (not (eq ?@ (char-after (1+ (point))))))
  749. (and >-pos
  750. ;; handle weird munged addresses
  751. ;; BUG FIX: This test was reversed. Thanks to the
  752. ;; brilliant Rod Whitby <rwhitby@research.canon.oz.au>
  753. ;; for discovering this!
  754. (< (car (last <-pos)) (car >-pos)))))
  755. ;; The argument contains more than one address.
  756. ;; Temporarily hide everything after this one.
  757. (setq end-of-address (copy-marker (1+ (point)) t))
  758. (narrow-to-region (point-min) (1+ (point)))
  759. (delete-char 1)
  760. (setq char ?\() ; HAVE I NO SHAME??
  761. )
  762. ;; record the position of various interesting chars, determine
  763. ;; validity later.
  764. ((setq record-pos-symbol
  765. (cdr (assq char
  766. '((?< . <-pos) (?> . >-pos) (?@ . @-pos)
  767. (?: . colon-pos) (?, . comma-pos) (?! . !-pos)
  768. (?% . %-pos) (?\; . \;-pos)))))
  769. (set record-pos-symbol
  770. (cons (point) (symbol-value record-pos-symbol)))
  771. (forward-char 1))
  772. ((eq char ?.)
  773. (forward-char 1))
  774. ((memq char '(
  775. ;; comment terminator invalid
  776. ?\)
  777. ;; domain literal terminator invalid
  778. ?\]
  779. ;; \ allowed only within quoted strings,
  780. ;; domain literals, and comments
  781. ?\\
  782. ))
  783. (mail-extr-nuke-char-at (point))
  784. (forward-char 1))
  785. (t
  786. ;; Do `(forward-word 1)', recognizing non-ASCII characters
  787. ;; except Latin-1 nbsp as words.
  788. (while (progn
  789. (skip-chars-forward "^\000-\177 ")
  790. (and (not (eobp))
  791. (eq ?w (char-syntax (char-after)))
  792. (progn
  793. (forward-word 1)
  794. (and (not (eobp))
  795. (> (char-after) ?\177)
  796. (not (eq (char-after) ? )))))))))
  797. (or (eq char ?\()
  798. ;; At the end of first address of a multiple address header.
  799. (and (eq char ?,)
  800. (eobp))
  801. (setq last-real-pos (point))))
  802. ;; Use only the leftmost <, if any. Replace all others with spaces.
  803. (while (cdr <-pos)
  804. (mail-extr-nuke-char-at (car <-pos))
  805. (setq <-pos (cdr <-pos)))
  806. ;; Use only the rightmost >, if any. Replace all others with spaces.
  807. (while (cdr >-pos)
  808. (mail-extr-nuke-char-at (nth 1 >-pos))
  809. (setcdr >-pos (nthcdr 2 >-pos)))
  810. ;; If multiple @s and a :, but no < and >, insert around buffer.
  811. ;; Example: @foo.bar.dom,@xxx.yyy.zzz:mailbox@aaa.bbb.ccc
  812. ;; This commonly happens on the UUCP "From " line. Ugh.
  813. (when (and (> (length @-pos) 1)
  814. (eq 1 (length colon-pos)) ;TODO: check if between last two @s
  815. (not \;-pos)
  816. (not <-pos))
  817. (goto-char (point-min))
  818. (delete-char 1)
  819. (setq <-pos (list (point)))
  820. (insert ?<))
  821. ;; If < but no >, insert > in rightmost possible position
  822. (when (and <-pos (null >-pos))
  823. (goto-char (point-max))
  824. (setq >-pos (list (point)))
  825. (insert ?>))
  826. ;; If > but no <, replace > with space.
  827. (when (and >-pos (null <-pos))
  828. (mail-extr-nuke-char-at (car >-pos))
  829. (setq >-pos nil))
  830. ;; Turn >-pos and <-pos into non-lists
  831. (setq >-pos (car >-pos)
  832. <-pos (car <-pos))
  833. ;; Trim other punctuation lists of items outside < > pair to handle
  834. ;; stupid MTAs.
  835. (when <-pos ; don't need to check >-pos also
  836. ;; handle bozo software that violates RFC 822 by sticking
  837. ;; punctuation marks outside of a < > pair
  838. (mail-extr-nuke-outside-range @-pos <-pos >-pos t)
  839. ;; RFC 822 says nothing about these two outside < >, but
  840. ;; remove those positions from the lists to make things
  841. ;; easier.
  842. (mail-extr-nuke-outside-range !-pos <-pos >-pos t)
  843. (mail-extr-nuke-outside-range %-pos <-pos >-pos t))
  844. ;; Check for : that indicates GROUP list and for : part of
  845. ;; ROUTE-ADDR spec.
  846. ;; Can't possibly be more than two :. Nuke any extra.
  847. (while colon-pos
  848. (setq temp (car colon-pos)
  849. colon-pos (cdr colon-pos))
  850. (cond ((and <-pos >-pos
  851. (> temp <-pos)
  852. (< temp >-pos))
  853. (if (or route-addr-:-pos
  854. (< (length @-pos) 2)
  855. (> temp (car @-pos))
  856. (< temp (nth 1 @-pos)))
  857. (mail-extr-nuke-char-at temp)
  858. (setq route-addr-:-pos temp)))
  859. ((or (not <-pos)
  860. (and <-pos
  861. (< temp <-pos)))
  862. (setq group-:-pos temp))))
  863. ;; Nuke any ; that is in or to the left of a < > pair or to the left
  864. ;; of a GROUP starting :. Also, there may only be one ;.
  865. (while \;-pos
  866. (setq temp (car \;-pos)
  867. \;-pos (cdr \;-pos))
  868. (cond ((and <-pos >-pos
  869. (> temp <-pos)
  870. (< temp >-pos))
  871. (mail-extr-nuke-char-at temp))
  872. ((and (or (not group-:-pos)
  873. (> temp group-:-pos))
  874. (not group-\;-pos))
  875. (setq group-\;-pos temp))))
  876. ;; Nuke unmatched GROUP syntax characters.
  877. (when (and group-:-pos (not group-\;-pos))
  878. ;; *** Do I really need to erase it?
  879. (mail-extr-nuke-char-at group-:-pos)
  880. (setq group-:-pos nil))
  881. (when (and group-\;-pos (not group-:-pos))
  882. ;; *** Do I really need to erase it?
  883. (mail-extr-nuke-char-at group-\;-pos)
  884. (setq group-\;-pos nil))
  885. ;; Handle junk like ";@host.company.dom" that sendmail adds.
  886. ;; **** should I remember comment positions?
  887. (when group-\;-pos
  888. ;; this is fine for now
  889. (mail-extr-nuke-outside-range !-pos group-:-pos group-\;-pos t)
  890. (mail-extr-nuke-outside-range @-pos group-:-pos group-\;-pos t)
  891. (mail-extr-nuke-outside-range %-pos group-:-pos group-\;-pos t)
  892. (mail-extr-nuke-outside-range comma-pos group-:-pos group-\;-pos t)
  893. (and last-real-pos
  894. (> last-real-pos (1+ group-\;-pos))
  895. (setq last-real-pos (1+ group-\;-pos)))
  896. ;; *** This may be wrong:
  897. (and mailextr-cend
  898. (> mailextr-cend group-\;-pos)
  899. (setq mailextr-cend nil
  900. mailextr-cbeg nil))
  901. (and quote-end
  902. (> quote-end group-\;-pos)
  903. (setq quote-end nil
  904. quote-beg nil))
  905. ;; This was both wrong and unnecessary:
  906. ;;(narrow-to-region (point-min) group-\;-pos)
  907. ;; *** The entire handling of GROUP addresses seems rather lame.
  908. ;; *** It deserves a complete rethink, except that these addresses
  909. ;; *** are hardly ever seen.
  910. )
  911. ;; Any commas must be between < and : of ROUTE-ADDR. Nuke any
  912. ;; others.
  913. ;; Hell, go ahead and nuke all of the commas.
  914. ;; **** This will cause problems when we start handling commas in
  915. ;; the PHRASE part .... no it won't ... yes it will ... ?????
  916. (mail-extr-nuke-outside-range comma-pos 1 1)
  917. ;; can only have multiple @s inside < >. The fact that some MTAs
  918. ;; put de-bracketed ROUTE-ADDRs in the UUCP-style "From " line is
  919. ;; handled above.
  920. ;; Locate PHRASE part of ROUTE-ADDR.
  921. (when <-pos
  922. (goto-char <-pos)
  923. (mail-extr-skip-whitespace-backward)
  924. (setq phrase-end (point))
  925. (goto-char (or ;;group-:-pos
  926. (point-min)))
  927. (mail-extr-skip-whitespace-forward)
  928. (if (< (point) phrase-end)
  929. (setq phrase-beg (point))
  930. (setq phrase-end nil)))
  931. ;; handle ROUTE-ADDRS with real ROUTEs.
  932. ;; If there are multiple @s, then we assume ROUTE-ADDR syntax, and
  933. ;; any % or ! must be semantically meaningless.
  934. ;; TODO: do this processing into canonicalization buffer
  935. (when route-addr-:-pos
  936. (setq !-pos nil
  937. %-pos nil
  938. >-pos (copy-marker >-pos)
  939. route-addr-:-pos (copy-marker route-addr-:-pos))
  940. (goto-char >-pos)
  941. (insert-before-markers ?X)
  942. (goto-char (car @-pos))
  943. (while (setq @-pos (cdr @-pos))
  944. (delete-char 1)
  945. (setq %-pos (cons (point-marker) %-pos))
  946. (insert "%")
  947. (goto-char (1- >-pos))
  948. (save-excursion
  949. (insert-buffer-substring extraction-buffer
  950. (car @-pos) route-addr-:-pos)
  951. (delete-region (car @-pos) route-addr-:-pos))
  952. (or (cdr @-pos)
  953. (setq saved-@-pos (list (point)))))
  954. (setq @-pos saved-@-pos)
  955. (goto-char >-pos)
  956. (delete-char -1)
  957. (mail-extr-nuke-char-at route-addr-:-pos)
  958. (mail-extr-demarkerize route-addr-:-pos)
  959. (setq route-addr-:-pos nil
  960. >-pos (mail-extr-demarkerize >-pos)
  961. %-pos (mapcar 'mail-extr-demarkerize %-pos)))
  962. ;; de-listify @-pos
  963. (setq @-pos (car @-pos))
  964. ;; TODO: remove comments in the middle of an address
  965. (with-current-buffer canonicalization-buffer
  966. (widen)
  967. (erase-buffer)
  968. (insert-buffer-substring extraction-buffer)
  969. (if <-pos
  970. (narrow-to-region (progn
  971. (goto-char (1+ <-pos))
  972. (mail-extr-skip-whitespace-forward)
  973. (point))
  974. >-pos)
  975. (if (and first-real-pos last-real-pos)
  976. (narrow-to-region first-real-pos last-real-pos)
  977. ;; ****** Oh no! What if the address is completely empty!
  978. ;; *** Is this correct?
  979. (narrow-to-region (point-max) (point-max))))
  980. (and @-pos %-pos
  981. (mail-extr-nuke-outside-range %-pos (point-min) @-pos))
  982. (and %-pos !-pos
  983. (mail-extr-nuke-outside-range !-pos (point-min) (car %-pos)))
  984. (and @-pos !-pos (not %-pos)
  985. (mail-extr-nuke-outside-range !-pos (point-min) @-pos))
  986. ;; Error condition:?? (and %-pos (not @-pos))
  987. ;; WARNING: THIS CODE IS DUPLICATED BELOW.
  988. (when (and %-pos (not @-pos))
  989. (goto-char (car %-pos))
  990. (delete-char 1)
  991. (setq @-pos (point))
  992. (insert "@")
  993. (setq %-pos (cdr %-pos)))
  994. (when (and mail-extr-mangle-uucp !-pos)
  995. ;; **** I don't understand this save-restriction and the
  996. ;; narrow-to-region inside it. Why did I do that?
  997. (save-restriction
  998. (cond ((and @-pos
  999. mail-extr-@-binds-tighter-than-!)
  1000. (goto-char @-pos)
  1001. (setq %-pos (cons (point) %-pos)
  1002. @-pos nil)
  1003. (delete-char 1)
  1004. (insert "%")
  1005. (setq insert-point (point-max)))
  1006. (mail-extr-@-binds-tighter-than-!
  1007. (setq insert-point (point-max)))
  1008. (%-pos
  1009. (setq insert-point (car (last %-pos))
  1010. saved-%-pos (mapcar 'mail-extr-markerize %-pos)
  1011. %-pos nil
  1012. @-pos (mail-extr-markerize @-pos)))
  1013. (@-pos
  1014. (setq insert-point @-pos)
  1015. (setq @-pos (mail-extr-markerize @-pos)))
  1016. (t
  1017. (setq insert-point (point-max))))
  1018. (narrow-to-region (point-min) insert-point)
  1019. (setq saved-!-pos (car !-pos))
  1020. (while !-pos
  1021. (goto-char (point-max))
  1022. (cond ((and (not @-pos)
  1023. (not (cdr !-pos)))
  1024. (setq @-pos (point))
  1025. (insert-before-markers "@ "))
  1026. (t
  1027. (setq %-pos (cons (point) %-pos))
  1028. (insert-before-markers "% ")))
  1029. (backward-char 1)
  1030. (insert-buffer-substring
  1031. (current-buffer)
  1032. (if (nth 1 !-pos)
  1033. (1+ (nth 1 !-pos))
  1034. (point-min))
  1035. (car !-pos))
  1036. (delete-char 1)
  1037. (or (save-excursion
  1038. (mail-extr-safe-move-sexp -1)
  1039. (mail-extr-skip-whitespace-backward)
  1040. (eq ?. (preceding-char)))
  1041. (insert-before-markers
  1042. (if (save-excursion
  1043. (mail-extr-skip-whitespace-backward)
  1044. (eq ?. (preceding-char)))
  1045. ""
  1046. ".")
  1047. "uucp"))
  1048. (setq !-pos (cdr !-pos))))
  1049. (and saved-%-pos
  1050. (setq %-pos (append (mapcar 'mail-extr-demarkerize
  1051. saved-%-pos)
  1052. %-pos)))
  1053. (setq @-pos (mail-extr-demarkerize @-pos))
  1054. (narrow-to-region (1+ saved-!-pos) (point-max)))
  1055. ;; WARNING: THIS CODE IS DUPLICATED ABOVE.
  1056. (when (and %-pos (not @-pos))
  1057. (goto-char (car %-pos))
  1058. (delete-char 1)
  1059. (setq @-pos (point))
  1060. (insert "@")
  1061. (setq %-pos (cdr %-pos)))
  1062. (when (setq %-pos (nreverse %-pos)) ; implies @-pos valid
  1063. (setq temp %-pos)
  1064. (catch 'truncated
  1065. (while temp
  1066. (goto-char (or (nth 1 temp)
  1067. @-pos))
  1068. (mail-extr-skip-whitespace-backward)
  1069. (save-excursion
  1070. (mail-extr-safe-move-sexp -1)
  1071. (setq domain-pos (point))
  1072. (mail-extr-skip-whitespace-backward)
  1073. (setq \.-pos (eq ?. (preceding-char))))
  1074. (when (and \.-pos
  1075. ;; #### string consing
  1076. (let ((s (intern-soft
  1077. (buffer-substring domain-pos (point))
  1078. mail-extr-all-top-level-domains)))
  1079. (and s (get s 'domain-name))))
  1080. (narrow-to-region (point-min) (point))
  1081. (goto-char (car temp))
  1082. (delete-char 1)
  1083. (setq @-pos (point))
  1084. (setcdr temp nil)
  1085. (setq %-pos (delq @-pos %-pos))
  1086. (insert "@")
  1087. (throw 'truncated t))
  1088. (setq temp (cdr temp)))))
  1089. (setq mbox-beg (point-min)
  1090. mbox-end (if %-pos (car %-pos)
  1091. (or @-pos
  1092. (point-max))))
  1093. (when @-pos
  1094. ;; Make the domain-name part lowercase since it's case
  1095. ;; insensitive anyway.
  1096. (downcase-region (1+ @-pos) (point-max))))
  1097. ;; Done canonicalizing address.
  1098. ;; We are now back in extraction-buffer.
  1099. ;; Decide what part of the address to search to find the full name.
  1100. (cond (
  1101. ;; Example: "First M. Last" <fml@foo.bar.dom>
  1102. (and phrase-beg
  1103. (eq quote-beg phrase-beg)
  1104. (<= quote-end phrase-end))
  1105. (narrow-to-region (1+ quote-beg) (1- quote-end))
  1106. (mail-extr-undo-backslash-quoting (point-min) (point-max)))
  1107. ;; Example: First Last <fml@foo.bar.dom>
  1108. (phrase-beg
  1109. (narrow-to-region phrase-beg phrase-end))
  1110. ;; Example: fml@foo.bar.dom (First M. Last)
  1111. (mailextr-cbeg
  1112. (narrow-to-region (1+ mailextr-cbeg) (1- mailextr-cend))
  1113. (mail-extr-undo-backslash-quoting (point-min) (point-max))
  1114. ;; Deal with spacing problems
  1115. (goto-char (point-min))
  1116. ;;; (cond ((not (search-forward " " nil t))
  1117. ;;; (goto-char (point-min))
  1118. ;;; (cond ((search-forward "_" nil t)
  1119. ;;; ;; Handle the *idiotic* use of underlines as spaces.
  1120. ;;; ;; Example: fml@foo.bar.dom (First_M._Last)
  1121. ;;; (goto-char (point-min))
  1122. ;;; (while (search-forward "_" nil t)
  1123. ;;; (replace-match " " t)))
  1124. ;;; ((search-forward "." nil t)
  1125. ;;; ;; Fix . used as space
  1126. ;;; ;; Example: danj1@cb.att.com (daniel.jacobson)
  1127. ;;; (goto-char (point-min))
  1128. ;;; (while (re-search-forward mail-extr-bad-dot-pattern nil t)
  1129. ;;; (replace-match "\\1 \\2" t))))))
  1130. )
  1131. ;; Otherwise we try to get the name from the mailbox portion
  1132. ;; of the address.
  1133. ;; Example: First_M_Last@foo.bar.dom
  1134. (t
  1135. ;; *** Work in canon buffer instead? No, can't. Hmm.
  1136. (goto-char (point-max))
  1137. (narrow-to-region (point) (point))
  1138. (insert-buffer-substring canonicalization-buffer
  1139. mbox-beg mbox-end)
  1140. (goto-char (point-min))
  1141. ;; Example: First_Last.XXX@foo.bar.dom
  1142. (setq \.-ends-name (re-search-forward "[_0-9]" nil t))
  1143. (goto-char (point-min))
  1144. (if (not mail-extr-mangle-uucp)
  1145. (modify-syntax-entry ?! "w" (syntax-table)))
  1146. (while (progn
  1147. (mail-extr-skip-whitespace-forward)
  1148. (not (eobp)))
  1149. (setq char (char-after (point)))
  1150. (cond
  1151. ((eq char ?\")
  1152. (setq quote-beg (point))
  1153. (or (mail-extr-safe-move-sexp 1)
  1154. ;; TODO: handle this error condition!!!!!
  1155. (forward-char 1))
  1156. ;; take into account deletions
  1157. (setq quote-end (- (point) 2))
  1158. (save-excursion
  1159. (backward-char 1)
  1160. (delete-char 1)
  1161. (goto-char quote-beg)
  1162. (or (eobp)
  1163. (delete-char 1)))
  1164. (mail-extr-undo-backslash-quoting quote-beg quote-end)
  1165. (or (eq ?\ (char-after (point)))
  1166. (insert " "))
  1167. ;; (setq mailbox-name-processed-flag t)
  1168. (setq \.-ends-name t))
  1169. ((eq char ?.)
  1170. (if (memq (char-after (1+ (point))) '(?_ ?=))
  1171. (progn
  1172. (forward-char 1)
  1173. (delete-char 1)
  1174. (insert ?\ ))
  1175. (if \.-ends-name
  1176. (narrow-to-region (point-min) (point))
  1177. (delete-char 1)
  1178. (insert " ")))
  1179. ;; (setq mailbox-name-processed-flag t)
  1180. )
  1181. ((memq (char-syntax char) '(?. ?\\))
  1182. (delete-char 1)
  1183. (insert " ")
  1184. ;; (setq mailbox-name-processed-flag t)
  1185. )
  1186. (t
  1187. (setq atom-beg (point))
  1188. (forward-word 1)
  1189. (setq atom-end (point))
  1190. (goto-char atom-beg)
  1191. (save-restriction
  1192. (narrow-to-region atom-beg atom-end)
  1193. (cond
  1194. ;; Handle X.400 addresses encoded in RFC-822.
  1195. ;; *** Shit! This has to handle the case where it is
  1196. ;; *** embedded in a quote too!
  1197. ;; *** Shit! The input is being broken up into atoms
  1198. ;; *** by periods!
  1199. ((looking-at mail-extr-x400-encoded-address-pattern)
  1200. ;; Copy the contents of the individual fields that
  1201. ;; might hold name data to the beginning.
  1202. (mapc
  1203. (lambda (field-pattern)
  1204. (when
  1205. (save-excursion
  1206. (re-search-forward field-pattern nil t))
  1207. (insert-buffer-substring (current-buffer)
  1208. (match-beginning 1)
  1209. (match-end 1))
  1210. (insert " ")))
  1211. (list mail-extr-x400-encoded-address-given-name-pattern
  1212. mail-extr-x400-encoded-address-surname-pattern
  1213. mail-extr-x400-encoded-address-full-name-pattern))
  1214. ;; Discard the rest, since it contains stuff like
  1215. ;; routing information, not part of a name.
  1216. (mail-extr-skip-whitespace-backward)
  1217. (delete-region (point) (point-max))
  1218. ;; Handle periods used for spacing.
  1219. (while (re-search-forward mail-extr-bad-dot-pattern nil t)
  1220. (replace-match "\\1 \\2" t))
  1221. ;; (setq mailbox-name-processed-flag t)
  1222. )
  1223. ;; Handle normal addresses.
  1224. (t
  1225. (goto-char (point-min))
  1226. ;; Handle _ and = used for spacing.
  1227. (while (re-search-forward "\\([^_=]+\\)[_=]" nil t)
  1228. (replace-match "\\1 " t)
  1229. ;; (setq mailbox-name-processed-flag t)
  1230. )
  1231. (goto-char (point-max))))))))
  1232. ;; undo the dirty deed
  1233. (if (not mail-extr-mangle-uucp)
  1234. (modify-syntax-entry ?! "." (syntax-table)))
  1235. ;;
  1236. ;; If we derived the name from the mailbox part of the address,
  1237. ;; and we only got one word out of it, don't treat that as a
  1238. ;; name. "foo@bar" --> (nil "foo@bar"), not ("foo" "foo@bar")
  1239. ;; (if (not mailbox-name-processed-flag)
  1240. ;; (delete-region (point-min) (point-max)))
  1241. ))
  1242. (set-syntax-table mail-extr-address-text-syntax-table)
  1243. (mail-extr-voodoo mbox-beg mbox-end canonicalization-buffer)
  1244. (goto-char (point-min))
  1245. ;; If name is "First Last" and userid is "F?L", then assume
  1246. ;; the middle initial is the second letter in the userid.
  1247. ;; Initial code by Jamie Zawinski <jwz@lucid.com>
  1248. ;; *** Make it work when there's a suffix as well.
  1249. (goto-char (point-min))
  1250. (when (and mail-extr-guess-middle-initial
  1251. (not disable-initial-guessing-flag)
  1252. (eq 3 (- mbox-end mbox-beg))
  1253. (progn
  1254. (goto-char (point-min))
  1255. (looking-at mail-extr-two-name-pattern)))
  1256. (setq fi (char-after (match-beginning 0))
  1257. li (char-after (match-beginning 3)))
  1258. (with-current-buffer canonicalization-buffer
  1259. ;; char-equal is ignoring case here, so no need to upcase
  1260. ;; or downcase.
  1261. (let ((case-fold-search t))
  1262. (and (char-equal fi (char-after mbox-beg))
  1263. (char-equal li (char-after (1- mbox-end)))
  1264. (setq mi (char-after (1+ mbox-beg))))))
  1265. (when (and mi
  1266. ;; TODO: use better table than syntax table
  1267. (eq ?w (char-syntax mi)))
  1268. (goto-char (match-beginning 3))
  1269. (insert (upcase mi) ". ")))
  1270. ;; Nuke name if it is the same as mailbox name.
  1271. (let ((buffer-length (- (point-max) (point-min)))
  1272. (i 0)
  1273. (names-match-flag t))
  1274. (when (and (> buffer-length 0)
  1275. (eq buffer-length (- mbox-end mbox-beg)))
  1276. (goto-char (point-max))
  1277. (insert-buffer-substring canonicalization-buffer
  1278. mbox-beg mbox-end)
  1279. (while (and names-match-flag
  1280. (< i buffer-length))
  1281. (or (eq (downcase (char-after (+ i (point-min))))
  1282. (downcase
  1283. (char-after (+ i buffer-length (point-min)))))
  1284. (setq names-match-flag nil))
  1285. (setq i (1+ i)))
  1286. (delete-region (+ (point-min) buffer-length) (point-max))
  1287. (and names-match-flag
  1288. mail-extr-ignore-realname-equals-mailbox-name
  1289. (narrow-to-region (point) (point)))))
  1290. ;; Nuke name if it's just one word.
  1291. (goto-char (point-min))
  1292. (and mail-extr-ignore-single-names
  1293. (not (re-search-forward "[- ]" nil t))
  1294. (narrow-to-region (point) (point)))
  1295. ;; Record the result
  1296. (setq value-list
  1297. (cons (list (if (not (= (point-min) (point-max)))
  1298. (buffer-string))
  1299. (with-current-buffer canonicalization-buffer
  1300. (if (not (= (point-min) (point-max)))
  1301. (buffer-string))))
  1302. value-list))
  1303. ;; Unless one address is all we wanted,
  1304. ;; delete this one from extraction-buffer
  1305. ;; and get ready to extract the next address.
  1306. (when all
  1307. (if end-of-address
  1308. (narrow-to-region 1 end-of-address)
  1309. (widen))
  1310. (delete-region (point-min) (point-max))
  1311. (widen))
  1312. )))
  1313. (if all (nreverse value-list) (car value-list))
  1314. ))
  1315. (defcustom mail-extr-disable-voodoo "\\cj"
  1316. "*If it is a regexp, names matching it will never be modified.
  1317. If it is neither nil nor a string, modifying of names will never take
  1318. place. It affects how `mail-extract-address-components' works."
  1319. :type '(choice (regexp :size 0)
  1320. (const :tag "Always enabled" nil)
  1321. (const :tag "Always disabled" t))
  1322. :group 'mail-extr)
  1323. (defun mail-extr-voodoo (mbox-beg mbox-end canonicalization-buffer)
  1324. (unless (and mail-extr-disable-voodoo
  1325. (or (not (stringp mail-extr-disable-voodoo))
  1326. (progn
  1327. (goto-char (point-min))
  1328. (re-search-forward mail-extr-disable-voodoo nil t))))
  1329. (let ((word-count 0)
  1330. (case-fold-search nil)
  1331. mixed-case-flag lower-case-flag ;;upper-case-flag
  1332. suffix-flag last-name-comma-flag
  1333. initial
  1334. begin-again-flag
  1335. drop-this-word-if-trailing-flag
  1336. drop-last-word-if-trailing-flag
  1337. word-found-flag
  1338. this-word-beg last-word-beg
  1339. name-beg name-end
  1340. name-done-flag
  1341. )
  1342. (save-excursion
  1343. (set-syntax-table mail-extr-address-text-syntax-table)
  1344. ;; Get rid of comments.
  1345. (goto-char (point-min))
  1346. (while (not (eobp))
  1347. ;; Initialize for this iteration of the loop.
  1348. (skip-chars-forward "^({[\"'`")
  1349. (let ((cbeg (point)))
  1350. (set-syntax-table mail-extr-address-text-comment-syntax-table)
  1351. (if (memq (following-char) '(?\' ?\`))
  1352. (search-forward "'" nil 'move
  1353. (if (eq ?\' (following-char)) 2 1))
  1354. (or (mail-extr-safe-move-sexp 1)
  1355. (goto-char (point-max))))
  1356. (set-syntax-table mail-extr-address-text-syntax-table)
  1357. (when (eq (char-after cbeg) ?\()
  1358. ;; Delete the comment itself.
  1359. (delete-region cbeg (point))
  1360. ;; Canonicalize whitespace where the comment was.
  1361. (skip-chars-backward " \t")
  1362. (if (looking-at "\\([ \t]+$\\|[ \t]+,\\)")
  1363. (replace-match "")
  1364. (setq cbeg (point))
  1365. (skip-chars-forward " \t")
  1366. (if (bobp)
  1367. (delete-region (point) cbeg)
  1368. (just-one-space))))))
  1369. ;; This was moved above.
  1370. ;; Fix . used as space
  1371. ;; But it belongs here because it occurs not only as
  1372. ;; rypens@reks.uia.ac.be (Piet.Rypens)
  1373. ;; but also as
  1374. ;; "Piet.Rypens" <rypens@reks.uia.ac.be>
  1375. ;;(goto-char (point-min))
  1376. ;;(while (re-search-forward mail-extr-bad-dot-pattern nil t)
  1377. ;; (replace-match "\\1 \\2" t))
  1378. (unless (search-forward " " nil t)
  1379. (goto-char (point-min))
  1380. (cond ((search-forward "_" nil t)
  1381. ;; Handle the *idiotic* use of underlines as spaces.
  1382. ;; Example: fml@foo.bar.dom (First_M._Last)
  1383. (goto-char (point-min))
  1384. (while (search-forward "_" nil t)
  1385. (replace-match " " t)))
  1386. ((search-forward "." nil t)
  1387. ;; Fix . used as space
  1388. ;; Example: danj1@cb.att.com (daniel.jacobson)
  1389. (goto-char (point-min))
  1390. (while (re-search-forward mail-extr-bad-dot-pattern nil t)
  1391. (replace-match "\\1 \\2" t)))))
  1392. ;; Loop over the words (and other junk) in the name.
  1393. (goto-char (point-min))
  1394. (while (not name-done-flag)
  1395. (when word-found-flag
  1396. ;; Last time through this loop we skipped over a word.
  1397. (setq last-word-beg this-word-beg)
  1398. (setq drop-last-word-if-trailing-flag
  1399. drop-this-word-if-trailing-flag)
  1400. (setq word-found-flag nil))
  1401. (when begin-again-flag
  1402. ;; Last time through the loop we found something that
  1403. ;; indicates we should pretend we are beginning again from
  1404. ;; the start.
  1405. (setq word-count 0)
  1406. (setq last-word-beg nil)
  1407. (setq drop-last-word-if-trailing-flag nil)
  1408. (setq mixed-case-flag nil)
  1409. (setq lower-case-flag nil)
  1410. ;; (setq upper-case-flag nil)
  1411. (setq begin-again-flag nil))
  1412. ;; Initialize for this iteration of the loop.
  1413. (mail-extr-skip-whitespace-forward)
  1414. (if (eq word-count 0) (narrow-to-region (point) (point-max)))
  1415. (setq this-word-beg (point))
  1416. (setq drop-this-word-if-trailing-flag nil)
  1417. ;; Decide what to do based on what we are looking at.
  1418. (cond
  1419. ;; Delete title
  1420. ((and (eq word-count 0)
  1421. (looking-at mail-extr-full-name-prefixes))
  1422. (goto-char (match-end 0))
  1423. (narrow-to-region (point) (point-max)))
  1424. ;; Stop after name suffix
  1425. ((and (>= word-count 2)
  1426. (looking-at mail-extr-full-name-suffix-pattern))
  1427. (mail-extr-skip-whitespace-backward)
  1428. (setq suffix-flag (point))
  1429. (if (eq ?, (following-char))
  1430. (forward-char 1)
  1431. (insert ?,))
  1432. ;; Enforce at least one space after comma
  1433. (or (eq ?\ (following-char))
  1434. (insert ?\ ))
  1435. (mail-extr-skip-whitespace-forward)
  1436. (cond ((memq (following-char) '(?j ?J ?s ?S))
  1437. (capitalize-word 1)
  1438. (if (eq (following-char) ?.)
  1439. (forward-char 1)
  1440. (insert ?.)))
  1441. (t
  1442. (upcase-word 1)))
  1443. (setq word-found-flag t)
  1444. (setq name-done-flag t))
  1445. ;; Handle SCA names
  1446. ((looking-at "MKA \\(.+\\)") ; "Mundanely Known As"
  1447. (goto-char (match-beginning 1))
  1448. (narrow-to-region (point) (point-max))
  1449. (setq begin-again-flag t))
  1450. ;; Check for initial last name followed by comma
  1451. ((and (eq ?, (following-char))
  1452. (eq word-count 1))
  1453. (forward-char 1)
  1454. (setq last-name-comma-flag t)
  1455. (or (eq ?\ (following-char))
  1456. (insert ?\ )))
  1457. ;; Stop before trailing comma-separated comment
  1458. ;; THIS CASE MUST BE AFTER THE PRECEDING CASES.
  1459. ;; *** This case is redundant???
  1460. ;;((eq ?, (following-char))
  1461. ;; (setq name-done-flag t))
  1462. ;; Delete parenthesized/quoted comment/nickname
  1463. ((memq (following-char) '(?\( ?\{ ?\[ ?\" ?\' ?\`))
  1464. (setq mailextr-cbeg (point))
  1465. (set-syntax-table mail-extr-address-text-comment-syntax-table)
  1466. (cond ((memq (following-char) '(?\' ?\`))
  1467. (or (search-forward "'" nil t
  1468. (if (eq ?\' (following-char)) 2 1))
  1469. (delete-char 1)))
  1470. (t
  1471. (or (mail-extr-safe-move-sexp 1)
  1472. (goto-char (point-max)))))
  1473. (set-syntax-table mail-extr-address-text-syntax-table)
  1474. (setq mailextr-cend (point))
  1475. (cond
  1476. ;; Handle case of entire name being quoted
  1477. ((and (eq word-count 0)
  1478. (looking-at " *\\'")
  1479. (>= (- mailextr-cend mailextr-cbeg) 2))
  1480. (narrow-to-region (1+ mailextr-cbeg) (1- mailextr-cend))
  1481. (goto-char (point-min)))
  1482. (t
  1483. ;; Handle case of quoted initial
  1484. (if (and (or (= 3 (- mailextr-cend mailextr-cbeg))
  1485. (and (= 4 (- mailextr-cend mailextr-cbeg))
  1486. (eq ?. (char-after (+ 2 mailextr-cbeg)))))
  1487. (not (looking-at " *\\'")))
  1488. (setq initial (char-after (1+ mailextr-cbeg)))
  1489. (setq initial nil))
  1490. (delete-region mailextr-cbeg mailextr-cend)
  1491. (if initial
  1492. (insert initial ". ")))))
  1493. ;; Handle *Stupid* VMS date stamps
  1494. ((looking-at mail-extr-stupid-vms-date-stamp-pattern)
  1495. (replace-match "" t))
  1496. ;; Handle Chinese characters.
  1497. ((looking-at mail-extr-hz-embedded-gb-encoded-chinese-pattern)
  1498. (goto-char (match-end 0))
  1499. (setq word-found-flag t))
  1500. ;; Skip initial garbage characters.
  1501. ;; THIS CASE MUST BE AFTER THE PRECEDING CASES.
  1502. ((and (eq word-count 0)
  1503. (looking-at mail-extr-leading-garbage))
  1504. (goto-char (match-end 0))
  1505. ;; *** Skip backward over these???
  1506. ;; (skip-chars-backward "& \"")
  1507. (narrow-to-region (point) (point-max)))
  1508. ;; Various stopping points
  1509. ((or
  1510. ;; Stop before ALL CAPS acronyms, if preceded by mixed-case
  1511. ;; words. Example: XT-DEM.
  1512. (and (>= word-count 2)
  1513. mixed-case-flag
  1514. (looking-at mail-extr-weird-acronym-pattern)
  1515. (not (looking-at mail-extr-roman-numeral-pattern)))
  1516. ;; Stop before trailing alternative address
  1517. (looking-at mail-extr-alternative-address-pattern)
  1518. ;; Stop before trailing comment not introduced by comma
  1519. ;; THIS CASE MUST BE AFTER AN EARLIER CASE.
  1520. (looking-at mail-extr-trailing-comment-start-pattern)
  1521. ;; Stop before telephone numbers
  1522. (and (>= word-count 1)
  1523. (looking-at mail-extr-telephone-extension-pattern)))
  1524. (setq name-done-flag t))
  1525. ;; Delete ham radio call signs
  1526. ((looking-at mail-extr-ham-call-sign-pattern)
  1527. (delete-region (match-beginning 0) (match-end 0)))
  1528. ;; Fixup initials
  1529. ((looking-at mail-extr-initial-pattern)
  1530. (or (eq (following-char) (upcase (following-char)))
  1531. (setq lower-case-flag t))
  1532. (forward-char 1)
  1533. (if (eq ?. (following-char))
  1534. (forward-char 1)
  1535. (insert ?.))
  1536. (or (eq ?\ (following-char))
  1537. (insert ?\ ))
  1538. (setq word-found-flag t))
  1539. ;; Handle BITNET LISTSERV list names.
  1540. ((and (eq word-count 0)
  1541. (looking-at mail-extr-listserv-list-name-pattern))
  1542. (narrow-to-region (match-beginning 1) (match-end 1))
  1543. (setq word-found-flag t)
  1544. (setq name-done-flag t))
  1545. ;; Handle & substitution, when & is last and is not first.
  1546. ((and (> word-count 0)
  1547. (eq ?\ (preceding-char))
  1548. (eq (following-char) ?&)
  1549. (eq (1+ (point)) (point-max)))
  1550. (delete-char 1)
  1551. (capitalize-region
  1552. (point)
  1553. (progn
  1554. (insert-buffer-substring canonicalization-buffer
  1555. mbox-beg mbox-end)
  1556. (point)))
  1557. (setq disable-initial-guessing-flag t)
  1558. (setq word-found-flag t))
  1559. ;; Handle & between names, as in "Bob & Susie".
  1560. ((and (> word-count 0) (eq (following-char) ?\&))
  1561. (setq name-beg (point))
  1562. (setq name-end (1+ name-beg))
  1563. (setq word-found-flag t)
  1564. (goto-char name-end))
  1565. ;; Regular name words
  1566. ((looking-at mail-extr-name-pattern)
  1567. (setq name-beg (point))
  1568. (setq name-end (match-end 0))
  1569. ;; Certain words will be dropped if they are at the end.
  1570. (and (>= word-count 2)
  1571. (not lower-case-flag)
  1572. (or
  1573. ;; Trailing 4-or-more letter lowercase words preceded by
  1574. ;; mixed case or uppercase words will be dropped.
  1575. (looking-at "[[:lower:]]\\{4,\\}[ \t]*\\'")
  1576. ;; Drop a trailing word which is terminated with a period.
  1577. (eq ?. (char-after (1- name-end))))
  1578. (setq drop-this-word-if-trailing-flag t))
  1579. ;; Set the flags that indicate whether we have seen a lowercase
  1580. ;; word, a mixed case word, and an uppercase word.
  1581. (if (re-search-forward "[[:lower:]]" name-end t)
  1582. (if (progn
  1583. (goto-char name-beg)
  1584. (re-search-forward "[[:upper:]]" name-end t))
  1585. (setq mixed-case-flag t)
  1586. (setq lower-case-flag t))
  1587. ;; (setq upper-case-flag t)
  1588. )
  1589. (goto-char name-end)
  1590. (setq word-found-flag t))
  1591. ;; Allow a number as a word, if it doesn't mean anything else.
  1592. ((looking-at "[0-9]+\\>")
  1593. (setq name-beg (point))
  1594. (setq name-end (match-end 0))
  1595. (goto-char name-end)
  1596. (setq word-found-flag t))
  1597. (t
  1598. (setq name-done-flag t)
  1599. ))
  1600. ;; Count any word that we skipped over.
  1601. (if word-found-flag
  1602. (setq word-count (1+ word-count))))
  1603. ;; If the last thing in the name is 2 or more periods, or one or more
  1604. ;; other sentence terminators (but not a single period) then keep them
  1605. ;; and the preceding word. This is for the benefit of whole sentences
  1606. ;; in the name field: it's better behavior than dropping the last word
  1607. ;; of the sentence...
  1608. (if (and (not suffix-flag)
  1609. (looking-at "\\(\\.+\\|[?!;:.][?!;:.]+\\|[?!;:][?!;:.]*\\)\\'"))
  1610. (goto-char (setq suffix-flag (point-max))))
  1611. ;; Drop everything after point and certain trailing words.
  1612. (narrow-to-region (point-min)
  1613. (or (and drop-last-word-if-trailing-flag
  1614. last-word-beg)
  1615. (point)))
  1616. ;; Xerox's mailers SUCK!!!!!!
  1617. ;; We simply refuse to believe that any last name is PARC or ADOC.
  1618. ;; If it looks like that is the last name, that there is no meaningful
  1619. ;; here at all. Actually I guess it would be best to map patterns
  1620. ;; like foo.hoser@xerox.com into foo@hoser.xerox.com, but I don't
  1621. ;; actually know that that is what's going on.
  1622. (unless suffix-flag
  1623. (goto-char (point-min))
  1624. (let ((case-fold-search t))
  1625. (if (looking-at "[-A-Za-z_]+[. ]\\(PARC\\|ADOC\\)\\'")
  1626. (erase-buffer))))
  1627. ;; If last name first put it at end (but before suffix)
  1628. (when last-name-comma-flag
  1629. (goto-char (point-min))
  1630. (search-forward ",")
  1631. (setq name-end (1- (point)))
  1632. (goto-char (or suffix-flag (point-max)))
  1633. (or (eq ?\ (preceding-char))
  1634. (insert ?\ ))
  1635. (insert-buffer-substring (current-buffer) (point-min) name-end)
  1636. (goto-char name-end)
  1637. (skip-chars-forward "\t ,")
  1638. (narrow-to-region (point) (point-max)))
  1639. ;; Delete leading and trailing junk characters.
  1640. ;; *** This is probably completely unneeded now.
  1641. ;;(goto-char (point-max))
  1642. ;;(skip-chars-backward mail-extr-non-end-name-chars)
  1643. ;;(if (eq ?. (following-char))
  1644. ;; (forward-char 1))
  1645. ;;(narrow-to-region (point)
  1646. ;; (progn
  1647. ;; (goto-char (point-min))
  1648. ;; (skip-chars-forward mail-extr-non-begin-name-chars)
  1649. ;; (point)))
  1650. ;; Compress whitespace
  1651. (goto-char (point-min))
  1652. (while (re-search-forward "[ \t\n]+" nil t)
  1653. (replace-match (if (eobp) "" " ") t))
  1654. ))))
  1655. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1656. ;;
  1657. ;; Table of top-level domain names.
  1658. ;;
  1659. ;; This is used during address canonicalization; be careful of format changes.
  1660. ;; Keep in mind that the country abbreviations follow ISO-3166. There is
  1661. ;; a U.S. FIPS that specifies a different set of two-letter country
  1662. ;; abbreviations.
  1663. ;;
  1664. ;; Updated by the RIPE Network Coordination Centre.
  1665. ;;
  1666. ;; Source: ISO 3166 Maintenance Agency
  1667. ;; http://www.iso.org/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1-semic.txt
  1668. ;; http://www.iana.org/domain-names.htm
  1669. ;; http://www.iana.org/cctld/cctld-whois.htm
  1670. ;; Latest change: 2007/11/15
  1671. (defconst mail-extr-all-top-level-domains
  1672. (let ((ob (make-vector 739 0)))
  1673. (mapc
  1674. (lambda (x)
  1675. (put (intern (downcase (car x)) ob)
  1676. 'domain-name
  1677. (if (nth 2 x)
  1678. (format (nth 2 x) (nth 1 x))
  1679. (nth 1 x))))
  1680. '(
  1681. ;; ISO 3166 codes:
  1682. ("ac" "Ascension Island")
  1683. ("ad" "Andorra")
  1684. ("ae" "United Arab Emirates")
  1685. ("af" "Afghanistan")
  1686. ("ag" "Antigua and Barbuda")
  1687. ("ai" "Anguilla")
  1688. ("al" "Albania")
  1689. ("am" "Armenia")
  1690. ("an" "Netherlands Antilles")
  1691. ("ao" "Angola")
  1692. ("aq" "Antarctica") ; continent
  1693. ("ar" "Argentina" "Argentine Republic")
  1694. ("as" "American Samoa")
  1695. ("at" "Austria" "The Republic of %s")
  1696. ("au" "Australia")
  1697. ("aw" "Aruba")
  1698. ("ax" "Aland Islands")
  1699. ("az" "Azerbaijan")
  1700. ("ba" "Bosnia-Herzegovina")
  1701. ("bb" "Barbados")
  1702. ("bd" "Bangladesh")
  1703. ("be" "Belgium" "The Kingdom of %s")
  1704. ("bf" "Burkina Faso")
  1705. ("bg" "Bulgaria")
  1706. ("bh" "Bahrain")
  1707. ("bi" "Burundi")
  1708. ("bj" "Benin")
  1709. ("bl" "Saint Barthelemy")
  1710. ("bm" "Bermuda")
  1711. ("bn" "Brunei Darussalam")
  1712. ("bo" "Bolivia" "Republic of %s")
  1713. ("br" "Brazil" "The Federative Republic of %s")
  1714. ("bs" "Bahamas")
  1715. ("bt" "Bhutan")
  1716. ("bv" "Bouvet Island")
  1717. ("bw" "Botswana")
  1718. ("by" "Belarus")
  1719. ("bz" "Belize")
  1720. ("ca" "Canada")
  1721. ("cc" "Cocos (Keeling) Islands")
  1722. ("cd" "Congo" "The Democratic Republic of the %s")
  1723. ("cf" "Central African Republic")
  1724. ("cg" "Congo")
  1725. ("ch" "Switzerland" "The Swiss Confederation")
  1726. ("ci" "Ivory Coast") ; Cote D'ivoire
  1727. ("ck" "Cook Islands")
  1728. ("cl" "Chile" "The Republic of %s")
  1729. ("cm" "Cameroon") ; In .fr domain
  1730. ("cn" "China" "The People's Republic of %s")
  1731. ("co" "Colombia")
  1732. ("cr" "Costa Rica" "The Republic of %s")
  1733. ("cu" "Cuba")
  1734. ("cv" "Cape Verde")
  1735. ("cx" "Christmas Island")
  1736. ("cy" "Cyprus")
  1737. ("cz" "Czech Republic")
  1738. ("de" "Germany")
  1739. ("dj" "Djibouti")
  1740. ("dk" "Denmark")
  1741. ("dm" "Dominica")
  1742. ("do" "Dominican Republic" "The %s")
  1743. ("dz" "Algeria")
  1744. ("ec" "Ecuador" "The Republic of %s")
  1745. ("ee" "Estonia")
  1746. ("eg" "Egypt" "The Arab Republic of %s")
  1747. ("eh" "Western Sahara")
  1748. ("er" "Eritrea")
  1749. ("es" "Spain" "The Kingdom of %s")
  1750. ("et" "Ethiopia")
  1751. ("eu" "European Union")
  1752. ("fi" "Finland" "The Republic of %s")
  1753. ("fj" "Fiji")
  1754. ("fk" "Falkland Islands (Malvinas)")
  1755. ("fm" "Micronesia" "Federated States of %s")
  1756. ("fo" "Faroe Islands")
  1757. ("fr" "France")
  1758. ("ga" "Gabon")
  1759. ("gb" "United Kingdom")
  1760. ("gd" "Grenada")
  1761. ("ge" "Georgia")
  1762. ("gf" "French Guiana")
  1763. ("gg" "Guernsey")
  1764. ("gh" "Ghana")
  1765. ("gi" "Gibraltar")
  1766. ("gl" "Greenland")
  1767. ("gm" "Gambia")
  1768. ("gn" "Guinea")
  1769. ("gp" "Guadeloupe (Fr.)")
  1770. ("gq" "Equatorial Guinea")
  1771. ("gr" "Greece" "The Hellenic Republic (%s)")
  1772. ("gs" "South Georgia and The South Sandwich Islands")
  1773. ("gt" "Guatemala")
  1774. ("gu" "Guam (U.S.)")
  1775. ("gw" "Guinea-Bissau")
  1776. ("gy" "Guyana")
  1777. ("hk" "Hong Kong")
  1778. ("hm" "Heard Island and McDonald Islands")
  1779. ("hn" "Honduras")
  1780. ("hr" "Croatia" "Croatia (Hrvatska)")
  1781. ("ht" "Haiti")
  1782. ("hu" "Hungary" "The Hungarian Republic")
  1783. ("id" "Indonesia")
  1784. ("ie" "Ireland")
  1785. ("il" "Israel" "The State of %s")
  1786. ("im" "Isle of Man" "The %s") ; NOT in ISO 3166-1 of 2001-02-26
  1787. ("in" "India" "The Republic of %s")
  1788. ("io" "British Indian Ocean Territory")
  1789. ("iq" "Iraq")
  1790. ("ir" "Iran" "Islamic Republic of %s")
  1791. ("is" "Iceland" "The Republic of %s")
  1792. ("it" "Italy" "The Italian Republic")
  1793. ("je" "Jersey")
  1794. ("jm" "Jamaica")
  1795. ("jo" "Jordan")
  1796. ("jp" "Japan")
  1797. ("ke" "Kenya")
  1798. ("kg" "Kyrgyzstan")
  1799. ("kh" "Cambodia")
  1800. ("ki" "Kiribati")
  1801. ("km" "Comoros")
  1802. ("kn" "Saint Kitts and Nevis")
  1803. ("kp" "Korea (North)" "Democratic People's Republic of Korea")
  1804. ("kr" "Korea (South)" "Republic of Korea")
  1805. ("kw" "Kuwait")
  1806. ("ky" "Cayman Islands")
  1807. ("kz" "Kazakhstan")
  1808. ("la" "Lao People's Democratic Republic")
  1809. ("lb" "Lebanon")
  1810. ("lc" "Saint Lucia")
  1811. ("li" "Liechtenstein")
  1812. ("lk" "Sri Lanka" "The Democratic Socialist Republic of %s")
  1813. ("lr" "Liberia")
  1814. ("ls" "Lesotho")
  1815. ("lt" "Lithuania")
  1816. ("lu" "Luxembourg")
  1817. ("lv" "Latvia")
  1818. ("ly" "Libyan Arab Jamahiriya")
  1819. ("ma" "Morocco")
  1820. ("mc" "Monaco")
  1821. ("md" "Moldova" "The Republic of %s")
  1822. ("me" "Montenegro")
  1823. ("mf" "Saint Martin (French part)")
  1824. ("mg" "Madagascar")
  1825. ("mh" "Marshall Islands")
  1826. ("mk" "Macedonia" "The Former Yugoslav Republic of %s")
  1827. ("ml" "Mali")
  1828. ("mm" "Myanmar")
  1829. ("mn" "Mongolia")
  1830. ("mo" "Macao")
  1831. ("mp" "Northern Mariana Islands")
  1832. ("mq" "Martinique")
  1833. ("mr" "Mauritania")
  1834. ("ms" "Montserrat")
  1835. ("mt" "Malta")
  1836. ("mu" "Mauritius")
  1837. ("mv" "Maldives")
  1838. ("mw" "Malawi")
  1839. ("mx" "Mexico" "The United Mexican States")
  1840. ("my" "Malaysia")
  1841. ("mz" "Mozambique")
  1842. ("na" "Namibia")
  1843. ("nc" "New Caledonia (Fr.)")
  1844. ("ne" "Niger") ; In .fr domain
  1845. ("nf" "Norfolk Island")
  1846. ("ng" "Nigeria")
  1847. ("ni" "Nicaragua" "The Republic of %s")
  1848. ("nl" "Netherlands" "The Kingdom of the %s")
  1849. ("no" "Norway" "The Kingdom of %s")
  1850. ("np" "Nepal") ; Via .in domain
  1851. ("nr" "Nauru")
  1852. ("nu" "Niue")
  1853. ("nz" "New Zealand")
  1854. ("om" "Oman")
  1855. ("pa" "Panama")
  1856. ("pe" "Peru")
  1857. ("pf" "French Polynesia")
  1858. ("pg" "Papua New Guinea")
  1859. ("ph" "Philippines" "The Republic of the %s")
  1860. ("pk" "Pakistan")
  1861. ("pl" "Poland")
  1862. ("pm" "Saint Pierre and Miquelon")
  1863. ("pn" "Pitcairn")
  1864. ("pr" "Puerto Rico (U.S.)")
  1865. ("ps" "Palestinian Territory, Occupied")
  1866. ("pt" "Portugal" "The Portuguese Republic")
  1867. ("pw" "Palau")
  1868. ("py" "Paraguay")
  1869. ("qa" "Qatar")
  1870. ("re" "Reunion (Fr.)") ; In .fr domain
  1871. ("ro" "Romania")
  1872. ("rs" "Serbia")
  1873. ("ru" "Russia" "Russian Federation")
  1874. ("rw" "Rwanda")
  1875. ("sa" "Saudi Arabia")
  1876. ("sb" "Solomon Islands")
  1877. ("sc" "Seychelles")
  1878. ("sd" "Sudan")
  1879. ("se" "Sweden" "The Kingdom of %s")
  1880. ("sg" "Singapore" "The Republic of %s")
  1881. ("sh" "Saint Helena")
  1882. ("si" "Slovenia")
  1883. ("sj" "Svalbard and Jan Mayen") ; In .no domain
  1884. ("sk" "Slovakia" "The Slovak Republic")
  1885. ("sl" "Sierra Leone")
  1886. ("sm" "San Marino")
  1887. ("sn" "Senegal")
  1888. ("so" "Somalia")
  1889. ("sr" "Suriname")
  1890. ("st" "Sao Tome and Principe")
  1891. ("su" "U.S.S.R." "The Union of Soviet Socialist Republics")
  1892. ("sv" "El Salvador")
  1893. ("sy" "Syrian Arab Republic")
  1894. ("sz" "Swaziland")
  1895. ("tc" "Turks and Caicos Islands")
  1896. ("td" "Chad")
  1897. ("tf" "French Southern Territories")
  1898. ("tg" "Togo")
  1899. ("th" "Thailand" "The Kingdom of %s")
  1900. ("tj" "Tajikistan")
  1901. ("tk" "Tokelau")
  1902. ("tl" "East Timor")
  1903. ("tm" "Turkmenistan")
  1904. ("tn" "Tunisia")
  1905. ("to" "Tonga")
  1906. ("tp" "East Timor")
  1907. ("tr" "Turkey" "The Republic of %s")
  1908. ("tt" "Trinidad and Tobago")
  1909. ("tv" "Tuvalu")
  1910. ("tw" "Taiwan" "%s, Province of China")
  1911. ("tz" "Tanzania" "United Republic of %s")
  1912. ("ua" "Ukraine")
  1913. ("ug" "Uganda")
  1914. ("uk" "United Kingdom" "The %s of Great Britain and Northern Ireland")
  1915. ("um" "United States Minor Outlying Islands")
  1916. ("us" "United States" "The %s of America")
  1917. ("uy" "Uruguay" "The Eastern Republic of %s")
  1918. ("uz" "Uzbekistan")
  1919. ("va" "Holy See (Vatican City State)")
  1920. ("vc" "Saint Vincent and the Grenadines")
  1921. ("ve" "Venezuela" "The Republic of %s")
  1922. ("vg" "Virgin Islands, British")
  1923. ("vi" "Virgin Islands, U.S.")
  1924. ("vn" "Vietnam")
  1925. ("vu" "Vanuatu")
  1926. ("wf" "Wallis and Futuna")
  1927. ("ws" "Samoa")
  1928. ("ye" "Yemen")
  1929. ("yt" "Mayotte")
  1930. ("yu" "Yugoslavia" "Yugoslavia, AKA Serbia-Montenegro")
  1931. ("za" "South Africa" "The Republic of %s")
  1932. ("zm" "Zambia")
  1933. ("zw" "Zimbabwe" "Republic of %s")
  1934. ;; Generic Domains:
  1935. ("aero" t "Air Transport Industry")
  1936. ("asia" t "Pan-Asia and Asia Pacific community")
  1937. ("biz" t "Businesses")
  1938. ("cat" t "Catalan language and culture")
  1939. ("com" t "Commercial")
  1940. ("coop" t "Cooperative Associations")
  1941. ("info" t "Info")
  1942. ("jobs" t "Employment")
  1943. ("mobi" t "Mobile products")
  1944. ("museum" t "Museums")
  1945. ("name" t "Individuals")
  1946. ("net" t "Network")
  1947. ("org" t "Non-profit Organization")
  1948. ("pro" t "Credentialed professionals")
  1949. ("tel" t "Contact data")
  1950. ("travel" t "Travel industry")
  1951. ;;("bitnet" t "Because It's Time NET")
  1952. ("gov" t "United States Government")
  1953. ("edu" t "Educational")
  1954. ("mil" t "United States Military")
  1955. ("int" t "International Treaties")
  1956. ;;("nato" t "North Atlantic Treaty Organization")
  1957. ("uucp" t "Unix to Unix CoPy")
  1958. ;; Infrastructure Domains:
  1959. ("arpa" t "Advanced Research Projects Agency (U.S. DoD)")
  1960. ))
  1961. ob))
  1962. ;;;###autoload
  1963. (defun what-domain (domain)
  1964. "Convert mail domain DOMAIN to the country it corresponds to."
  1965. (interactive
  1966. (let ((completion-ignore-case t))
  1967. (list (completing-read "Domain: "
  1968. mail-extr-all-top-level-domains nil t))))
  1969. (or (setq domain (intern-soft (downcase domain)
  1970. mail-extr-all-top-level-domains))
  1971. (error "No such domain"))
  1972. (message "%s: %s" (upcase (symbol-name domain)) (get domain 'domain-name)))
  1973. ;(let ((all nil))
  1974. ; (mapatoms #'(lambda (x)
  1975. ; (if (and (boundp x)
  1976. ; (string-match "^mail-extr-" (symbol-name x)))
  1977. ; (setq all (cons x all)))))
  1978. ; (setq all (sort all #'string-lessp))
  1979. ; (cons 'setq
  1980. ; (apply 'nconc (mapcar #'(lambda (x)
  1981. ; (list x (symbol-value x)))
  1982. ; all))))
  1983. (provide 'mail-extr)
  1984. ;;; mail-extr.el ends here