view lisp/mail/mail-extr.el @ 107863:594e81986a75

2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-insert-link): Find the link buffer on visible frames. (org-export-latex-default-packages-alist): hyperref must be loaded late. (org-open-file): More care with the new matching for file links. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-latex.el (org-export-latex-preprocess): Do not yet protect defined entities - these will be taken care of later. (org-export-latex-special-chars): Post-process entity replacement. (org-export-latex-fontify-headline): Do not yet protect defined entities - these will be taken care of later. (org-export-latex-tables, org-export-latex-links): Format the caption properly. * org-entities.el (org-entities-user): Fix typo. * org.el (org-prepare-agenda-buffers): Uniquify TODO keywords * org-entities.el (org-entities-user): Improve docstring. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-entities.el (org-macs): Require org-macs, to be sure that we have `declare-function' defined. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-latex.el (org-export-latex-classes): Update docstring. * org.el (org-format-latex-header): Add cookies to the header. (org-splice-latex-header): Implement placement according to cookies. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-publish.el (org-publish-aux-preprocess): Control case sensitivity. 2010-04-10 Bastien Guerry <bzg@altern.org> * org.el (org-splice-latex-header): Fix typo. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-latex.el (org-export-latex-make-header): Use `org-splice-latex-header' to build the header. (org-export-latex-classes): Update docstring. * org.el (org-splice-latex-header): New function. (org-create-formula-image): Use `org-splice-latex-header' to build the header. * org-gnus.el (org-gnus-follow-link): Handle nndoc backend. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-export-latex-packages-alist) (org-export-latex-default-packages-alist): Fix docstring to reflect the expected structure. * org-docbook.el (org-docbook-do-expand): Fix bug with variable names. (org-export-docbook-finalize-table): Make use of label for tables. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-attach.el (org-attach-commit): Split on newlines. * org.el (org-export-latex-default-packages-alist): Use list instead of cons for the entries. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-entities.el (org-entity-get-representation): Catch the case that there is not entry in the list. * org-mobile.el (org-mobile-use-encryption) (org-mobile-encryption-tempfile, org-mobile-encryption-password): New options. (org-mobile-check-setup): CHeck the encryption setup. (org-mobile-copy-agenda-files, org-mobile-sumo-agenda-command) (org-mobile-create-sumo-agenda): Use encryption code. (org-mobile-encrypt-and-move): New function. (org-mobile-encrypt-file, org-mobile-decrypt-file): New functions. (org-mobile-move-capture): Decrypt the capture file. * org.el (org-entities): Require the new file. (org-export-latex-default-packages-alist): New variable. (org-complete): Use new entity code for completion. (org-create-formula-image): Use the new packages variable. * org-latex.el (org-export-latex-classes): Remove the standard packages from the class headers. (org-export-latex-make-header): Use the new package variable. (org-export-latex-special-chars): Better regexp for entities, to support entity name that contain numbers. (org-export-latex-treat-backslash-char): Use the new entity code. * org-html.el (org-html-do-expand): Use the new entity code. * org-exp.el (org-export): Add the new export commands. (org-html-entities): Constant removed. (org-export-visible): Add the new export commands. * org-entities.el: New file. * org-docbook.el (org-docbook-do-expand): Use new entity code. * org-ascii.el (org-export-ascii-entities): New variable. (org-export-as-latin1, org-export-as-latin1-to-buffer) (org-export-as-utf8, org-export-as-utf8-to-buffer): New commands. (org-export-as-encoding): New function. (org-export-ascii-preprocess): Call `org-ascii-replace-entities'. (org-ascii-replace-entities): New function. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-html.el (org-html-level-start): Catch the case that target might be nil. 2010-04-10 Dan Davison <davison@stats.ox.ac.uk> * org.el (org-appearance): Change Customize group variable name from org-font-lock to org-appearance, and change tag from "Org Font Lock" to "Org Appearance" (org-odd-levels-only): Change Customize group variable name (org-level-color-stars-only): Change Customize group variable name (org-hide-leading-stars): Change Customize group variable name (org-hidden-keywords): Change Customize group variable name (org-fontify-done-headline): Change Customize group variable name (org-fontify-emphasized-text): Change Customize group variable name (org-fontify-whole-heading-line): Change Customize group variable name (org-highlight-latex-fragments-and-specials): Change Customize group variable name (org-hide-emphasis-markers): Change Customize group variable name (org-emphasis-alist): Change Customize group variable name (org-emphasis-regexp-components): Change Customize group variable name (org-modules): Remove mention of org-R * org-faces.el (org-faces): Change Customize group variable name 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-agenda.el (org-diary-last-run-time): New variable. (org-diary): prepare agenda buffers only if last call was some time ago. * org-html.el (org-export-html-preprocess): Replace \ref macros with a link. (org-format-org-table-html): Add the label as an anchor. * org-docbook.el (org-export-docbook-format-image): Do some formatting on captions. * org-latex.el (org-export-latex-tables, org-export-latex-links): Do some formatting on captions. * org-html.el (org-export-html-format-image) (org-format-org-table-html): Do some formatting on captions. 2010-04-10 Dan Davison <davison@stats.ox.ac.uk> * org.el (org-hidden-keywords): New customizable variable. This is a list of symbols specifying which of the special keywords #+DATE, #+AUTHOR, #+EMAIL and #+TITLE should be hidden by font lock. (org-fontify-meta-lines-and-blocks): Changes to font-lock code implementing new faces and hiding behaviour. * org-faces.el (org-document-title): New face for #+TITLE lines (org-document-info): New face for #+DATE, #+AUTHOR, #+EMAIL lines (org-document-info-keyword): New face for #+DATE, #+AUTHOR, #+EMAIL keywords 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-publish.el (org-publish-sanitize-plist): New function to rename "index" properties to "sitemap". Do this renaming globally. (org-publish-with-aux-preprocess-maybe): New macro. (org-publish-org-to-pdf, org-publish-org-to-html): Use the new macro. (org-publish-aux-preprocess) (org-publish-index-generate-theindex.inc): New function. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-table.el (org-table-align): Interpret <N> at fixed width, not as maximum width. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-exp.el (org-export-author-info, org-export-email-info): Fix docstrings. * org-beamer.el (org-beamer-select-environment): Renamed from `org-beamer-set-environment-tag'. Improve docstring. * org-freemind.el (org-freemind-write-mm-buffer): Fix another problem with odd levels. * org-ascii.el (org-export-as-ascii): Export email only if the author wants it. * org-docbook.el (org-export-as-docbook): Export email only if the author wants it. * org-html.el (org-export-as-html): Export email only if the author wants it. * org-exp.el (org-export-email-info): New option. (org-export-plist-vars): Add entry for `org-export-email'. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-table.el (org-table-goto-line): Fix typo. 2010-04-10 Mikael Fornius <mfo@abc.se> * org.el (org-agenda-files): Typo. (org-read-agenda-file-list): Add optional argument to help `org-store-new-agenda-file-list' to remember un-expanded file names. Expand file names relative to `org-directory'. (org-store-new-agenda-file-list): Keep un-expanded file names when saving, if available. (org-agenda-files): Update documentation. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-ascii.el (org-export-as-ascii): Catch the case of exporting a buffer with no file name attached. * org.el (org-log-refile): New option. (org-log-note-headings): Add a heading for refiling. (org-startup-options): Add keywords for logging of the refile action. (org-refile): Add logging action. (org-add-log-note): Allow for refiling action. * org-agenda.el (org-agenda-bulk-action): Make sure `org-log-refile' is not `note' during a bulk action. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-map-dblocks): Use save-excursion to remember the position. * org-attach.el (org-attach-commit): Remove dependence on xargs. (org-attach-delete-one): Commit after deleting a file. * org-latex.el (org-export-latex-fontify): Do not mistake table.el borders for strike-through emphasis. * org-freemind.el (org-freemind-write-mm-buffer): Simplify the handling of odd levels. * org-agenda.el (org-agenda-todo-ignore-deadlines): Document `past' and `future' values. (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item): Handle `past' and `future' values. * org.el (org-read-agenda-file-list): Interpret file names relative to org-directory and allow environment variables and "~". * org-latex.el (org-export-latex-special-chars): Allow a parenthesis before an exponent or subscript. 2010-04-10 Dan Davison <davison@stats.ox.ac.uk> * org-src.el (org-edit-src-exit): When returning from code edit buffer, if code block is hidden, leave point at start of #+begin_src line 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-insert-heading): Do not remove all spaces if the headline is empty. * org-indent.el (org-indent): Fix group name. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-table.el (org-table-goto-column): Fix forcing a non-existing column. (org-table-get, org-table-put, org-table-goto-line) (org-table-current-line): New functions. 2010-04-10 Jan Bcker <jan.boecker@jboecker.de> * org.el (org-open-file): Allow regular expressions in org-file-apps to capture link parameters using groups. In a command string to be executed, the parameters can be referenced using %1, %2, etc. Lisp forms can access them using (match-string n link). (org-apps-regexp-alist): Adopt the created regexp, as this is now matched against a file: link instead of the file name. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-crypt.el (org-reveal-start-hook): Add a decryption function to this hook. (org-decrypt-entries, org-encrypt-entries, org-decrypt-entry): Add docstrings. * org.el (org-point-at-end-of-empty-headline) (org-level-increment, org-get-previous-line-level): New function. (org-cycle-level): Rewritten to be independent of when this function is called. (org-in-regexps-block-p): New function. (org-reveal-start-hook): New hook. (org-reveal): Run new hook. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-latex.el (org-export-latex-keywords): Start a new paragraph after time keywords, do not add "\newline". * org-html.el (org-export-as-html): Avoid double # in href. * org.el (org-refile-get-location): Catch an invalid target specification. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-agenda.el (org-agenda-add-entry-to-org-agenda-diary-file): Make sure the behavior regarding to extracting time is consistent. 2010-04-10 Stephen Eglen <stephen@gnu.org> * org-agenda.el (org-agenda-insert-diary-extract-time): New variable. (org-agenda-add-entry-to-org-agenda-diary-file): Use this new variable rather than `org-agenda-search-headline-for-time'. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-list.el (org-fix-bullet-type): Improve cursor positioning. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-adaptive-fill-regexp-backup): New variable. (org-set-autofill-regexps): Store a backup of `adaptive-fill-regexp'. (org-adaptive-fill-function): Fix filling of comments and ordered lists. If there is no other match, till try adaptive fill. 2010-04-10 John Wiegley <jwiegley@gmail.com> * org-agenda.el (org-agenda-include-deadlines): Added new customization variable to determine whether unscheduled tasks should appear in the agenda solely because of their deadline. Default to true, which was the previous behavior (it just wasn't configurable). (org-agenda-mode-map, org-agenda-view-mode-dispatch): Bind ! in the agenda to show/hide deadline tasks. (org-agenda-menu): Added menu option for show/hide deadlines. (org-agenda-list): Make the agenda list sensitive to the value of `org-agenda-include-deadlines'. (org-agenda-toggle-deadlines): New function to toggle the value of `org-agenda-include-deadlines' and repaint the modeline indicators. (org-agenda-set-mode-name): Show "Deadlines" in the agenda modeline if deadline tasks are being displayed. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-table.el (org-table-eval-formula): Replace $# and @# by current column and row number. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-set-property, org-delete-property): Go back to prompting for the property. * org-latex.el (org-export-latex-make-header): Fully process author line. (org-export-latex-fontify-headline): Allow several arguments, not just one. (org-export-latex-fix-inputenc): Catch the error when `latexenc-coding-system-to-inputenc' is not defined. * org-agenda.el (org-agenda-skip-if-todo): New function. (org-agenda-skip-if): Add conditions for TODO keywords. (org-agenda-skip-if): Document the new todo conditions. 2010-04-10 Mikael Fornius <mfo@abc.se> * org.el (org-at-property-p): Check if we are inside a property drawer not just any drawer. (org-set-property, org-delete-property): When cursor is on a property key value pair do not prompt for property name instead use name at cursor. (org-ctrl-c-ctrl-c): Still do org-property-action when cursor is on the first line of a property drawer. (org-property-end-re): Spell check. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-exp.el (org-export-attach-captions-and-attributes): Add the properties to the entire table, in case the first line is removed. * org-archive.el (org-archive-reversed-order): New option. (org-archive-subtree, org-archive-to-archive-sibling): Use the new option `org-archive-reversed-order'. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-agenda.el (org-agenda-entry-types): New variable. (org-agenda-list): Use `org-agenda-entry-types'. (org-agenda-custom-commands-local-options): Support for setting `org-agenda-entry-types' as an option. (org-diary): Shift some documentation from here to the variable `org-agenda-entry-types'. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-latex.el (org-export-latex-make-header): Apply macros in author field. * org-clock.el (org-clocking-buffer, org-clocking-p): New function. (org-clock-select-task, org-clock-notify-once-if-expired) (org-clock-in, org-clock-out, org-clock-cancel, org-clock-goto) (org-clock-out-if-current, org-clock-save): Use the new functions. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-docbook.el (org-export-as-docbook): Remove unnecessary newline. (org-export-as-docbook): Remove unnecessary newline. (org-export-as-docbook): Fix problem with double footnote reference in one place. * org-exp.el (org-export-format-source-code-or-example): Remove unnecessary newline. * org.el (org-deadline, org-schedule): Allow rescheduling entries with repeaters. * org-table.el (org-table-convert-refs-to-rc): Better way to catch function calls that look like references. * org.el (org-open-at-point): Get link abbreviations from reference buffer. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-table.el (org-table-convert-refs-to-rc): Do not read arctan2 as a reference. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-link-unescape): Solve issue with lower-case escapes. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-latex.el (org-export-latex-classes): Add \usepackage{latexsym} to all classes. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-html.el (org-export-as-html): Do not allow protected lines into the table of contents. * org-latex.el (org-export-latex-special-chars): Find subsequent occurrences of special characters. (org-export-latex-tables): Do not convert table-like stuff that is protected. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-list.el (org-toggle-checkbox): No errors when updating checkbox count fails because there is no heading. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-clock.el (org-clock-report-include-clocking-task): New option. (org-clock-sum): Add the current clocking task. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-cycle): Print a message when in a table.el table. (org-edit-special): Recognize the table.el context. (org-ctrl-c-ctrl-c): Print a message when in a table.el table. * org-src.el (org-at-table.el-p): Declare. (org-edit-src-code): Handle a special case for table.el editing. (org-edit-src-find-region-and-lang): Recognize the table.el context. * org-latex.el (org-export-latex-tables): Convert table.el tables. (org-export-latex-convert-table.el-table): New function. * org-html.el (org-html-expand): Fix table.el export. * org-latex.el (org-export-latex-preprocess): Protect footnotes in headings. * org-id.el (org-id-find-id-file): Fix bug when there is no hash table for the id locations. * org.el (org-read-date-analyze): Match American-style dates, like 5/30 or 5/13/7. Make sure cal-iso.el is loaded. Don't force he current year when reading ISO and American dates. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-face-from-face-or-color): New function. (org-get-todo-face, org-font-lock-add-priority-faces) (org-get-tag-face): Use `org-face-from-face-or-color'. * org-faces.el (org-todo-keyword-faces, org-priority-faces): Allow simple colors as values. (org-faces-easy-properties): New option. * org-agenda.el (org-agenda-set-mode-name): Show if the agenda is restricted, as an agenda mode. (org-agenda-fontify-priorities): Allow simple colors as values. 2010-04-10 Bastien Guerry <bzg@altern.org> * org-timer.el (org-timer-current-timer): Renamed from `org-timer-last-timer'. (org-timer-timer1, org-timer-timer2, org-timer-timer3): Removed. (org-timer-cancel-timer, org-timer-show-remaining-time) (org-timer-set-timer): Update to use only one timer. * org.el (org-set-property): Remove useless space in the prompt. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-html.el (org-export-html-style-default): Add a default style for textareas. * org-exp.el (org-export-format-source-code-or-example): Fix textarea tag. 2010-04-10 Bastien Guerry <bzg@altern.org> * org-clock.el (org-clock-current-task): New variable to store last clocked in task. (org-clock-set-current, org-clock-delete-current): New functions. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-remember.el (org-remember-apply-template): Extend comment. (org-remember-handler): Implement clock sibling filing. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-publish.el (org-publish-all, org-publish-current-file) (org-publish-current-project): When called with prefix argument FORCE, also rebuild the validation file list. * org-latex.el (org-export-latex-preprocess): Protect footnotes in section headings. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-html.el (org-export-as-html-and-open): Kill product buffer if the user wants that. * org-latex.el (org-export-as-pdf-and-open): Kill product buffer if the user wants that. * org-exp.el (org-export-kill-product-buffer-when-displayed): New option. * org-agenda.el (org-batch-agenda-csv): Use the time property instead of the `time-of-day' property. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-timer.el (org-timer-start-hook, org-timer-stop-hook) (org-timer-pause-hook, org-timer-set-hook) (org-timer-cancel-hook): New hooks. (org-timer-start): Run `org-timer-start-hook'. (org-timer-pause-or-continue): Run `org-timer-pause-hook'. (org-timer-stop): Run `org-timer-stop-hook'. (org-timer-cancel-timers): Run `org-timer-cancel-hook'. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-reveal): Double prefix arg shows the subtree of the parent. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-agenda.el (org-search-view): Fix bug with searching full words in headlines in search view. (org-agenda-skip-deadline-prewarning-if-scheduled): New option. (org-agenda-get-deadlines): Suppress pre-warning if the entry is scheduled (if the user configures it so. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-hide-archived-subtrees): Don't jump to end of subtree if the match was not in a headline. (org-inside-latex-macro-p): Allow more complex arguments. (org-emphasize): Protect against use at end of buffer. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-agenda.el (org-agenda-align-tags): Avoid side effects on text properties. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-agenda.el (org-agenda-todo-ignore-scheduled): More allowed values. (org-agenda-todo-ignore-scheduled) (org-agenda-todo-ignore-deadlines): More control with different allowed values. (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item): Honor the new option settings. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-get-location): Make sure the selection buffer is shown in the current frame. * org-ascii.el (org-export-ascii-table-widen-columns): New option. (org-export-ascii-preprocess): Realign tables to remove narrowing if `org-export-ascii-table-widen-columns' is set. * org-table.el (org-table-do-narrow): New variable. (org-table-align): Narrow only if `org-table-do-narrow' is t. * org.el (org-deadline, org-schedule): Allow updating if the relevant time stamp does not have a repeater, i.e. do not require that no time stamp has a repeater. * org-agenda.el (org-agenda-align-tags): Don't add a face to the new white space before the tags. * org-latex.el (org-export-as-latex): Do nit require the buffer to be visiting a file when only exporting to a buffer or string. (org-export-latex-fix-inputenc): Only save the buffer is there is a file name attached to it. 2010-04-10 Dan Davison <davison@stats.ox.ac.uk> * org-src.el (org-edit-src-exit): Widen before exiting edit buffers 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-fontify-meta-lines-and-blocks): Honor `org-fontify-quote-and-verse-blocks'. * org-faces.el (org-fontify-quote-and-verse-blocks): New option. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-open-at-point): Also check for text property org-linked-text before offering collected links. 2010-04-10 Stephen Eglen <stephen@gnu.org> * org-agenda.el (org-agenda-add-entry-to-org-agenda-diary-file): Optionally extract time specification from text and add to the timestamp. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-exp.el (org-html-entities): Fix typo. * org-latex.el (org-export-latex-make-header): Use \providecommand to make sure the \alert macro is defined. * org.el (org-format-latex-signal-error) (org-create-formula-image): Use `org-format-latex-signal-error'. 2010-04-10 Stephen Eglen <stephen@gnu.org> * org.el (org-store-link): For dired buffers, use default-directory as link name if dired-get-filename returns nil. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-exp.el (org-export-concatenate-multiline-links): The for protectedness at beginning of match. * org-latex.el (org-export-latex-fix-inputenc): Never leave the AUTO as a coding system, instead default to utf8. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-block-todo-from-children-or-siblings-or-parent) (org-block-todo-from-checkboxes): Respect the local variable value when deciding if blocking should be active. * org-latex.el (org-export-latex-make-header): Define the align macro if it is not yet defined. * org-agenda.el (org-agenda-insert-diary-make-new-entry): Call `org-insert-heading' with the INVISIBLE-OK argument. * org-mac-message.el (org-mac-message-insert-flagged): Call `org-insert-heading' with the INVISIBLE-OK argument. * org.el (org-insert-heading): New argument INVISIBLE-OK. * org-agenda.el (org-agenda-view-mode-dispatch): Improve the prompt message. * org-html.el (org-html-level-start): Use the `html-container-class' text property to set an additional class for an outline container. * org-exp.el (org-export-remember-html-container-classes): New function. (org-export-preprocess-string): Call `org-export-remember-html-container-classes'. * org.el (org-cycle): Mention level cycling in the docstring. (org-default-properties): Add new property HTML_CONTAINER_CLASS. * org-remember.el (org-remember-apply-template): Do file insertion first. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-habit.el (org-habit-insert-consistency-graphs): Fix a problem with mis-aligned graphs when showing habits. 2010-04-10 Mikael Fornius <mfo@abc.se> * org.el (org-assign-fast-keys): Prefer keys used in keyword name when assigning. Begin using numerical characters when all in name is used up. This is to spare alphanumeric characters for better match with other keywords. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-exp.el (org-export-preprocess-hook): Improve documentation. * org-latex.el (org-export-latex-preprocess): More consistent conversion and protection of the words LaTeX and TeX. (org-export-latex-fontify-headline, org-export-latex-preprocess): Allow angle brackets in commands, for beamer. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-clock.el (org-clock-in): Improve the look of the clock line by formatting links. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-latex.el (org-export-latex-classes): Use AUTO as the place holder string for the coding system. And improve the documentation. (org-export-latex-fix-inputenc): Only modify the coding system if it is given by the placeholder AUTO. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-clock.el (org-task-overrun-text): New option. (org-task-overrun, org-clock-update-period): New variables. (org-clock-get-clock-string, org-clock-update-mode-line): Mark overrun clock. (org-clock-notify-once-if-expired): Check if clock is overrun. * org-faces.el: New face `org-mode-line-clock-overrun'. 2010-04-10 Jan Bcker <jan.boecker@jboecker.de> * org.el (org-narrow-to-subtree): Position the end of the narrowed region before the line with the next heading, to prevent the user from prepending text to the next headline. 2010-04-10 Stephen Eglen <stephen@gnu.org> * org-agenda.el (org-get-time-of-day): Use org-agenda-time-leading-zero to allow leading zero (rather than space) for times. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-agenda.el (org-agenda-diary-entry-in-org-file): Make sure org-datetree.el is loaded. * org-datetree.el: autoload `org-datetree-find-day-create' * org-latex.el (org-export-latex-hyperref-format): New option. (org-export-latex-links): Use `org-export-latex-hyperref-format'. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-ctags.el (org-ctags-enable): Change order of functions. (org-ctags-create-tags): Add wildcard to file name expansion. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-entry-properties): Fix some important bugs. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-link-unescape, org-link-escape): Only use hexlify if the table is not explicitly given. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-clock.el (org-clock-out-when-done): Allow a list of keywords as value. (org-clock-out-if-current): Work with the new list value of `org-clock-out-when-done'. (org-clock-out, org-clock-out-if-current): Avoid circular logic between clocking out and state changes. * org-ctags.el (org-ctags-path-to-ctags): Better system-type test. * org-latex.el (org-export-latex-treat-backslash-char): Do not by accident protect a character that is before a backslash. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-agenda.el (org-diary-class): Use `org-order-calendar-date-args'. * org.el (org-order-calendar-date-args): New function. * org-exp.el (org-export-target-internal-links): Check for protectedness after the first bracket. * org.el (org-entry-properties): Don't match wrong-case TODO keywords. * org-agenda.el (org-agenda-schedule, org-agenda-deadline): Document that ARG is passed through to remove the date. (org-agenda-bulk-action): Accept prefix arg and pass it on. Do not read a date when the user has given a `C-u' prefix. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-agenda.el (org-agenda-fix-displayed-tags): Fix bug when all tags are hidden. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-latex.el (org-export-latex-fix-inputenc): New function. (org-export-latex-inputenc-alist): New option. * org-exp.el (org-export): New key SPC to publish enclosing subtree. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-indent.el (org-indent-add-properties): Catch case when there is no headline in the buffer. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-exp.el (org-html-entities): Add checkmark symbol. * org-ascii.el (org-export-ascii-preprocess): Protect targets in verbatim code for ASCII export. * org.el (org-update-statistics-cookies): Also see checkboxes in ordered lists. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-agenda.el (org-agenda-view-mode-dispatch): Define the `L' key. * org-beamer.el (org-beamer-amend-header): Change the location where `org-beamer-header-extra' is inserted. * org.el (org-compute-latex-and-specials-regexp): Don't do BIND just for computing this regexp. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-beamer.el (org-beamer-frame-default-options): New option. (org-beamer-sectioning): Use default options if the user does not have defined any. (org-beamer-fix-toc): Put a frame around the table of contents. * org-exp.el (org-export-remove-comment-blocks-and-subtrees): Make sure case-folding works well when processing comment stuff. * org-latex.el (org-export-latex-after-save-hook): New hook. (org-export-as-latex): Run the new hook. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-beamer.el (org-beamer-environments-default): Add the note environments. (org-beamer-after-initial-vars): Allow several BEAMER_HEADER_EXTRA lines and collect and combine the content. (org-beamer-after-initial-vars): Check for note tags and make sure they will be seen like a property. * org.el (org-offer-links-in-entry): Fix bug when there is a single link. * org-exp.el (org-export): Make sure the mark is activated, also when `transient-mark-mode' is off. * org-agenda.el (org-agenda-search-view-always-boolean): New option. (org-agenda-search-view-search-words-only): Obsolete variable, is now an alias for `org-agenda-search-view-always-boolean'. (org-agenda-search-view-force-full-words): New option. (org-search-view): Improve docstring, and implement a better logic for Boolean and phrase searches. (org-agenda-last-search-view-search-was-boolean): New variable. (org-agenda-manipulate-query): Consider the type of the last search when modifying the search string. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-latex.el (org-export-as-latex): Do the first letbind in the right moment. * org-agenda.el (org-get-entries-from-diary): Add the new face to these entries. * org-faces.el (org-agenda-diary): New face. * org.el (org-make-link-regexps): Allow regexp-special characters in link types. (org-open-file): When in-emacs is `system', also force system opening, like when the value was `(16)'. (org-update-statistics-cookies): Handle entries without children. * org-exp.el (org-export-preprocess-before-normalizing-links-hook): New hook. (org-export-preprocess-string): Run the new hook. * org.el (org-offer-links-in-entry): Make RET open all links. * org-html.el (org-export-as-html): Remove any leftover display properties in the html file. * org-wl.el (org-wl-store-link): Work-around for format bug with text properties. * org-habit.el (org-habit-insert-consistency-graphs): Turn off invisibility while adding the graphs. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-remember.el (org-select-remember-template): Use C letter to customize remember templates. * org-agenda.el (org-agenda-bulk-mark, org-agenda-bulk-unmark): Move cursor to next visible line. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-beamer.el (org-beamer-sectioning): Leave columns environment by specifying 0 or 1 for column width. (org-beamer-column-widths): Make 0 stand for 0.0. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-exp.el (org-export-mark-radio-links): Don't match inside <<target>>. * org.el (org-format-latex-header-extra): New variable. (org-format-latex): Set org-format-latex-header-extra from in-buffer stuff. (org-format-latex): Add org-format-latex-header-extra to the variables on which image creation depends. (org-create-formula-image): Add the header stuff from in-buffer settings. (org-read-date-analyze): Base the analysis for future preference on NOW, not on the default date. * org-inlinetask.el (org-inlinetask-export-handler): Add CSS class for TODO keyword in inline tasks. * org.el (org-log-note-headings): New headings for removing deadline or scheduling date. (org-deadline, org-schedule): Arrange for logging when removing a date. (org-add-log-note): Handle deadline and scheduling removal. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-exp.el (org-export-visible): Add LaTeX/pdf export. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-agenda.el (org-diary-class): New function. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-latex.el (org-export-latex-preprocess): Do process the text of a radio target. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-entry-properties): Add TIMESTAMP properties back in. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-all-time-keywords): New variable. (org-set-regexps-and-options): Set `org-all-time-keywords'. (org-entry-blocked-p): New function. (org-special-properties): Add BLOCKED as a new special property. (org-entry-properties): New optional argument SPECIFIC, only parse for this property when it is specified. (org-entry-get): Pass a SPECIFIC argument to `org-entry-properties'. * org-latex.el (org-export-as-latex): Preprocess TEXT as well. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-latex.el (org-export-latex-tables): No forced line end if there is no caption. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-exp.el (org-html-entities): Add Euro symbols from Marvosym package. * org-latex.el (org-export-latex-tables): Only add a caption when macro in in longtable environments if one has been defined. * org-html.el (org-export-as-html): Only take title from buffer if not exporting body-only. * org-latex.el (org-export-latex-preprocess): Better version of the regular expression for protecting LaTeX macros. (org-export-latex-preprocess): Start searching for macros to protect from beginning of buffer. * org-exp.el (org-export-target-internal-links): Check for protectedness earlier in the string. * org-agenda.el (org-agenda-highlight-todo): Match TODO keywords case sensitively. * org-id.el (org-id-store-link): Match TODO keywords case sensitively. * org.el (org-heading-components, org-get-outline-path) (org-display-outline-path): Match TODO keywords case sensitively. * org-latex.el (org-export-as-latex): Ignore read-only properties. * org-exp.el (org-export-preprocess-string): Remove any `read-only' properties. * org-agenda.el (org-agenda-inactive-leader): New option. (org-agenda-get-timestamps): Use `org-agenda-inactive-leader'. (org-tags-view): Prompt for matcher if MATCH is an empty string. (org-todo-list): Prompt for matcher if ARG is an empty string. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-open-link-functions): New hook. (org-open-at-point): Run `org-open-link-functions'. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-agenda.el (org-agenda-date-prompt): Allow inactive time stamps as well. * org.el (org-inhibit-startup-visibility-stuff): New variable. (org-mode): Don't do startup visibility if inhibited. (org-outline-overlay-data, org-set-outline-overlay-data): New functions. (org-save-outline-visibility): New macro. (org-log-note-headings): Document that one should not change the `state' note format. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-make-link-regexps): Capture link path into a group. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-beamer.el (org-beamer-after-initial-vars): Do not overwrite the options plist. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-startup-with-beamer-mode): New option. (org-property-changed-functions) (org-property-allowed-value-functions): New hooks. (org-entry-put, org-property-get-allowed-values): Run the new hooks. (org-property-next-allowed-value): Run the new hooks. * org-exp.el (org-export-select-backend-specific-text): Add the special beamer tags. * org-beamer.el (org-export-preprocess-before-selecting-backend-code-hook): New file. * org-latex.el (org-export-latex-after-initial-vars-hook): New hook. (org-export-as-latex): Run `org-export-latex-after-initial-vars-hook'. (org-export-latex-format-toc-function) (org-export-latex-make-header): Call `org-export-latex-format-toc-function'. * org.el (org-fill-template): Make template searches case sensitive. * org-exp.el (org-export): Use "1" as a sign to export only the subtree. * org-colview-xemacs.el (org-columns-edit-value): Use org-unrestricted property. * org-colview.el (org-columns-edit-value): Use org-unrestricted property. * org.el (org-compute-property-at-point): Set org-unrestricted text property if the list contains ":ETC". (org-insert-property-drawer): Use org-unrestricted property. * org-exp.el (org-export-preprocess-before-selecting-backend-code-hook): New hook. (org-export-preprocess-string): Run `org-export-preprocess-before-selecting-backend-code-hook'. * org-xoxo.el (org-export-as-xoxo): Run `org-export-first-hook'. * org-latex.el (org-export-region-as-latex): Run `org-export-first-hook'. * org-html.el (org-export-as-html): Run `org-export-first-hook'. * org-docbook.el (org-export-as-docbook): Run `org-export-first-hook'. * org-ascii.el (org-export-as-ascii): Run `org-export-first-hook'. * org-exp.el (org-export-first-hook): New hook. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-list.el (org-previous-item): Exit at the beginning of the buffer. * org-id.el (org-id-locations-save): Only write the id locations if any are defined. * org-archive.el (org-archive-all-done): Make this work in a file with org-odd-levels-only set. * org.el (org-get-refile-targets): Catch the case when a buffer has no file. * org-latex.el (org-export-as-latex): Cleanup forced line ends where they are not needed. (org-export-latex-subcontent): Remove unnecessary newlines. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-latex.el (org-export-latex-make-header): Remove \obeylines. (org-export-latex-fontify): Fix regexp bug that takes special care of protecting the right boundary characters in emphasis matches. (org-export-latex-preprocess): Allow multiple arguments to latex macros. * org.el (org-make-link-regexps): Use John Gruber's regexp for urls. * org-macs.el (org-re): Interpret :punct: in regexps. * org-exp.el (org-export-replace-src-segments-and-examples): Also take the final newline after the END line. * org.el (org-clean-visibility-after-subtree-move): Only fix entries that are not entirely invisible already. (org-insert-link): Respect org-link-file-path-type for "docview:" links in addition to "file:" links. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-exp.el (org-export-format-source-code-or-example): Avoid additional extra white lines in LaTeX. * org-list.el (org-list-parse-list): Leave empty lines after the list, don't consider them as part of the list. * org-mobile.el (org-mobile-sumo-agenda-command): Allow tagstodo searches. * org-clock.el (org-clock-select-task): Convert integer to character for XEmacs. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-clock.el (org-clock-resolve): Make reading a char XEmacs compatible. 2010-04-10 Tassilo Horn <tassilo@member.fsf.org> * org.el (org-complete-tags-always-offer-all-agenda-tags): New variable. (org-set-tags): Use it. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-list.el (org-empty-line-terminates-plain-lists): Update docstring. * org.el (org-format-latex): Fix link creation for processed latex snippets. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-footnote.el (org-footnote-normalize): Protect replacement text. * org.el (org-inside-latex-macro-p): Save match data. 2010-04-10 Jan Bcker <jan.boecker@jboecker.de> * org-docview.el: New file. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-latex.el (org-export-latex-class-options): New variable. (org-export-latex-set-initial-vars): Use the class options. * org.el (org-forward-same-level): Stop at headings that start with an invisible character. (org-additional-option-like-keywords): Add LaTeX_CLASS_OPTIONS. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-footnote.el (org-footnote-normalize): Don't take optional arguments in LaTeX macros as footnotes. * org.el (org-inside-latex-macro-p): New function. * org-latex.el (org-latex-to-pdf-process): Change customization group to `org-export-pdf'. * org-agenda.el (org-agenda-get-blocks): Look at time string also on days after the first one. * org.el (org-insert-heading): Also check for item before assuming before-first-heading condition. * org-latex.el (org-latex-to-pdf-process): Fix typo in group tag. (org-export-pdf-logfiles): New option. (org-export-as-pdf): Use `org-export-pdf-logfiles'. (org-export-pdf-logfiles): Fix customization type. * org.el (org-insert-link): Improve error message when there is no default link to select with RET. * org-agenda.el (org-agenda-filter-by-tag): Use char argument from parameter list. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-latex.el (org-export-latex-parse-global) (org-export-latex-parse-content) (org-export-latex-parse-subcontent): Use `org-re-search-forward-unprotected'. (org-export-as-pdf): Remove log files produced by XeTeX. * org-macs.el (org-re-search-forward-unprotected): New function. 2010-04-10 James TD Smith <ahktenzero@mohorovi.cc> * org-colview.el (org-agenda-colview-summarize): Sort out some confusion between properties and titles, which resulted in agenda summaries not working if a title was set for a column. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-mobile.el (org-mobile-agendas): New option. (org-mobile-sumo-agenda-command): Select the right agendas. * org-latex.el (org-export-latex-format-image): Preserve the original-indentation property. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-clock.el (org-clock-insert-selection-line): Catch error when an old tasks no longer exists. * org-latex.el (org-export-as-pdf): Remove also the .idx file. (org-export-as-pdf): Don't remove the old PDF file before making the new one. * org-mouse.el (org-mouse-end-headline, org-mouse-insert-item) (org-mouse-context-menu): Use `org-looking-back'. * org.el (org-cycle-level): Use `org-looking-back'. * org-list.el (org-cycle-item-indentation): Use `org-looking-back'. * org-compat.el (org-looking-back): New function. * org.el (org-insert-heading): Catch before-first-headline when inserting a headline. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-latex.el (org-export-latex-format-image): Indent figure environment, so that it does not interrupt plain list. * org.el (org-open-at-point): Allow long link descriptions. 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com> * org-html.el (org-export-as-html): Remove empty lines at the beginning of the exported text. 2010-04-15 Carsten Dominik <carsten.dominik@gmail.com> * org.texi (LaTeX and PDF export): Add a footnote about xetex. (LaTeX/PDF export commands): Section renamed and moved. (Sectioning structure): Update. (References): New use case for field coordinates. (The export dispatcher): Renamed from ASCII export. (Setting up the staging area): Document the availability of encryption for MobileOrg. (Images and tables): Document how to reference labels. (Index entries): New section. (Generating an index): New section. (Column width and alignment): Document that <N> now means a fixed width, not a maximum width. (Publishing options): Document the :email option. (Beamer class export): Fix bug in the BEAMER example. (Refiling notes): Document refile logging. (In-buffer settings): Document refile logging keywords. (Drawers): Document `C-c C-z' command. (Agenda commands): Mention the alternative key `C-c C-z'. (Special properties): Document the BLOCKED property. (The spreadsheet): Mention the formula editor. (References): Document field coordinates. (Publishing action): Correct the documentation for the publishing function. (The date/time prompt): Document that we accept dates like month/day/year. (Cooperation): Document the changes in table.el support. (Faces for TODO keywords, Faces for TODO keywords) (Priorities): Document the easy colors. (Visibility cycling): Document the new double prefix arg for `org-reveal'. (Cooperation): Remember.el is part of Emacs. (Clean view): Mention that `wrap-prefix' is also set by org-indent-mode. (Agenda commands): Add information about prefix args to scheduling and deadline commands. (Search view): Point to the docstring of `org-search-view' for more details. (Agenda commands): Document that `>' prompts for a date. (Setting tags): Document variable org-complete-tags-always-offer-all-agenda-tags. (Column attributes): Cross-reference special properties.
author Carsten Dominik <carsten.dominik@gmail.com>
date Thu, 15 Apr 2010 12:11:52 +0200
parents 1d1d5d9bd884
children 280c8ae2476d 376148b31b5e
line wrap: on
line source

;;; mail-extr.el --- extract full name and address from RFC 822 mail header -*- coding: utf-8 -*-

;; Copyright (C) 1991, 1992, 1993, 1994, 1997, 2001, 2002, 2003, 2004,
;;   2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.

;; Author: Joe Wells <jbw@cs.bu.edu>
;; Maintainer: FSF
;; Keywords: mail

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;; The entry point of this code is
;;
;;    mail-extract-address-components: (address &optional all)
;;
;;    Given an RFC-822 ADDRESS, extract full name and canonical address.
;;    Returns a list of the form (FULL-NAME CANONICAL-ADDRESS).
;;    If no name can be extracted, FULL-NAME will be nil.
;;    ADDRESS may be a string or a buffer.  If it is a buffer, the visible
;;     (narrowed) portion of the buffer will be interpreted as the address.
;;     (This feature exists so that the clever caller might be able to avoid
;;     consing a string.)
;;    If ADDRESS contains more than one RFC-822 address, only the first is
;;     returned.
;;
;;    If ALL is non-nil, that means return info about all the addresses
;;     that are found in ADDRESS.  The value is a list of elements of
;;     the form (FULL-NAME CANONICAL-ADDRESS), one per address.
;;
;; This code is more correct (and more heuristic) parser than the code in
;; rfc822.el.  And despite its size, it's fairly fast.
;;
;; There are two main benefits:
;;
;; 1. Higher probability of getting the correct full name for a human than
;;    any other package we know of.  (On the other hand, it will cheerfully
;;    mangle non-human names/comments.)
;; 2. Address part is put in a canonical form.
;;
;; The interface is not yet carved in stone; please give us suggestions.
;;
;; We have an extensive test-case collection of funny addresses if you want to
;; work with the code.  Developing this code requires frequent testing to
;; make sure you're not breaking functionality.  The test cases aren't included
;; because they are over 100K.
;;
;; If you find an address that mail-extr fails on, please send it to the
;; maintainer along with what you think the correct results should be.  We do
;; not consider it a bug if mail-extr mangles a comment that does not
;; correspond to a real human full name, although we would prefer that
;; mail-extr would return the comment as-is.
;;
;; Features:
;;
;; * Full name handling:
;;
;;   * knows where full names can be found in an address.
;;   * avoids using empty comments and quoted text.
;;   * extracts full names from mailbox names.
;;   * recognizes common formats for comments after a full name.
;;   * puts a period and a space after each initial.
;;   * understands & referring to the mailbox name, capitalized.
;;   * strips name prefixes like "Prof.", etc.
;;   * understands what characters can occur in names (not just letters).
;;   * figures out middle initial from mailbox name.
;;   * removes funny nicknames.
;;   * keeps suffixes such as Jr., Sr., III, etc.
;;   * reorders "Last, First" type names.
;;
;; * Address handling:
;;
;;   * parses rfc822 quoted text, comments, and domain literals.
;;   * parses rfc822 multi-line headers.
;;   * does something reasonable with rfc822 GROUP addresses.
;;   * handles many rfc822 noncompliant and garbage addresses.
;;   * canonicalizes addresses (after stripping comments/phrases outside <>).
;;     * converts ! addresses into .UUCP and %-style addresses.
;;     * converts rfc822 ROUTE addresses to %-style addresses.
;;     * truncates %-style addresses at leftmost fully qualified domain name.
;;     * handles local relative precedence of ! vs. % and @ (untested).
;;
;; It does almost no string creation.  It primarily uses the built-in
;; parsing routines with the appropriate syntax tables.  This should
;; result in greater speed.
;;
;; TODO:
;;
;; * handle all test cases.  (This will take forever.)
;; * software to pick the correct header to use (eg., "Senders-Name:").
;; * multiple addresses in the "From:" header (almost all of the necessary
;;   code is there).
;; * flag to not treat `,' as an address separator.  (This is useful when
;;   there is a "From:" header but no "Sender:" header, because then there
;;   is only allowed to be one address.)
;; * mailbox name does not necessarily contain full name.
;; * fixing capitalization when it's all upper or lowercase.  (Hard!)
;; * some of the domain literal handling is missing.  (But I've never even
;;   seen one of these in a mail address, so maybe no big deal.)
;; * arrange to have syntax tables byte-compiled.
;; * speed hacks.
;; * delete unused variables.
;; * arrange for testing with different relative precedences of ! vs. @
;;   and %.
;; * insert documentation strings!
;; * handle X.400-gatewayed addresses according to RFC 1148.

;;; Change Log:
;;
;; Thu Feb 17 17:57:33 1994  Jamie Zawinski (jwz@lucid.com)
;;
;;	* merged with jbw's latest version
;;
;; Wed Feb  9 21:56:27 1994  Jamie Zawinski (jwz@lucid.com)
;;
;;      * high-bit chars in comments weren't treated as word syntax
;;
;; Sat Feb  5 03:13:40 1994  Jamie Zawinski (jwz@lucid.com)
;;
;;      * call replace-match with fixed-case arg
;;
;; Thu Dec 16 21:56:45 1993  Jamie Zawinski (jwz@lucid.com)
;;
;;      * some more cleanup, doc, added provide
;;
;; Tue Mar 23 21:23:18 1993  Joe Wells  (jbw at csd.bu.edu)
;;
;; 	* Made mail-full-name-prefixes a user-customizable variable.
;;        Allow passing the address as a buffer as well as a string.
;;        Allow [ and ] as name characters (Finnish character set).
;;
;; Mon Mar 22 21:20:56 1993  Joe Wells  (jbw at bigbird.bu.edu)
;;
;; 	* Handle "null" addresses.  Handle = used for spacing in mailbox
;; 	  name.  Fix bug in handling of ROUTE-ADDR-type addresses that are
;; 	  missing their brackets.  Handle uppercase "JR".  Extract full
;; 	  names from X.400 addresses encoded in RFC-822.  Fix bug in
;;        handling of multiple addresses where first has trailing comment.
;;        Handle more kinds of telephone extension lead-ins.
;;
;; Mon Mar 22 20:16:57 1993  Joe Wells  (jbw at bigbird.bu.edu)
;;
;; 	* Handle HZ encoding for embedding GB encoded chinese characters.
;;
;; Mon Mar 22 00:46:12 1993  Joe Wells  (jbw at bigbird.bu.edu)
;;
;; 	* Fixed too broad matching of ham radio call signs.  Fixed bug in
;; 	  handling an unmatched ' in a name string.  Enhanced recognition
;; 	  of when . in the mailbox name terminates the name portion.
;; 	  Narrowed conversion of . to space to only the necessary
;; 	  situation.  Deal with VMS's stupid date stamps.  Handle a unique
;; 	  way of introducing an alternate address.  Fixed spacing bug I
;; 	  introduced in switching last name order.  Fixed bug in handling
;; 	  address with ! and % but no @.  Narrowed the cases in which
;; 	  certain trailing words are discarded.
;;
;; Sun Mar 21 21:41:06 1993  Joe Wells  (jbw at bigbird.bu.edu)
;;
;; 	* Fixed bugs in handling GROUP addresses.  Certain words in the
;; 	  middle of a name no longer terminate it.  Handle LISTSERV list
;;        names.  Ignore comment field containing mailbox name.
;;
;; Sun Mar 21 14:39:38 1993  Joe Wells  (jbw at bigbird.bu.edu)
;;
;; 	* Moved variant-method code back into main function.  Handle
;; 	underscores as spaces in comments.  Handle leading nickname.  Add
;; 	flag to ignore single-word names.  Other changes.
;;
;; Mon Feb  1 22:23:31 1993  Joe Wells  (jbw at bigbird.bu.edu)
;;
;; 	* Added in changes by Rod Whitby and Jamie Zawinski.  This
;;        includes the flag mail-extr-guess-middle-initial and the fix for
;;        handling multiple addresses correctly.  (Whitby just changed
;;	  a > to a <.)
;;
;; Mon Apr  6 23:59:09 1992  Joe Wells  (jbw at bigbird.bu.edu)
;;
;; 	* Cleaned up some more.  Release version 1.0 to world.
;;
;; Sun Apr  5 19:39:08 1992  Joe Wells  (jbw at bigbird.bu.edu)
;;
;; 	* Cleaned up full name extraction extensively.
;;
;; Sun Feb  2 14:45:24 1992  Joe Wells  (jbw at bigbird.bu.edu)
;;
;; 	* Total rewrite.  Integrated mail-canonicalize-address into
;; 	mail-extract-address-components.  Now handles GROUP addresses more
;; 	or less correctly.  Better handling of lots of different cases.
;;
;; Fri Jun 14 19:39:50 1991
;;	* Created.

;;; Code:


(defgroup mail-extr nil
  "Extract full name and address from RFC 822 mail header."
  :prefix "mail-extr-"
  :group 'mail)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; User configuration variable definitions.
;;

(defcustom mail-extr-guess-middle-initial nil
  "*Whether to try to guess middle initial from mail address.
If true, then when we see an address like \"John Smith <jqs@host.com>\"
we will assume that \"John Q. Smith\" is the fellow's name."
  :type 'boolean
  :group 'mail-extr)

(defcustom mail-extr-ignore-single-names nil
  "*Whether to ignore a name that is just a single word.
If true, then when we see an address like \"Idiot <dumb@stupid.com>\"
we will act as though we couldn't find a full name in the address."
  :type 'boolean
  :version "22.1"
  :group 'mail-extr)

(defcustom mail-extr-ignore-realname-equals-mailbox-name t
"*Whether to ignore a name that is equal to the mailbox name.
If true, then when the address is like \"Single <single@address.com>\"
we will act as though we couldn't find a full name in the address."
  :type 'boolean
  :group 'mail-extr)

;; Matches a leading title that is not part of the name (does not
;; contribute to uniquely identifying the person).
(defcustom mail-extr-full-name-prefixes
  (purecopy
   "\\(Prof\\|D[Rr]\\|Mrs?\\|Rev\\|Rabbi\\|SysOp\\|LCDR\\)\\.?[ \t\n]")
  "*Matches prefixes to the full name that identify a person's position.
These are stripped from the full name because they do not contribute to
uniquely identifying the person."
  :type 'regexp
  :group 'mail-extr)

(defcustom mail-extr-@-binds-tighter-than-! nil
  "*Whether the local mail transport agent looks at ! before @."
  :type 'boolean
  :group 'mail-extr)

(defcustom mail-extr-mangle-uucp nil
  "*Whether to throw away information in UUCP addresses
by translating things like \"foo!bar!baz@host\" into \"baz@bar.UUCP\"."
  :type 'boolean
  :group 'mail-extr)

;;----------------------------------------------------------------------
;; what orderings are meaningful?????
;;(defvar mail-operator-precedence-list '(?! ?% ?@))
;; Right operand of a % or a @ must be a domain name, period.  No other
;; operators allowed.  Left operand of a @ is an address relative to that
;; site.

;; Left operand of a ! must be a domain name.  Right operand is an
;; arbitrary address.
;;----------------------------------------------------------------------



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Constant definitions.
;;

;; Any character that can occur in a name, not counting characters that
;; separate parts of a multipart name (hyphen and period).
;; Yes, there are weird people with digits in their names.
;; You will also notice the consideration for the
;; Swedish/Finnish/Norwegian character set.
(defconst mail-extr-all-letters-but-separators
  (purecopy "][[:alnum:]{|}'~`"))

;; Any character that can occur in a name in an RFC822 address including
;; the separator (hyphen and possibly period) for multipart names.
;; #### should . be in here?
(defconst mail-extr-all-letters
  (purecopy (concat mail-extr-all-letters-but-separators "---")))

;; Any character that can start a name.
;; Keep this set as minimal as possible.
(defconst mail-extr-first-letters (purecopy "[:alpha:]"))

;; Any character that can end a name.
;; Keep this set as minimal as possible.
(defconst mail-extr-last-letters (purecopy "[:alpha:]`'."))

(defconst mail-extr-leading-garbage "\\W+")

;; (defconst mail-extr-non-name-chars
;;   (purecopy (concat "^" mail-extr-all-letters ".")))
;; (defconst mail-extr-non-begin-name-chars
;;   (purecopy (concat "^" mail-extr-first-letters)))
;; (defconst mail-extr-non-end-name-chars
;;   (purecopy (concat "^" mail-extr-last-letters)))

;; Matches an initial not followed by both a period and a space.
;; (defconst mail-extr-bad-initials-pattern
;;   (purecopy
;;    (format "\\(\\([^%s]\\|\\`\\)[%s]\\)\\(\\.\\([^ ]\\)\\| \\|\\([^%s .]\\)\\|\\'\\)"
;;            mail-extr-all-letters mail-extr-first-letters mail-extr-all-letters)))

;; Matches periods used instead of spaces.  Must not match the period
;; following an initial.
(defconst mail-extr-bad-dot-pattern
  (purecopy
   (format "\\([%s][%s]\\)\\.+\\([%s]\\)"
	   mail-extr-all-letters
	   mail-extr-last-letters
	   mail-extr-first-letters)))

;; Matches an embedded or leading nickname that should be removed.
;; (defconst mail-extr-nickname-pattern
;;   (purecopy
;;    (format "\\([ .]\\|\\`\\)[\"'`\[\(]\\([ .%s]+\\)[\]\"'\)] "
;;            mail-extr-all-letters)))

;; Matches the occurrence of a generational name suffix, and the last
;; character of the preceding name.  This is important because we want to
;; keep such suffixes: they help to uniquely identify the person.
;; *** Perhaps this should be a user-customizable variable.  However, the
;; *** regular expression is fairly tricky to alter, so maybe not.
(defconst mail-extr-full-name-suffix-pattern
  (purecopy
   (format
    "\\(,? ?\\([JjSs][Rr]\\.?\\|V?I+V?\\)\\)\\([^%s]\\([^%s]\\|\\'\\)\\|\\'\\)"
    mail-extr-all-letters mail-extr-all-letters)))

(defconst mail-extr-roman-numeral-pattern (purecopy "V?I+V?\\b"))

;; Matches a trailing uppercase (with other characters possible) acronym.
;; Must not match a trailing uppercase last name or trailing initial
(defconst mail-extr-weird-acronym-pattern
  (purecopy "\\([A-Z]+[-_/]\\|[A-Z][A-Z][A-Z]?\\b\\)"))

;; Matches a mixed-case or lowercase name (not an initial).
;; #### Match Latin1 lower case letters here too?
;; (defconst mail-extr-mixed-case-name-pattern
;;   (purecopy
;;    (format
;;     "\\b\\([a-z][%s]*[%s]\\|[%s][%s]*[a-z][%s]*[%s]\\|[%s][%s]*[a-z]\\)"
;;     mail-extr-all-letters mail-extr-last-letters
;;     mail-extr-first-letters mail-extr-all-letters mail-extr-all-letters
;;     mail-extr-last-letters mail-extr-first-letters mail-extr-all-letters)))

;; Matches a trailing alternative address.
;; #### Match Latin1 letters here too?
;; #### Match _ before @ here too?
(defconst mail-extr-alternative-address-pattern
  (purecopy "\\(aka *\\)?[a-zA-Z.]+[!@][a-zA-Z.]"))

;; Matches a variety of trailing comments not including comma-delimited
;; comments.
(defconst mail-extr-trailing-comment-start-pattern
  (purecopy " [-{]\\|--\\|[+@#></\;]"))

;; Matches a name (not an initial).
;; This doesn't force a word boundary at the end because sometimes a
;; comment is separated by a `-' with no preceding space.
(defconst mail-extr-name-pattern
  (purecopy (format "\\b[%s][%s]*[%s]"
		    mail-extr-first-letters
		    mail-extr-all-letters
		    mail-extr-last-letters)))

(defconst mail-extr-initial-pattern
  (purecopy (format "\\b[%s]\\([. ]\\|\\b\\)" mail-extr-first-letters)))

;; Matches a single name before a comma.
;; (defconst mail-extr-last-name-first-pattern
;;   (purecopy (concat "\\`" mail-extr-name-pattern ",")))

;; Matches telephone extensions.
(defconst mail-extr-telephone-extension-pattern
  (purecopy
   "\\(\\([Ee]xt\\|\\|[Tt]ph\\|[Tt]el\\|[Xx]\\).?\\)? *\\+?[0-9][- 0-9]+"))

;; Matches ham radio call signs.
;; Help from: Mat Maessen N2NJZ <maessm@rpi.edu>, Mark Feit
;; <mark@era.com>, Michael Covington <mcovingt@ai.uga.edu>.
;; Examples: DX504 DX515 K5MRU K8DHK KA9WGN KA9WGN KD3FU KD6EUI KD6HBW
;; KE9TV KF0NV N1API N3FU N3GZE N3IGS N4KCC N7IKQ N9HHU W4YHF W6ANK WA2SUH
;; WB7VZI N2NJZ NR3G KJ4KK AB4UM AL7NI KH6OH WN3KBT N4TMI W1A N0NZO
(defconst mail-extr-ham-call-sign-pattern
  (purecopy "\\b\\(DX[0-9]+\\|[AKNW][A-Z]?[0-9][A-Z][A-Z]?[A-Z]?\\)"))

;; Possible trailing suffixes: "\\(/\\(KT\\|A[AEG]\\|[R0-9]\\)\\)?"
;; /KT == Temporary Technician (has CSC but not "real" license)
;; /AA == Temporary Advanced
;; /AE == Temporary Extra
;; /AG == Temporary General
;; /R  == repeater
;; /#  == stations operating out of home district
;; I don't include these in the regexp above because I can't imagine
;; anyone putting them with their name in an e-mail address.

;; Matches normal single-part name
(defconst mail-extr-normal-name-pattern
  (purecopy (format "\\b[%s][%s]+[%s]"
		    mail-extr-first-letters
		    mail-extr-all-letters-but-separators
		    mail-extr-last-letters)))

;; Matches a single word name.
;; (defconst mail-extr-one-name-pattern
;;   (purecopy (concat "\\`" mail-extr-normal-name-pattern "\\'")))

;; Matches normal two names with missing middle initial
;; The first name is not allowed to have a hyphen because this can cause
;; false matches where the "middle initial" is actually the first letter
;; of the second part of the first name.
(defconst mail-extr-two-name-pattern
  (purecopy
   (concat "\\`\\(" mail-extr-normal-name-pattern
	   "\\|" mail-extr-initial-pattern
	   "\\) +\\(" mail-extr-name-pattern "\\)\\(,\\|\\'\\)")))

(defconst mail-extr-listserv-list-name-pattern
  (purecopy "Multiple recipients of list \\([-A-Z]+\\)"))

(defconst mail-extr-stupid-vms-date-stamp-pattern
  (purecopy
   "[0-9][0-9]-[JFMASOND][aepuco][nbrylgptvc]-[0-9][0-9][0-9][0-9] [0-9]+ *"))

;;; HZ -- GB (PRC Chinese character encoding) in ASCII embedding protocol
;;
;; In ASCII mode, a byte is interpreted as an ASCII character, unless a '~' is
;; encountered. The character '~' is an escape character. By convention, it
;; must be immediately followed ONLY by '~', '{' or '\n' (<LF>), with the
;; following special meaning.
;;
;; o The escape sequence '~~' is interpreted as a '~'.
;; o The escape-to-GB sequence '~{' switches the mode from ASCII to GB.
;; o The escape sequence '~\n' is a line-continuation marker to be consumed
;;   with no output produced.
;;
;; In GB mode, characters are interpreted two bytes at a time as (pure) GB
;; codes until the escape-from-GB code '~}' is read. This code switches the
;; mode from GB back to ASCII.  (Note that the escape-from-GB code '~}'
;; ($7E7D) is outside the defined GB range.)
(defconst mail-extr-hz-embedded-gb-encoded-chinese-pattern
  (purecopy "~{\\([^~].\\|~[^\}]\\)+~}"))

;; The leading optional lowercase letters are for a bastardized version of
;; the encoding, as is the optional nature of the final slash.
(defconst mail-extr-x400-encoded-address-pattern
  (purecopy "[a-z]?[a-z]?\\(/[A-Za-z]+\\(\\.[A-Za-z]+\\)?=[^/]+\\)+/?\\'"))

(defconst mail-extr-x400-encoded-address-field-pattern-format
  (purecopy "/%s=\\([^/]+\\)\\(/\\|\\'\\)"))

(defconst mail-extr-x400-encoded-address-surname-pattern
  ;; S stands for Surname (family name).
  (purecopy
   (format mail-extr-x400-encoded-address-field-pattern-format "[Ss]")))

(defconst mail-extr-x400-encoded-address-given-name-pattern
  ;; G stands for Given name.
  (purecopy
   (format mail-extr-x400-encoded-address-field-pattern-format "[Gg]")))

(defconst mail-extr-x400-encoded-address-full-name-pattern
  ;; PN stands for Personal Name.  When used it represents the combination
  ;; of the G and S fields.
  ;; "The one system I used having this field asked it with the prompt
  ;; `Personal Name'.  But they mapped it into G and S on outgoing real
  ;; X.400 addresses.  As they mapped G and S into PN on incoming..."
  (purecopy
   (format mail-extr-x400-encoded-address-field-pattern-format "[Pp][Nn]")))



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Syntax tables used for quick parsing.
;;

(defconst mail-extr-address-syntax-table (make-syntax-table))
(defconst mail-extr-address-comment-syntax-table (make-syntax-table))
(defconst mail-extr-address-domain-literal-syntax-table (make-syntax-table))
(defconst mail-extr-address-text-comment-syntax-table (make-syntax-table))
(defconst mail-extr-address-text-syntax-table (make-syntax-table))
(mapc
 (lambda (pair)
   (let ((syntax-table (symbol-value (car pair))))
     (dolist (item (cdr pair))
       (if (eq 2 (length item))
	   ;; modifying syntax of a single character
	   (modify-syntax-entry (car item) (car (cdr item)) syntax-table)
	 ;; modifying syntax of a range of characters
	 (let ((char (nth 0 item))
	       (bound (nth 1 item))
	       (syntax (nth 2 item)))
	   (while (<= char bound)
	     (modify-syntax-entry char syntax syntax-table)
	     (setq char (1+ char))))))))
 '((mail-extr-address-syntax-table
    (?\000 ?\037 "w")			;control characters
    (?\040	 " ")			;SPC
    (?! ?~	 "w")			;printable characters
    (?\177	 "w")			;DEL
    (?\t " ")
    (?\r " ")
    (?\n " ")
    (?\( ".")
    (?\) ".")
    (?<  ".")
    (?>  ".")
    (?@  ".")
    (?,  ".")
    (?\; ".")
    (?:  ".")
    (?\\ "\\")
    (?\" "\"")
    (?.  ".")
    (?\[ ".")
    (?\] ".")
    ;; % and ! aren't RFC822 characters, but it is convenient to pretend
    (?%  ".")
    (?!  ".") ;; this needs to be word-constituent when not in .UUCP mode
    )
   (mail-extr-address-comment-syntax-table
    (?\000 ?\377 "w")
    (?\040 " ")
    (?\240 " ")
    (?\t " ")
    (?\r " ")
    (?\n " ")
    (?\( "\(\)")
    (?\) "\)\(")
    (?\\ "\\"))
   (mail-extr-address-domain-literal-syntax-table
    (?\000 ?\377 "w")
    (?\040 " ")
    (?\240 " ")
    (?\t " ")
    (?\r " ")
    (?\n " ")
    (?\[ "\(\]")			;??????
    (?\] "\)\[")			;??????
    (?\\ "\\"))
   (mail-extr-address-text-comment-syntax-table
    (?\000 ?\377 "w")
    (?\040 " ")
    (?\240 " ")
    (?\t " ")
    (?\r " ")
    (?\n " ")
    (?\( "\(\)")
    (?\) "\)\(")
    (?\[ "\(\]")
    (?\] "\)\[")
    (?\{ "\(\}")
    (?\} "\)\{")
    (?\\ "\\")
    (?\" "\"")
    ;; (?\' "\)\`")
    ;; (?\` "\(\'")
    )
   (mail-extr-address-text-syntax-table
    (?\000 ?\177 ".")
    (?\200 ?\377 "w")
    (?\040 " ")
    (?\t " ")
    (?\r " ")
    (?\n " ")
    (?A ?Z "w")
    (?a ?z "w")
    (?-    "w")
    (?\}   "w")
    (?\{   "w")
    (?|    "w")
    (?\'   "w")
    (?~    "w")
    (?0 ?9 "w"))
   ))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Utility functions and macros.
;;

;; Fixme: There are Latin-1 nbsp below.  If such characters should be
;; included, this is the wrong thing to do -- it should use syntax (or
;; regexp char classes).

(defsubst mail-extr-skip-whitespace-forward ()
  ;; v19 fn skip-syntax-forward is more tasteful, but not byte-coded.
  (skip-chars-forward " \t\n\r "))

(defsubst mail-extr-skip-whitespace-backward ()
  ;; v19 fn skip-syntax-backward is more tasteful, but not byte-coded.
  (skip-chars-backward " \t\n\r "))


(defsubst mail-extr-undo-backslash-quoting (beg end)
  (save-excursion
    (save-restriction
      (narrow-to-region beg end)
      (goto-char (point-min))
      ;; undo \ quoting
      (while (search-forward "\\" nil t)
	(delete-char -1)
	(or (eobp)
	    (forward-char 1))))))

(defsubst mail-extr-nuke-char-at (pos)
  (save-excursion
    (goto-char pos)
    (delete-char 1)
    (insert ?\ )))

(put 'mail-extr-nuke-outside-range
     'edebug-form-spec '(symbolp &optional form form atom))

(defmacro mail-extr-nuke-outside-range (list-symbol
					beg-symbol end-symbol
					&optional no-replace)
  "Delete all elements outside BEG..END in LIST.
LIST-SYMBOL names a variable holding a list of buffer positions
BEG-SYMBOL and END-SYMBOL name variables delimiting a range
Each element of LIST-SYMBOL which lies outside of the range is
 deleted from the list.
Unless NO-REPLACE is true, at each of the positions in LIST-SYMBOL
 which lie outside of the range, one character at that position is
 replaced with a SPC."
  (or (memq no-replace '(t nil))
      (error "no-replace must be t or nil, evaluable at macroexpand-time"))
  `(let ((temp ,list-symbol)
	   ch)
       (while temp
	 (setq ch (car temp))
	 (when (or (> ch ,end-symbol)
		   (< ch ,beg-symbol))
	   ,@(if no-replace
		   nil
		 `((mail-extr-nuke-char-at ch)))
	   (setcar temp nil))
	 (setq temp (cdr temp)))
       (setq ,list-symbol (delq nil ,list-symbol))))

(defun mail-extr-demarkerize (marker)
  ;; if arg is a marker, destroys the marker, then returns the old value.
  ;; otherwise returns the arg.
  (if (markerp marker)
      (let ((temp (marker-position marker)))
	(set-marker marker nil)
	temp)
    marker))

(defun mail-extr-markerize (pos)
  ;; coerces pos to a marker if non-nil.
  (if (or (markerp pos) (null pos))
      pos
    (copy-marker pos)))

(defsubst mail-extr-safe-move-sexp (arg)
  ;; Safely skip over one balanced sexp, if there is one.  Return t if success.
  (condition-case error
      (progn
	(goto-char (or (scan-sexps (point) arg) (point)))
	t)
    (error
     ;; #### kludge kludge kludge kludge kludge kludge kludge !!!
     (if (string-equal (nth 1 error) "Unbalanced parentheses")
	 nil
       (while t
	 (signal (car error) (cdr error)))))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; The main function to grind addresses
;;

(defvar disable-initial-guessing-flag)	; dynamic assignment
(defvar cbeg)				; dynamic assignment
(defvar cend)				; dynamic assignment
(defvar mail-extr-all-top-level-domains) ; Defined below.

;;;###autoload
(defun mail-extract-address-components (address &optional all)
  "Given an RFC-822 address ADDRESS, extract full name and canonical address.
Returns a list of the form (FULL-NAME CANONICAL-ADDRESS).  If no
name can be extracted, FULL-NAME will be nil.  Also see
`mail-extr-ignore-single-names' and
`mail-extr-ignore-realname-equals-mailbox-name'.

If the optional argument ALL is non-nil, then ADDRESS can contain zero
or more recipients, separated by commas, and we return a list of
the form ((FULL-NAME CANONICAL-ADDRESS) ...) with one element for
each recipient.  If ALL is nil, then if ADDRESS contains more than
one recipients, all but the first is ignored.

ADDRESS may be a string or a buffer.  If it is a buffer, the visible
\(narrowed) portion of the buffer will be interpreted as the address.
\(This feature exists so that the clever caller might be able to avoid
consing a string.)"
  (let ((canonicalization-buffer (get-buffer-create " *canonical address*"))
	(extraction-buffer (get-buffer-create " *extract address components*"))
	value-list)

    (with-current-buffer (get-buffer-create extraction-buffer)
      (fundamental-mode)
      (buffer-disable-undo extraction-buffer)
      (set-syntax-table mail-extr-address-syntax-table)
      (widen)
      (erase-buffer)
      (setq case-fold-search nil)

      ;; Insert extra space at beginning to allow later replacement with <
      ;; without having to move markers.
      (insert ?\ )

      ;; Insert the address itself.
      (cond ((stringp address)
	     (insert address))
	    ((bufferp address)
	     (insert-buffer-substring address))
	    (t
	     (error "Invalid address: %s" address)))

      (set-text-properties (point-min) (point-max) nil)

      (with-current-buffer (get-buffer-create canonicalization-buffer)
	(fundamental-mode)
	(buffer-disable-undo canonicalization-buffer)
	(setq case-fold-search nil))


      ;; Unfold multiple lines.
      (goto-char (point-min))
      (while (re-search-forward "\\([^\\]\\(\\\\\\\\\\)*\\)\n[ \t]" nil t)
	(replace-match "\\1 " t))

      ;; Loop over addresses until we have as many as we want.
      (while (and (or all (null value-list))
		  (progn (goto-char (point-min))
			 (skip-chars-forward " \t")
			 (not (eobp))))
	(let (char
	      end-of-address
	      <-pos >-pos @-pos colon-pos comma-pos !-pos %-pos \;-pos
	      group-:-pos group-\;-pos route-addr-:-pos
	      record-pos-symbol
	      first-real-pos last-real-pos
	      phrase-beg phrase-end
	      cbeg cend			; dynamically set from -voodoo
	      quote-beg quote-end
	      atom-beg atom-end
	      mbox-beg mbox-end
	      \.-ends-name
	      temp
	      ;;	name-suffix
	      fi mi li			; first, middle, last initial
	      saved-%-pos saved-!-pos saved-@-pos
	      domain-pos \.-pos insert-point
	      ;;	mailbox-name-processed-flag
	      disable-initial-guessing-flag) ; dynamically set from -voodoo

	  (set-syntax-table mail-extr-address-syntax-table)
	  (goto-char (point-min))

	  ;; Insert extra space at beginning to allow later replacement with <
	  ;; without having to move markers.
	  (or (eq (following-char) ?\ )
	      (insert ?\ ))

	  ;; First pass grabs useful information about address.
	  (while (progn
		   (mail-extr-skip-whitespace-forward)
		   (not (eobp)))
	    (setq char (char-after (point)))
	    (or first-real-pos
		(if (not (eq char ?\())
		    (setq first-real-pos (point))))
	    (cond
	     ;; comment
	     ((eq char ?\()
	      (set-syntax-table mail-extr-address-comment-syntax-table)
	      ;; only record the first non-empty comment's position
	      (if (and (not cbeg)
		       (save-excursion
			 (forward-char 1)
			 (mail-extr-skip-whitespace-forward)
			 (not (eq ?\) (char-after (point))))))
		  (setq cbeg (point)))
	      ;; TODO: don't record if unbalanced
	      (or (mail-extr-safe-move-sexp 1)
		  (forward-char 1))
	      (set-syntax-table mail-extr-address-syntax-table)
	      (if (and cbeg
		       (not cend))
		  (setq cend (point))))
	     ;; quoted text
	     ((eq char ?\")
	      ;; only record the first non-empty quote's position
	      (if (and (not quote-beg)
		       (save-excursion
			 (forward-char 1)
			 (mail-extr-skip-whitespace-forward)
			 (not (eq ?\" (char-after (point))))))
		  (setq quote-beg (point)))
	      ;; TODO: don't record if unbalanced
	      (or (mail-extr-safe-move-sexp 1)
		  (forward-char 1))
	      (if (and quote-beg
		       (not quote-end))
		  (setq quote-end (point))))
	     ;; domain literals
	     ((eq char ?\[)
	      (set-syntax-table mail-extr-address-domain-literal-syntax-table)
	      (or (mail-extr-safe-move-sexp 1)
		  (forward-char 1))
	      (set-syntax-table mail-extr-address-syntax-table))
	     ;; commas delimit addresses when outside < > pairs.
	     ((and (eq char ?,)
		   (or (and (null <-pos)
			    ;; Handle ROUTE-ADDR address that is missing its <.
			    (not (eq ?@ (char-after (1+ (point))))))
		       (and >-pos
			    ;; handle weird munged addresses
			    ;; BUG FIX: This test was reversed.  Thanks to the
			    ;; brilliant Rod Whitby <rwhitby@research.canon.oz.au>
			    ;; for discovering this!
			    (< (car (last <-pos)) (car >-pos)))))
	      ;; The argument contains more than one address.
	      ;; Temporarily hide everything after this one.
	      (setq end-of-address (copy-marker (1+ (point)) t))
	      (narrow-to-region (point-min) (1+ (point)))
	      (delete-char 1)
	      (setq char ?\() ; HAVE I NO SHAME??
	      )
	     ;; record the position of various interesting chars, determine
	     ;; validity later.
	     ((setq record-pos-symbol
		    (cdr (assq char
			       '((?< . <-pos) (?> . >-pos) (?@ . @-pos)
				 (?: . colon-pos) (?, . comma-pos) (?! . !-pos)
				 (?% . %-pos) (?\; . \;-pos)))))
	      (set record-pos-symbol
		   (cons (point) (symbol-value record-pos-symbol)))
	      (forward-char 1))
	     ((eq char ?.)
	      (forward-char 1))
	     ((memq char '(
			   ;; comment terminator invalid
			   ?\)
			   ;; domain literal terminator invalid
			   ?\]
			   ;; \ allowed only within quoted strings,
			   ;; domain literals, and comments
			   ?\\
			   ))
	      (mail-extr-nuke-char-at (point))
	      (forward-char 1))
	     (t
	      ;; Do `(forward-word 1)', recognizing non-ASCII characters
	      ;; except Latin-1 nbsp as words.
	      (while (progn
		       (skip-chars-forward "^\000-\177 ")
		       (and (not (eobp))
			    (eq ?w (char-syntax (char-after)))
			    (progn
			      (forward-word 1)
			      (and (not (eobp))
				   (> (char-after) ?\177)
				   (not (eq (char-after) ? )))))))))
	    (or (eq char ?\()
		;; At the end of first address of a multiple address header.
		(and (eq char ?,)
		     (eobp))
		(setq last-real-pos (point))))

	  ;; Use only the leftmost <, if any.  Replace all others with spaces.
	  (while (cdr <-pos)
	    (mail-extr-nuke-char-at (car <-pos))
	    (setq <-pos (cdr <-pos)))

	  ;; Use only the rightmost >, if any.  Replace all others with spaces.
	  (while (cdr >-pos)
	    (mail-extr-nuke-char-at (nth 1 >-pos))
	    (setcdr >-pos (nthcdr 2 >-pos)))

	  ;; If multiple @s and a :, but no < and >, insert around buffer.
	  ;; Example: @foo.bar.dom,@xxx.yyy.zzz:mailbox@aaa.bbb.ccc
	  ;; This commonly happens on the UUCP "From " line.  Ugh.
	  (when (and (> (length @-pos) 1)
		      (eq 1 (length colon-pos))	;TODO: check if between last two @s
		      (not \;-pos)
		      (not <-pos))
	    (goto-char (point-min))
	    (delete-char 1)
	    (setq <-pos (list (point)))
	    (insert ?<))

	  ;; If < but no >, insert > in rightmost possible position
	  (when (and <-pos (null >-pos))
	    (goto-char (point-max))
	    (setq >-pos (list (point)))
	    (insert ?>))

	  ;; If > but no <, replace > with space.
	  (when (and >-pos (null <-pos))
	    (mail-extr-nuke-char-at (car >-pos))
	    (setq >-pos nil))

	  ;; Turn >-pos and <-pos into non-lists
	  (setq >-pos (car >-pos)
		<-pos (car <-pos))

	  ;; Trim other punctuation lists of items outside < > pair to handle
	  ;; stupid MTAs.
	  (when <-pos			; don't need to check >-pos also
	    ;; handle bozo software that violates RFC 822 by sticking
	    ;; punctuation marks outside of a < > pair
	    (mail-extr-nuke-outside-range @-pos <-pos >-pos t)
	    ;; RFC 822 says nothing about these two outside < >, but
	    ;; remove those positions from the lists to make things
	    ;; easier.
	    (mail-extr-nuke-outside-range !-pos <-pos >-pos t)
	    (mail-extr-nuke-outside-range %-pos <-pos >-pos t))

	  ;; Check for : that indicates GROUP list and for : part of
	  ;; ROUTE-ADDR spec.
	  ;; Can't possibly be more than two :.  Nuke any extra.
	  (while colon-pos
	    (setq temp (car colon-pos)
		  colon-pos (cdr colon-pos))
	    (cond ((and <-pos >-pos
			(> temp <-pos)
			(< temp >-pos))
		   (if (or route-addr-:-pos
			   (< (length @-pos) 2)
			   (> temp (car @-pos))
			   (< temp (nth 1 @-pos)))
		       (mail-extr-nuke-char-at temp)
		     (setq route-addr-:-pos temp)))
		  ((or (not <-pos)
		       (and <-pos
			    (< temp <-pos)))
		   (setq group-:-pos temp))))

	  ;; Nuke any ; that is in or to the left of a < > pair or to the left
	  ;; of a GROUP starting :.  Also, there may only be one ;.
	  (while \;-pos
	    (setq temp (car \;-pos)
		  \;-pos (cdr \;-pos))
	    (cond ((and <-pos >-pos
			(> temp <-pos)
			(< temp >-pos))
		   (mail-extr-nuke-char-at temp))
		  ((and (or (not group-:-pos)
			    (> temp group-:-pos))
			(not group-\;-pos))
		   (setq group-\;-pos temp))))

	  ;; Nuke unmatched GROUP syntax characters.
	  (when (and group-:-pos (not group-\;-pos))
	    ;; *** Do I really need to erase it?
	    (mail-extr-nuke-char-at group-:-pos)
	    (setq group-:-pos nil))
	  (when (and group-\;-pos (not group-:-pos))
	    ;; *** Do I really need to erase it?
	    (mail-extr-nuke-char-at group-\;-pos)
	    (setq group-\;-pos nil))

	  ;; Handle junk like ";@host.company.dom" that sendmail adds.
	  ;; **** should I remember comment positions?
	  (when group-\;-pos
	    ;; this is fine for now
	    (mail-extr-nuke-outside-range !-pos group-:-pos group-\;-pos t)
	    (mail-extr-nuke-outside-range @-pos group-:-pos group-\;-pos t)
	    (mail-extr-nuke-outside-range %-pos group-:-pos group-\;-pos t)
	    (mail-extr-nuke-outside-range comma-pos group-:-pos group-\;-pos t)
	    (and last-real-pos
		 (> last-real-pos (1+ group-\;-pos))
		 (setq last-real-pos (1+ group-\;-pos)))
	    ;; *** This may be wrong:
	    (and cend
		 (> cend group-\;-pos)
		 (setq cend nil
		       cbeg nil))
	    (and quote-end
		 (> quote-end group-\;-pos)
		 (setq quote-end nil
		       quote-beg nil))
	    ;; This was both wrong and unnecessary:
	    ;;(narrow-to-region (point-min) group-\;-pos)

	    ;; *** The entire handling of GROUP addresses seems rather lame.
	    ;; *** It deserves a complete rethink, except that these addresses
	    ;; *** are hardly ever seen.
	    )

	  ;; Any commas must be between < and : of ROUTE-ADDR.  Nuke any
	  ;; others.
	  ;; Hell, go ahead and nuke all of the commas.
	  ;; **** This will cause problems when we start handling commas in
	  ;; the PHRASE part .... no it won't ... yes it will ... ?????
	  (mail-extr-nuke-outside-range comma-pos 1 1)

	  ;; can only have multiple @s inside < >.  The fact that some MTAs
	  ;; put de-bracketed ROUTE-ADDRs in the UUCP-style "From " line is
	  ;; handled above.

	  ;; Locate PHRASE part of ROUTE-ADDR.
	  (when <-pos
	    (goto-char <-pos)
	    (mail-extr-skip-whitespace-backward)
	    (setq phrase-end (point))
	    (goto-char (or ;;group-:-pos
			(point-min)))
	    (mail-extr-skip-whitespace-forward)
	    (if (< (point) phrase-end)
		(setq phrase-beg (point))
	      (setq phrase-end nil)))

	  ;; handle ROUTE-ADDRS with real ROUTEs.
	  ;; If there are multiple @s, then we assume ROUTE-ADDR syntax, and
	  ;; any % or ! must be semantically meaningless.
	  ;; TODO: do this processing into canonicalization buffer
	  (when route-addr-:-pos
	    (setq !-pos nil
		  %-pos nil
		  >-pos (copy-marker >-pos)
		  route-addr-:-pos (copy-marker route-addr-:-pos))
	    (goto-char >-pos)
	    (insert-before-markers ?X)
	    (goto-char (car @-pos))
	    (while (setq @-pos (cdr @-pos))
	      (delete-char 1)
	      (setq %-pos (cons (point-marker) %-pos))
	      (insert "%")
	      (goto-char (1- >-pos))
	      (save-excursion
		(insert-buffer-substring extraction-buffer
					 (car @-pos) route-addr-:-pos)
		(delete-region (car @-pos) route-addr-:-pos))
	      (or (cdr @-pos)
		  (setq saved-@-pos (list (point)))))
	    (setq @-pos saved-@-pos)
	    (goto-char >-pos)
	    (delete-char -1)
	    (mail-extr-nuke-char-at route-addr-:-pos)
	    (mail-extr-demarkerize route-addr-:-pos)
	    (setq route-addr-:-pos nil
		  >-pos (mail-extr-demarkerize >-pos)
		  %-pos (mapcar 'mail-extr-demarkerize %-pos)))

	  ;; de-listify @-pos
	  (setq @-pos (car @-pos))

	  ;; TODO: remove comments in the middle of an address

	  (with-current-buffer canonicalization-buffer
	    (widen)
	    (erase-buffer)
	    (insert-buffer-substring extraction-buffer)

	    (if <-pos
		(narrow-to-region (progn
				    (goto-char (1+ <-pos))
				    (mail-extr-skip-whitespace-forward)
				    (point))
				  >-pos)
	      (if (and first-real-pos last-real-pos)
		  (narrow-to-region first-real-pos last-real-pos)
		;; ****** Oh no!  What if the address is completely empty!
		;; *** Is this correct?
		(narrow-to-region (point-max) (point-max))))

	    (and @-pos %-pos
		 (mail-extr-nuke-outside-range %-pos (point-min) @-pos))
	    (and %-pos !-pos
		 (mail-extr-nuke-outside-range !-pos (point-min) (car %-pos)))
	    (and @-pos !-pos (not %-pos)
		 (mail-extr-nuke-outside-range !-pos (point-min) @-pos))

	    ;; Error condition:?? (and %-pos (not @-pos))

	    ;; WARNING: THIS CODE IS DUPLICATED BELOW.
	    (when (and %-pos (not @-pos))
	      (goto-char (car %-pos))
	      (delete-char 1)
	      (setq @-pos (point))
	      (insert "@")
	      (setq %-pos (cdr %-pos)))

	    (when (and mail-extr-mangle-uucp !-pos)
	      ;; **** I don't understand this save-restriction and the
	      ;; narrow-to-region inside it.  Why did I do that?
	      (save-restriction
		(cond ((and @-pos
			    mail-extr-@-binds-tighter-than-!)
		       (goto-char @-pos)
		       (setq %-pos (cons (point) %-pos)
			     @-pos nil)
		       (delete-char 1)
		       (insert "%")
		       (setq insert-point (point-max)))
		      (mail-extr-@-binds-tighter-than-!
		       (setq insert-point (point-max)))
		      (%-pos
		       (setq insert-point (car (last %-pos))
			     saved-%-pos (mapcar 'mail-extr-markerize %-pos)
			     %-pos nil
			     @-pos (mail-extr-markerize @-pos)))
		      (@-pos
		       (setq insert-point @-pos)
		       (setq @-pos (mail-extr-markerize @-pos)))
		      (t
		       (setq insert-point (point-max))))
		(narrow-to-region (point-min) insert-point)
		(setq saved-!-pos (car !-pos))
		(while !-pos
		  (goto-char (point-max))
		  (cond ((and (not @-pos)
			      (not (cdr !-pos)))
			 (setq @-pos (point))
			 (insert-before-markers "@ "))
			(t
			 (setq %-pos (cons (point) %-pos))
			 (insert-before-markers "% ")))
		  (backward-char 1)
		  (insert-buffer-substring
		   (current-buffer)
		   (if (nth 1 !-pos)
		       (1+ (nth 1 !-pos))
		     (point-min))
		   (car !-pos))
		  (delete-char 1)
		  (or (save-excursion
			(mail-extr-safe-move-sexp -1)
			(mail-extr-skip-whitespace-backward)
			(eq ?. (preceding-char)))
		      (insert-before-markers
		       (if (save-excursion
			     (mail-extr-skip-whitespace-backward)
			     (eq ?. (preceding-char)))
			   ""
			 ".")
		       "uucp"))
		  (setq !-pos (cdr !-pos))))
	      (and saved-%-pos
		   (setq %-pos (append (mapcar 'mail-extr-demarkerize
					       saved-%-pos)
				       %-pos)))
	      (setq @-pos (mail-extr-demarkerize @-pos))
	      (narrow-to-region (1+ saved-!-pos) (point-max)))

	    ;; WARNING: THIS CODE IS DUPLICATED ABOVE.
	    (when (and %-pos (not @-pos))
	      (goto-char (car %-pos))
	      (delete-char 1)
	      (setq @-pos (point))
	      (insert "@")
	      (setq %-pos (cdr %-pos)))

	    (when (setq %-pos (nreverse %-pos))	; implies @-pos valid
	      (setq temp %-pos)
	      (catch 'truncated
		(while temp
		  (goto-char (or (nth 1 temp)
				 @-pos))
		  (mail-extr-skip-whitespace-backward)
		  (save-excursion
		    (mail-extr-safe-move-sexp -1)
		    (setq domain-pos (point))
		    (mail-extr-skip-whitespace-backward)
		    (setq \.-pos (eq ?. (preceding-char))))
		  (when (and \.-pos
			     ;; #### string consing
			     (let ((s (intern-soft
				       (buffer-substring domain-pos (point))
				       mail-extr-all-top-level-domains)))
			       (and s (get s 'domain-name))))
		    (narrow-to-region (point-min) (point))
		    (goto-char (car temp))
		    (delete-char 1)
		    (setq @-pos (point))
		    (setcdr temp nil)
		    (setq %-pos (delq @-pos %-pos))
		    (insert "@")
		    (throw 'truncated t))
		  (setq temp (cdr temp)))))
	    (setq mbox-beg (point-min)
		  mbox-end (if %-pos (car %-pos)
			     (or @-pos
				 (point-max))))

	    (when @-pos
	      ;; Make the domain-name part lowercase since it's case
	      ;; insensitive anyway.
	      (downcase-region (1+ @-pos) (point-max))))

	  ;; Done canonicalizing address.
	  ;; We are now back in extraction-buffer.

	  ;; Decide what part of the address to search to find the full name.
	  (cond (
		 ;; Example: "First M. Last" <fml@foo.bar.dom>
		 (and phrase-beg
		      (eq quote-beg phrase-beg)
		      (<= quote-end phrase-end))
		 (narrow-to-region (1+ quote-beg) (1- quote-end))
		 (mail-extr-undo-backslash-quoting (point-min) (point-max)))

		;; Example: First Last <fml@foo.bar.dom>
		(phrase-beg
		 (narrow-to-region phrase-beg phrase-end))

		;; Example: fml@foo.bar.dom (First M. Last)
		(cbeg
		 (narrow-to-region (1+ cbeg) (1- cend))
		 (mail-extr-undo-backslash-quoting (point-min) (point-max))

		 ;; Deal with spacing problems
		 (goto-char (point-min))
;;;	     (cond ((not (search-forward " " nil t))
;;;		    (goto-char (point-min))
;;;		    (cond ((search-forward "_" nil t)
;;;			   ;; Handle the *idiotic* use of underlines as spaces.
;;;			   ;; Example: fml@foo.bar.dom (First_M._Last)
;;;			   (goto-char (point-min))
;;;			   (while (search-forward "_" nil t)
;;;			     (replace-match " " t)))
;;;			  ((search-forward "." nil t)
;;;			   ;; Fix . used as space
;;;			   ;; Example: danj1@cb.att.com (daniel.jacobson)
;;;			   (goto-char (point-min))
;;;			   (while (re-search-forward mail-extr-bad-dot-pattern nil t)
;;;			     (replace-match "\\1 \\2" t))))))
		 )

		;; Otherwise we try to get the name from the mailbox portion
		;; of the address.
		;; Example: First_M_Last@foo.bar.dom
		(t
		 ;; *** Work in canon buffer instead?  No, can't.  Hmm.
		 (goto-char (point-max))
		 (narrow-to-region (point) (point))
		 (insert-buffer-substring canonicalization-buffer
					  mbox-beg mbox-end)
		 (goto-char (point-min))

		 ;; Example: First_Last.XXX@foo.bar.dom
		 (setq \.-ends-name (re-search-forward "[_0-9]" nil t))

		 (goto-char (point-min))

		 (if (not mail-extr-mangle-uucp)
		     (modify-syntax-entry ?! "w" (syntax-table)))

		 (while (progn
			  (mail-extr-skip-whitespace-forward)
			  (not (eobp)))
		   (setq char (char-after (point)))
		   (cond
		    ((eq char ?\")
		     (setq quote-beg (point))
		     (or (mail-extr-safe-move-sexp 1)
			 ;; TODO: handle this error condition!!!!!
			 (forward-char 1))
		     ;; take into account deletions
		     (setq quote-end (- (point) 2))
		     (save-excursion
		       (backward-char 1)
		       (delete-char 1)
		       (goto-char quote-beg)
		       (or (eobp)
			   (delete-char 1)))
		     (mail-extr-undo-backslash-quoting quote-beg quote-end)
		     (or (eq ?\  (char-after (point)))
			 (insert " "))
		     ;;		 (setq mailbox-name-processed-flag t)
		     (setq \.-ends-name t))
		    ((eq char ?.)
		     (if (memq (char-after (1+ (point))) '(?_ ?=))
			 (progn
			   (forward-char 1)
			   (delete-char 1)
			   (insert ?\ ))
		       (if \.-ends-name
			   (narrow-to-region (point-min) (point))
			 (delete-char 1)
			 (insert " ")))
		     ;;		 (setq mailbox-name-processed-flag t)
		     )
		    ((memq (char-syntax char) '(?. ?\\))
		     (delete-char 1)
		     (insert " ")
		     ;;		 (setq mailbox-name-processed-flag t)
		     )
		    (t
		     (setq atom-beg (point))
		     (forward-word 1)
		     (setq atom-end (point))
		     (goto-char atom-beg)
		     (save-restriction
		       (narrow-to-region atom-beg atom-end)
		       (cond

			;; Handle X.400 addresses encoded in RFC-822.
			;; *** Shit!  This has to handle the case where it is
			;; *** embedded in a quote too!
			;; *** Shit!  The input is being broken up into atoms
			;; *** by periods!
			((looking-at mail-extr-x400-encoded-address-pattern)

			 ;; Copy the contents of the individual fields that
			 ;; might hold name data to the beginning.
			 (mapc
			  (lambda (field-pattern)
			    (when
				(save-excursion
				  (re-search-forward field-pattern nil t))
			      (insert-buffer-substring (current-buffer)
						       (match-beginning 1)
						       (match-end 1))
			      (insert " ")))
			  (list mail-extr-x400-encoded-address-given-name-pattern
				mail-extr-x400-encoded-address-surname-pattern
				mail-extr-x400-encoded-address-full-name-pattern))

			 ;; Discard the rest, since it contains stuff like
			 ;; routing information, not part of a name.
			 (mail-extr-skip-whitespace-backward)
			 (delete-region (point) (point-max))

			 ;; Handle periods used for spacing.
			 (while (re-search-forward mail-extr-bad-dot-pattern nil t)
			   (replace-match "\\1 \\2" t))

			 ;;		     (setq mailbox-name-processed-flag t)
			 )

			;; Handle normal addresses.
			(t
			 (goto-char (point-min))
			 ;; Handle _ and = used for spacing.
			 (while (re-search-forward "\\([^_=]+\\)[_=]" nil t)
			   (replace-match "\\1 " t)
			   ;;		       (setq mailbox-name-processed-flag t)
			   )
			 (goto-char (point-max))))))))

		 ;; undo the dirty deed
		 (if (not mail-extr-mangle-uucp)
		     (modify-syntax-entry ?! "." (syntax-table)))
		 ;;
		 ;; If we derived the name from the mailbox part of the address,
		 ;; and we only got one word out of it, don't treat that as a
		 ;; name.  "foo@bar" --> (nil "foo@bar"), not ("foo" "foo@bar")
		 ;; (if (not mailbox-name-processed-flag)
		 ;;     (delete-region (point-min) (point-max)))
		 ))

	  (set-syntax-table mail-extr-address-text-syntax-table)

	  (mail-extr-voodoo mbox-beg mbox-end canonicalization-buffer)
	  (goto-char (point-min))

	  ;; If name is "First Last" and userid is "F?L", then assume
	  ;; the middle initial is the second letter in the userid.
	  ;; Initial code by Jamie Zawinski <jwz@lucid.com>
	  ;; *** Make it work when there's a suffix as well.
	  (goto-char (point-min))
	  (when (and mail-extr-guess-middle-initial
		     (not disable-initial-guessing-flag)
		     (eq 3 (- mbox-end mbox-beg))
		     (progn
		       (goto-char (point-min))
		       (looking-at mail-extr-two-name-pattern)))
	    (setq fi (char-after (match-beginning 0))
		  li (char-after (match-beginning 3)))
	    (with-current-buffer canonicalization-buffer
	      ;; char-equal is ignoring case here, so no need to upcase
	      ;; or downcase.
	      (let ((case-fold-search t))
		(and (char-equal fi (char-after mbox-beg))
		     (char-equal li (char-after (1- mbox-end)))
		     (setq mi (char-after (1+ mbox-beg))))))
	    (when (and mi
		       ;; TODO: use better table than syntax table
		       (eq ?w (char-syntax mi)))
	      (goto-char (match-beginning 3))
	      (insert (upcase mi) ". ")))

	  ;; Nuke name if it is the same as mailbox name.
	  (let ((buffer-length (- (point-max) (point-min)))
		(i 0)
		(names-match-flag t))
	    (when (and (> buffer-length 0)
		       (eq buffer-length (- mbox-end mbox-beg)))
	      (goto-char (point-max))
	      (insert-buffer-substring canonicalization-buffer
				       mbox-beg mbox-end)
	      (while (and names-match-flag
			  (< i buffer-length))
		(or (eq (downcase (char-after (+ i (point-min))))
			(downcase
			 (char-after (+ i buffer-length (point-min)))))
		    (setq names-match-flag nil))
		(setq i (1+ i)))
	      (delete-region (+ (point-min) buffer-length) (point-max))
	      (and names-match-flag
			   mail-extr-ignore-realname-equals-mailbox-name
			   (narrow-to-region (point) (point)))))

	  ;; Nuke name if it's just one word.
	  (goto-char (point-min))
	  (and mail-extr-ignore-single-names
	       (not (re-search-forward "[- ]" nil t))
	       (narrow-to-region (point) (point)))

	  ;; Record the result
	  (setq value-list
		(cons (list (if (not (= (point-min) (point-max)))
				(buffer-string))
			    (with-current-buffer canonicalization-buffer
			      (if (not (= (point-min) (point-max)))
				  (buffer-string))))
		      value-list))

	  ;; Unless one address is all we wanted,
	  ;; delete this one from extraction-buffer
	  ;; and get ready to extract the next address.
	  (when all
	    (if end-of-address
		(narrow-to-region 1 end-of-address)
	      (widen))
	    (delete-region (point-min) (point-max))
	    (widen))
	  )))
    (if all (nreverse value-list) (car value-list))
    ))

(defcustom mail-extr-disable-voodoo "\\cj"
  "*If it is a regexp, names matching it will never be modified.
If it is neither nil nor a string, modifying of names will never take
place.  It affects how `mail-extract-address-components' works."
  :type '(choice (regexp :size 0)
		 (const :tag "Always enabled" nil)
		 (const :tag "Always disabled" t))
  :group 'mail-extr)

(defun mail-extr-voodoo (mbox-beg mbox-end canonicalization-buffer)
  (unless (and mail-extr-disable-voodoo
	       (or (not (stringp mail-extr-disable-voodoo))
		   (progn
		     (goto-char (point-min))
		     (re-search-forward mail-extr-disable-voodoo nil t))))
    (let ((word-count 0)
	  (case-fold-search nil)
	  mixed-case-flag lower-case-flag ;;upper-case-flag
	  suffix-flag last-name-comma-flag
	  ;;cbeg cend
	  initial
	  begin-again-flag
	  drop-this-word-if-trailing-flag
	  drop-last-word-if-trailing-flag
	  word-found-flag
	  this-word-beg last-word-beg
	  name-beg name-end
	  name-done-flag
	  )
      (save-excursion
	(set-syntax-table mail-extr-address-text-syntax-table)

	;; Get rid of comments.
	(goto-char (point-min))
	(while (not (eobp))
	  ;; Initialize for this iteration of the loop.
	  (skip-chars-forward "^({[\"'`")
	  (let ((cbeg (point)))
	    (set-syntax-table mail-extr-address-text-comment-syntax-table)
	    (if (memq (following-char) '(?\' ?\`))
		(search-forward "'" nil 'move
				(if (eq ?\' (following-char)) 2 1))
	      (or (mail-extr-safe-move-sexp 1)
		  (goto-char (point-max))))
	    (set-syntax-table mail-extr-address-text-syntax-table)
	    (when (eq (char-after cbeg) ?\()
	      ;; Delete the comment itself.
	      (delete-region cbeg (point))
	      ;; Canonicalize whitespace where the comment was.
	      (skip-chars-backward " \t")
	      (if (looking-at "\\([ \t]+$\\|[ \t]+,\\)")
		  (replace-match "")
		(setq cbeg (point))
		(skip-chars-forward " \t")
		(if (bobp)
		    (delete-region (point) cbeg)
		  (just-one-space))))))

	;; This was moved above.
	;; Fix . used as space
	;; But it belongs here because it occurs not only as
	;;   rypens@reks.uia.ac.be (Piet.Rypens)
	;; but also as
	;;   "Piet.Rypens" <rypens@reks.uia.ac.be>
	;;(goto-char (point-min))
	;;(while (re-search-forward mail-extr-bad-dot-pattern nil t)
	;;  (replace-match "\\1 \\2" t))

	(unless (search-forward " " nil t)
	  (goto-char (point-min))
	  (cond ((search-forward "_" nil t)
		 ;; Handle the *idiotic* use of underlines as spaces.
		 ;; Example: fml@foo.bar.dom (First_M._Last)
		 (goto-char (point-min))
		 (while (search-forward "_" nil t)
		   (replace-match " " t)))
		((search-forward "." nil t)
		 ;; Fix . used as space
		 ;; Example: danj1@cb.att.com (daniel.jacobson)
		 (goto-char (point-min))
		 (while (re-search-forward mail-extr-bad-dot-pattern nil t)
		   (replace-match "\\1 \\2" t)))))

	;; Loop over the words (and other junk) in the name.
	(goto-char (point-min))
	(while (not name-done-flag)

	  (when word-found-flag
	    ;; Last time through this loop we skipped over a word.
	    (setq last-word-beg this-word-beg)
	    (setq drop-last-word-if-trailing-flag
		  drop-this-word-if-trailing-flag)
	    (setq word-found-flag nil))

	  (when begin-again-flag
	    ;; Last time through the loop we found something that
	    ;; indicates we should pretend we are beginning again from
	    ;; the start.
	    (setq word-count 0)
	    (setq last-word-beg nil)
	    (setq drop-last-word-if-trailing-flag nil)
	    (setq mixed-case-flag nil)
	    (setq lower-case-flag nil)
	    ;;	       (setq upper-case-flag nil)
	    (setq begin-again-flag nil))

	  ;; Initialize for this iteration of the loop.
	  (mail-extr-skip-whitespace-forward)
	  (if (eq word-count 0) (narrow-to-region (point) (point-max)))
	  (setq this-word-beg (point))
	  (setq drop-this-word-if-trailing-flag nil)

	  ;; Decide what to do based on what we are looking at.
	  (cond

	   ;; Delete title
	   ((and (eq word-count 0)
		 (looking-at mail-extr-full-name-prefixes))
	    (goto-char (match-end 0))
	    (narrow-to-region (point) (point-max)))

	   ;; Stop after name suffix
	   ((and (>= word-count 2)
		 (looking-at mail-extr-full-name-suffix-pattern))
	    (mail-extr-skip-whitespace-backward)
	    (setq suffix-flag (point))
	    (if (eq ?, (following-char))
		(forward-char 1)
	      (insert ?,))
	    ;; Enforce at least one space after comma
	    (or (eq ?\  (following-char))
		(insert ?\ ))
	    (mail-extr-skip-whitespace-forward)
	    (cond ((memq (following-char) '(?j ?J ?s ?S))
		   (capitalize-word 1)
		   (if (eq (following-char) ?.)
		       (forward-char 1)
		     (insert ?.)))
		  (t
		   (upcase-word 1)))
	    (setq word-found-flag t)
	    (setq name-done-flag t))

	   ;; Handle SCA names
	   ((looking-at "MKA \\(.+\\)")	; "Mundanely Known As"
	    (goto-char (match-beginning 1))
	    (narrow-to-region (point) (point-max))
	    (setq begin-again-flag t))

	   ;; Check for initial last name followed by comma
	   ((and (eq ?, (following-char))
		 (eq word-count 1))
	    (forward-char 1)
	    (setq last-name-comma-flag t)
	    (or (eq ?\  (following-char))
		(insert ?\ )))

	   ;; Stop before trailing comma-separated comment
	   ;; THIS CASE MUST BE AFTER THE PRECEDING CASES.
	   ;; *** This case is redundant???
	   ;;((eq ?, (following-char))
	   ;; (setq name-done-flag t))

	   ;; Delete parenthesized/quoted comment/nickname
	   ((memq (following-char) '(?\( ?\{ ?\[ ?\" ?\' ?\`))
	    (setq cbeg (point))
	    (set-syntax-table mail-extr-address-text-comment-syntax-table)
	    (cond ((memq (following-char) '(?\' ?\`))
		   (or (search-forward "'" nil t
				       (if (eq ?\' (following-char)) 2 1))
		       (delete-char 1)))
		  (t
		   (or (mail-extr-safe-move-sexp 1)
		       (goto-char (point-max)))))
	    (set-syntax-table mail-extr-address-text-syntax-table)
	    (setq cend (point))
	    (cond
	     ;; Handle case of entire name being quoted
	     ((and (eq word-count 0)
		   (looking-at " *\\'")
		   (>= (- cend cbeg) 2))
	      (narrow-to-region (1+ cbeg) (1- cend))
	      (goto-char (point-min)))
	     (t
	      ;; Handle case of quoted initial
	      (if (and (or (= 3 (- cend cbeg))
			   (and (= 4 (- cend cbeg))
				(eq ?. (char-after (+ 2 cbeg)))))
		       (not (looking-at " *\\'")))
		  (setq initial (char-after (1+ cbeg)))
		(setq initial nil))
	      (delete-region cbeg cend)
	      (if initial
		  (insert initial ". ")))))

	   ;; Handle *Stupid* VMS date stamps
	   ((looking-at mail-extr-stupid-vms-date-stamp-pattern)
	    (replace-match "" t))

	   ;; Handle Chinese characters.
	   ((looking-at mail-extr-hz-embedded-gb-encoded-chinese-pattern)
	    (goto-char (match-end 0))
	    (setq word-found-flag t))

	   ;; Skip initial garbage characters.
	   ;; THIS CASE MUST BE AFTER THE PRECEDING CASES.
	   ((and (eq word-count 0)
		 (looking-at mail-extr-leading-garbage))
	    (goto-char (match-end 0))
	    ;; *** Skip backward over these???
	    ;; (skip-chars-backward "& \"")
	    (narrow-to-region (point) (point-max)))

	   ;; Various stopping points
	   ((or

	     ;; Stop before ALL CAPS acronyms, if preceded by mixed-case
	     ;; words.  Example: XT-DEM.
	     (and (>= word-count 2)
		  mixed-case-flag
		  (looking-at mail-extr-weird-acronym-pattern)
		  (not (looking-at mail-extr-roman-numeral-pattern)))

	     ;; Stop before trailing alternative address
	     (looking-at mail-extr-alternative-address-pattern)

	     ;; Stop before trailing comment not introduced by comma
	     ;; THIS CASE MUST BE AFTER AN EARLIER CASE.
	     (looking-at mail-extr-trailing-comment-start-pattern)

	     ;; Stop before telephone numbers
	     (and (>= word-count 1)
		  (looking-at mail-extr-telephone-extension-pattern)))
	    (setq name-done-flag t))

	   ;; Delete ham radio call signs
	   ((looking-at mail-extr-ham-call-sign-pattern)
	    (delete-region (match-beginning 0) (match-end 0)))

	   ;; Fixup initials
	   ((looking-at mail-extr-initial-pattern)
	    (or (eq (following-char) (upcase (following-char)))
		(setq lower-case-flag t))
	    (forward-char 1)
	    (if (eq ?. (following-char))
		(forward-char 1)
	      (insert ?.))
	    (or (eq ?\  (following-char))
		(insert ?\ ))
	    (setq word-found-flag t))

	   ;; Handle BITNET LISTSERV list names.
	   ((and (eq word-count 0)
		 (looking-at mail-extr-listserv-list-name-pattern))
	    (narrow-to-region (match-beginning 1) (match-end 1))
	    (setq word-found-flag t)
	    (setq name-done-flag t))

	   ;; Handle & substitution, when & is last and is not first.
	   ((and (> word-count 0)
		 (eq ?\  (preceding-char))
		 (eq (following-char) ?&)
		 (eq (1+ (point)) (point-max)))
	    (delete-char 1)
	    (capitalize-region
	     (point)
	     (progn
	       (insert-buffer-substring canonicalization-buffer
					mbox-beg mbox-end)
	       (point)))
	    (setq disable-initial-guessing-flag t)
	    (setq word-found-flag t))

	   ;; Handle & between names, as in "Bob & Susie".
	   ((and (> word-count 0) (eq (following-char) ?\&))
	    (setq name-beg (point))
	    (setq name-end (1+ name-beg))
	    (setq word-found-flag t)
	    (goto-char name-end))

	   ;; Regular name words
	   ((looking-at mail-extr-name-pattern)
	    (setq name-beg (point))
	    (setq name-end (match-end 0))

	    ;; Certain words will be dropped if they are at the end.
	    (and (>= word-count 2)
		 (not lower-case-flag)
		 (or
		  ;; Trailing 4-or-more letter lowercase words preceded by
		  ;; mixed case or uppercase words will be dropped.
		  (looking-at "[[:lower:]]\\{4,\\}[ \t]*\\'")
		  ;; Drop a trailing word which is terminated with a period.
		  (eq ?. (char-after (1- name-end))))
		 (setq drop-this-word-if-trailing-flag t))

	    ;; Set the flags that indicate whether we have seen a lowercase
	    ;; word, a mixed case word, and an uppercase word.
	    (if (re-search-forward "[[:lower:]]" name-end t)
		(if (progn
		      (goto-char name-beg)
		      (re-search-forward "[[:upper:]]" name-end t))
		    (setq mixed-case-flag t)
		  (setq lower-case-flag t))
	      ;;	    (setq upper-case-flag t)
	      )

	    (goto-char name-end)
	    (setq word-found-flag t))

	   ;; Allow a number as a word, if it doesn't mean anything else.
	   ((looking-at "[0-9]+\\>")
	    (setq name-beg (point))
	    (setq name-end (match-end 0))
	    (goto-char name-end)
	    (setq word-found-flag t))

	   (t
	    (setq name-done-flag t)
	    ))

	  ;; Count any word that we skipped over.
	  (if word-found-flag
	      (setq word-count (1+ word-count))))

	;; If the last thing in the name is 2 or more periods, or one or more
	;; other sentence terminators (but not a single period) then keep them
	;; and the preceding word.  This is for the benefit of whole sentences
	;; in the name field: it's better behavior than dropping the last word
	;; of the sentence...
	(if (and (not suffix-flag)
		 (looking-at "\\(\\.+\\|[?!;:.][?!;:.]+\\|[?!;:][?!;:.]*\\)\\'"))
	    (goto-char (setq suffix-flag (point-max))))

	;; Drop everything after point and certain trailing words.
	(narrow-to-region (point-min)
			  (or (and drop-last-word-if-trailing-flag
				   last-word-beg)
			      (point)))

	;; Xerox's mailers SUCK!!!!!!
	;; We simply refuse to believe that any last name is PARC or ADOC.
	;; If it looks like that is the last name, that there is no meaningful
	;; here at all.  Actually I guess it would be best to map patterns
	;; like foo.hoser@xerox.com into foo@hoser.xerox.com, but I don't
	;; actually know that that is what's going on.
	(unless suffix-flag
	  (goto-char (point-min))
	  (let ((case-fold-search t))
	    (if (looking-at "[-A-Za-z_]+[. ]\\(PARC\\|ADOC\\)\\'")
		(erase-buffer))))

	;; If last name first put it at end (but before suffix)
	(when last-name-comma-flag
	  (goto-char (point-min))
	  (search-forward ",")
	  (setq name-end (1- (point)))
	  (goto-char (or suffix-flag (point-max)))
	  (or (eq ?\  (preceding-char))
	      (insert ?\ ))
	  (insert-buffer-substring (current-buffer) (point-min) name-end)
	  (goto-char name-end)
	  (skip-chars-forward "\t ,")
	  (narrow-to-region (point) (point-max)))

	;; Delete leading and trailing junk characters.
	;; *** This is probably completely unneeded now.
	;;(goto-char (point-max))
	;;(skip-chars-backward mail-extr-non-end-name-chars)
	;;(if (eq ?. (following-char))
	;;    (forward-char 1))
	;;(narrow-to-region (point)
	;;                  (progn
	;;                    (goto-char (point-min))
	;;                    (skip-chars-forward mail-extr-non-begin-name-chars)
	;;                    (point)))

	;; Compress whitespace
	(goto-char (point-min))
	(while (re-search-forward "[ \t\n]+" nil t)
	  (replace-match (if (eobp) "" " ") t))
	))))



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Table of top-level domain names.
;;
;; This is used during address canonicalization; be careful of format changes.
;; Keep in mind that the country abbreviations follow ISO-3166.  There is
;; a U.S. FIPS that specifies a different set of two-letter country
;; abbreviations.
;;
;; Updated by the RIPE Network Coordination Centre.
;;
;; Source: ISO 3166 Maintenance Agency
;; http://www.iso.org/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1-semic.txt
;; http://www.iana.org/domain-names.htm
;; http://www.iana.org/cctld/cctld-whois.htm
;; Latest change: 2007/11/15

(defconst mail-extr-all-top-level-domains
  (let ((ob (make-vector 739 0)))
    (mapc
     (lambda (x)
       (put (intern (downcase (car x)) ob)
	    'domain-name
	    (if (nth 2 x)
		(format (nth 2 x) (nth 1 x))
	      (nth 1 x))))
     '(
       ;; ISO 3166 codes:
       ("ac" "Ascension Island")
       ("ad" "Andorra")
       ("ae" "United Arab Emirates")
       ("af" "Afghanistan")
       ("ag" "Antigua and Barbuda")
       ("ai" "Anguilla")
       ("al" "Albania")
       ("am" "Armenia")
       ("an" "Netherlands Antilles")
       ("ao" "Angola")
       ("aq" "Antarctica")		; continent
       ("ar" "Argentina"	"Argentine Republic")
       ("as" "American Samoa")
       ("at" "Austria"		"The Republic of %s")
       ("au" "Australia")
       ("aw" "Aruba")
       ("ax" "Aland Islands")
       ("az" "Azerbaijan")
       ("ba" "Bosnia-Herzegovina")
       ("bb" "Barbados")
       ("bd" "Bangladesh")
       ("be" "Belgium"		"The Kingdom of %s")
       ("bf" "Burkina Faso")
       ("bg" "Bulgaria")
       ("bh" "Bahrain")
       ("bi" "Burundi")
       ("bj" "Benin")
       ("bl" "Saint Barthelemy")
       ("bm" "Bermuda")
       ("bn" "Brunei Darussalam")
       ("bo" "Bolivia"		"Republic of %s")
       ("br" "Brazil"		"The Federative Republic of %s")
       ("bs" "Bahamas")
       ("bt" "Bhutan")
       ("bv" "Bouvet Island")
       ("bw" "Botswana")
       ("by" "Belarus")
       ("bz" "Belize")
       ("ca" "Canada")
       ("cc" "Cocos (Keeling) Islands")
       ("cd" "Congo"            "The Democratic Republic of the %s")
       ("cf" "Central African Republic")
       ("cg" "Congo")
       ("ch" "Switzerland"	"The Swiss Confederation")
       ("ci" "Ivory Coast")		; Cote D'ivoire
       ("ck" "Cook Islands")
       ("cl" "Chile"		"The Republic of %s")
       ("cm" "Cameroon")		; In .fr domain
       ("cn" "China"		"The People's Republic of %s")
       ("co" "Colombia")
       ("cr" "Costa Rica"	"The Republic of %s")
       ("cu" "Cuba")
       ("cv" "Cape Verde")
       ("cx" "Christmas Island")
       ("cy" "Cyprus")
       ("cz" "Czech Republic")
       ("de" "Germany")
       ("dj" "Djibouti")
       ("dk" "Denmark")
       ("dm" "Dominica")
       ("do" "Dominican Republic"	"The %s")
       ("dz" "Algeria")
       ("ec" "Ecuador"		"The Republic of %s")
       ("ee" "Estonia")
       ("eg" "Egypt"		"The Arab Republic of %s")
       ("eh" "Western Sahara")
       ("er" "Eritrea")
       ("es" "Spain"		"The Kingdom of %s")
       ("et" "Ethiopia")
       ("eu" "European Union")
       ("fi" "Finland"		"The Republic of %s")
       ("fj" "Fiji")
       ("fk" "Falkland Islands (Malvinas)")
       ("fm" "Micronesia"	"Federated States of %s")
       ("fo" "Faroe Islands")
       ("fr" "France")
       ("ga" "Gabon")
       ("gb" "United Kingdom")
       ("gd" "Grenada")
       ("ge" "Georgia")
       ("gf" "French Guiana")
       ("gg" "Guernsey")
       ("gh" "Ghana")
       ("gi" "Gibraltar")
       ("gl" "Greenland")
       ("gm" "Gambia")
       ("gn" "Guinea")
       ("gp" "Guadeloupe (Fr.)")
       ("gq" "Equatorial Guinea")
       ("gr" "Greece"		"The Hellenic Republic (%s)")
       ("gs" "South Georgia and The South Sandwich Islands")
       ("gt" "Guatemala")
       ("gu" "Guam (U.S.)")
       ("gw" "Guinea-Bissau")
       ("gy" "Guyana")
       ("hk" "Hong Kong")
       ("hm" "Heard Island and Mcdonald Islands")
       ("hn" "Honduras")
       ("hr" "Croatia"		"Croatia (Hrvatska)")
       ("ht" "Haiti")
       ("hu" "Hungary"		"The Hungarian Republic")
       ("id" "Indonesia")
       ("ie" "Ireland")
       ("il" "Israel"		"The State of %s")
       ("im" "Isle of Man"	"The %s") ; NOT in ISO 3166-1 of 2001-02-26
       ("in" "India"		"The Republic of %s")
       ("io" "British Indian Ocean Territory")
       ("iq" "Iraq")
       ("ir" "Iran"		"Islamic Republic of %s")
       ("is" "Iceland"		"The Republic of %s")
       ("it" "Italy"		"The Italian Republic")
       ("je" "Jersey")
       ("jm" "Jamaica")
       ("jo" "Jordan")
       ("jp" "Japan")
       ("ke" "Kenya")
       ("kg" "Kyrgyzstan")
       ("kh" "Cambodia")
       ("ki" "Kiribati")
       ("km" "Comoros")
       ("kn" "Saint Kitts and Nevis")
       ("kp" "Korea (North)"	"Democratic People's Republic of Korea")
       ("kr" "Korea (South)"	"Republic of Korea")
       ("kw" "Kuwait")
       ("ky" "Cayman Islands")
       ("kz" "Kazakhstan")
       ("la" "Lao People's Democratic Republic")
       ("lb" "Lebanon")
       ("lc" "Saint Lucia")
       ("li" "Liechtenstein")
       ("lk" "Sri Lanka"	"The Democratic Socialist Republic of %s")
       ("lr" "Liberia")
       ("ls" "Lesotho")
       ("lt" "Lithuania")
       ("lu" "Luxembourg")
       ("lv" "Latvia")
       ("ly" "Libyan Arab Jamahiriya")
       ("ma" "Morocco")
       ("mc" "Monaco")
       ("md" "Moldova"		"The Republic of %s")
       ("me" "Montenegro")
       ("mf" "Saint Martin (French part)")
       ("mg" "Madagascar")
       ("mh" "Marshall Islands")
       ("mk" "Macedonia"	"The Former Yugoslav Republic of %s")
       ("ml" "Mali")
       ("mm" "Myanmar")
       ("mn" "Mongolia")
       ("mo" "Macao")
       ("mp" "Northern Mariana Islands")
       ("mq" "Martinique")
       ("mr" "Mauritania")
       ("ms" "Montserrat")
       ("mt" "Malta")
       ("mu" "Mauritius")
       ("mv" "Maldives")
       ("mw" "Malawi")
       ("mx" "Mexico"		"The United Mexican States")
       ("my" "Malaysia")
       ("mz" "Mozambique")
       ("na" "Namibia")
       ("nc" "New Caledonia (Fr.)")
       ("ne" "Niger")			; In .fr domain
       ("nf" "Norfolk Island")
       ("ng" "Nigeria")
       ("ni" "Nicaragua"	"The Republic of %s")
       ("nl" "Netherlands"	"The Kingdom of the %s")
       ("no" "Norway"		"The Kingdom of %s")
       ("np" "Nepal")			; Via .in domain
       ("nr" "Nauru")
       ("nu" "Niue")
       ("nz" "New Zealand")
       ("om" "Oman")
       ("pa" "Panama")
       ("pe" "Peru")
       ("pf" "French Polynesia")
       ("pg" "Papua New Guinea")
       ("ph" "Philippines"	"The Republic of the %s")
       ("pk" "Pakistan")
       ("pl" "Poland")
       ("pm" "Saint Pierre and Miquelon")
       ("pn" "Pitcairn")
       ("pr" "Puerto Rico (U.S.)")
       ("ps" "Palestinian Territory, Occupied")
       ("pt" "Portugal"		"The Portuguese Republic")
       ("pw" "Palau")
       ("py" "Paraguay")
       ("qa" "Qatar")
       ("re" "Reunion (Fr.)")		; In .fr domain
       ("ro" "Romania")
       ("rs" "Serbia")
       ("ru" "Russia"		"Russian Federation")
       ("rw" "Rwanda")
       ("sa" "Saudi Arabia")
       ("sb" "Solomon Islands")
       ("sc" "Seychelles")
       ("sd" "Sudan")
       ("se" "Sweden"		"The Kingdom of %s")
       ("sg" "Singapore"	"The Republic of %s")
       ("sh" "Saint Helena")
       ("si" "Slovenia")
       ("sj" "Svalbard and Jan Mayen") ; In .no domain
       ("sk" "Slovakia"		"The Slovak Republic")
       ("sl" "Sierra Leone")
       ("sm" "San Marino")
       ("sn" "Senegal")
       ("so" "Somalia")
       ("sr" "Suriname")
       ("st" "Sao Tome and Principe")
       ("su" "U.S.S.R." "The Union of Soviet Socialist Republics")
       ("sv" "El Salvador")
       ("sy" "Syrian Arab Republic")
       ("sz" "Swaziland")
       ("tc" "Turks and Caicos Islands")
       ("td" "Chad")
       ("tf" "French Southern Territories")
       ("tg" "Togo")
       ("th" "Thailand"		"The Kingdom of %s")
       ("tj" "Tajikistan")
       ("tk" "Tokelau")
       ("tl" "East Timor")
       ("tm" "Turkmenistan")
       ("tn" "Tunisia")
       ("to" "Tonga")
       ("tp" "East Timor")
       ("tr" "Turkey"		"The Republic of %s")
       ("tt" "Trinidad and Tobago")
       ("tv" "Tuvalu")
       ("tw" "Taiwan"		"%s, Province of China")
       ("tz" "Tanzania"		"United Republic of %s")
       ("ua" "Ukraine")
       ("ug" "Uganda")
       ("uk" "United Kingdom"	"The %s of Great Britain and Northern Ireland")
       ("um" "United States Minor Outlying Islands")
       ("us" "United States"	"The %s of America")
       ("uy" "Uruguay"		"The Eastern Republic of %s")
       ("uz" "Uzbekistan")
       ("va" "Holy See (Vatican City State)")
       ("vc" "Saint Vincent and the Grenadines")
       ("ve" "Venezuela"	"The Republic of %s")
       ("vg" "Virgin Islands, British")
       ("vi" "Virgin Islands, U.S.")
       ("vn" "Vietnam")
       ("vu" "Vanuatu")
       ("wf" "Wallis and Futuna")
       ("ws" "Samoa")
       ("ye" "Yemen")
       ("yt" "Mayotte")
       ("yu" "Yugoslavia"	"Yugoslavia, AKA Serbia-Montenegro")
       ("za" "South Africa"	"The Republic of %s")
       ("zm" "Zambia")
       ("zw" "Zimbabwe"		"Republic of %s")
       ;; Generic Domains:
       ("aero" t                "Air Transport Industry")
       ("asia" t                "Pan-Asia and Asia Pacific community")
       ("biz" t                 "Businesses")
       ("cat" t                 "Catalan language and culture")
       ("com" t			"Commercial")
       ("coop" t                "Cooperative Associations")
       ("info" t                "Info")
       ("jobs" t                "Employment")
       ("mobi" t                "Mobile products")
       ("museum" t              "Museums")
       ("name" t                "Individuals")
       ("net" t			"Network")
       ("org" t			"Non-profit Organization")
       ("pro" t                 "Credentialed professionals")
       ("tel" t                 "Contact data")
       ("travel" t              "Travel industry")
       ;;("bitnet" t		"Because It's Time NET")
       ("gov" t			"United States Government")
       ("edu" t			"Educational")
       ("mil" t			"United States Military")
       ("int" t			"International Treaties")
       ;;("nato" t		"North Atlantic Treaty Organization")
       ("uucp" t		"Unix to Unix CoPy")
       ;; Infrastructure Domains:
       ("arpa" t		"Advanced Research Projects Agency (U.S. DoD)")
       ))
    ob))

;;;###autoload
(defun what-domain (domain)
  "Convert mail domain DOMAIN to the country it corresponds to."
  (interactive
   (let ((completion-ignore-case t))
     (list (completing-read "Domain: "
			    mail-extr-all-top-level-domains nil t))))
  (or (setq domain (intern-soft (downcase domain)
				mail-extr-all-top-level-domains))
      (error "No such domain"))
  (message "%s: %s" (upcase (symbol-name domain)) (get domain 'domain-name)))


;(let ((all nil))
;  (mapatoms #'(lambda (x)
;		(if (and (boundp x)
;			 (string-match "^mail-extr-" (symbol-name x)))
;		    (setq all (cons x all)))))
;  (setq all (sort all #'string-lessp))
;  (cons 'setq
;	(apply 'nconc (mapcar #'(lambda (x)
;				  (list x (symbol-value x)))
;			      all))))


(provide 'mail-extr)

;; arch-tag: 7785fade-1073-4ed6-b4f6-28db34a7982d
;;; mail-extr.el ends here