mail-extr.el 74 KB

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