mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-17 11:20:39 -08:00
`string-replace` is easier to understand, less error-prone, much faster, and results in shorter Lisp and byte code. Use it where applicable and obviously safe (erring on the conservative side). * admin/authors.el (authors-scan-change-log): * lisp/autoinsert.el (auto-insert-alist): * lisp/calc/calc-prog.el (calc-edit-macro-combine-alg-ent) (calc-edit-macro-combine-ext-command) (calc-edit-macro-combine-var-name): * lisp/calc/calc-units.el (math-make-unit-string): * lisp/calendar/cal-html.el (cal-html-comment): * lisp/calendar/cal-tex.el (cal-tex-comment): * lisp/calendar/icalendar.el (icalendar--convert-string-for-export) (icalendar--convert-string-for-import): * lisp/calendar/iso8601.el (iso8601--concat-regexps) (iso8601--full-time-match, iso8601--combined-match): * lisp/calendar/time-date.el (format-seconds): * lisp/calendar/todo-mode.el (todo-filter-items-filename): * lisp/cedet/cedet-files.el (cedet-directory-name-to-file-name) (cedet-file-name-to-directory-name): * lisp/comint.el (comint-watch-for-password-prompt): * lisp/dired-aux.el (dired-do-chmod): * lisp/dired-x.el (dired-man): * lisp/dired.el (dired-insert-directory, dired-goto-file-1): * lisp/emacs-lisp/comp.el (comp-c-func-name): * lisp/emacs-lisp/re-builder.el (reb-copy): * lisp/erc/erc-dcc.el (erc-dcc-unquote-filename): * lisp/erc/erc.el (erc-quit-reason-zippy, erc-part-reason-zippy) (erc-update-mode-line-buffer, erc-message-english-PART): * lisp/files.el (make-backup-file-name-1, files--transform-file-name) (read-file-modes): * lisp/fringe.el (fringe-mode): * lisp/gnus/gnus-art.el (gnus-button-handle-info-url): * lisp/gnus/gnus-group.el (gnus-group-completing-read): * lisp/gnus/gnus-icalendar.el (gnus-icalendar-event-from-ical): * lisp/gnus/gnus-mlspl.el (gnus-group-split-fancy): * lisp/gnus/gnus-search.el (gnus-search-query-parse-date) (gnus-search-transform-expression, gnus-search-run-search): * lisp/gnus/gnus-start.el (gnus-dribble-enter): * lisp/gnus/gnus-sum.el (gnus-summary-refer-article): * lisp/gnus/gnus-util.el (gnus-mode-string-quote): * lisp/gnus/message.el (message-put-addresses-in-ecomplete) (message-parse-mailto-url, message-mailto-1): * lisp/gnus/mml-sec.el (mml-secure-epg-sign): * lisp/gnus/mml-smime.el (mml-smime-epg-verify): * lisp/gnus/mml2015.el (mml2015-epg-verify): * lisp/gnus/nnmaildir.el (nnmaildir--system-name) (nnmaildir-request-list, nnmaildir-retrieve-groups) (nnmaildir-request-group, nnmaildir-retrieve-headers): * lisp/gnus/nnrss.el (nnrss-node-text): * lisp/gnus/spam-report.el (spam-report-gmane-internal) (spam-report-user-mail-address): * lisp/ibuffer.el (name): * lisp/image-dired.el (image-dired-pngnq-thumb) (image-dired-pngcrush-thumb, image-dired-optipng-thumb) (image-dired-create-thumb-1): * lisp/info.el (Info-set-mode-line): * lisp/international/mule-cmds.el (describe-language-environment): * lisp/mail/rfc2231.el (rfc2231-parse-string): * lisp/mail/rfc2368.el (rfc2368-parse-mailto-url): * lisp/mail/rmail.el (rmail-insert-inbox-text) (rmail-simplified-subject-regexp): * lisp/mail/rmailout.el (rmail-output-body-to-file): * lisp/mail/undigest.el (rmail-digest-rfc1153): * lisp/man.el (Man-default-man-entry): * lisp/mouse.el (minor-mode-menu-from-indicator): * lisp/mpc.el (mpc--debug): * lisp/net/browse-url.el (browse-url-mail): * lisp/net/eww.el (eww-update-header-line-format): * lisp/net/newst-backend.el (newsticker-save-item): * lisp/net/rcirc.el (rcirc-sentinel): * lisp/net/soap-client.el (soap-decode-date-time): * lisp/nxml/rng-cmpct.el (rng-c-literal-2-re): * lisp/nxml/xmltok.el (let*): * lisp/obsolete/nnir.el (nnir-run-swish-e, nnir-run-hyrex) (nnir-run-find-grep): * lisp/play/dunnet.el (dun-doassign): * lisp/play/handwrite.el (handwrite): * lisp/proced.el (proced-format-args): * lisp/profiler.el (profiler-report-header-line-format): * lisp/progmodes/gdb-mi.el (gdb-mi-quote): * lisp/progmodes/make-mode.el (makefile-bsdmake-rule-action-regex) (makefile-make-font-lock-keywords): * lisp/progmodes/prolog.el (prolog-guess-fill-prefix): * lisp/progmodes/ruby-mode.el (ruby-toggle-string-quotes): * lisp/progmodes/sql.el (sql-remove-tabs-filter, sql-str-literal): * lisp/progmodes/which-func.el (which-func-current): * lisp/replace.el (query-replace-read-from) (occur-engine, replace-quote): * lisp/select.el (xselect--encode-string): * lisp/ses.el (ses-export-tab): * lisp/subr.el (shell-quote-argument): * lisp/term/pc-win.el (msdos-show-help): * lisp/term/w32-win.el (w32--set-selection): * lisp/term/xterm.el (gui-backend-set-selection): * lisp/textmodes/picture.el (picture-tab-search): * lisp/thumbs.el (thumbs-call-setroot-command): * lisp/tooltip.el (tooltip-show-help-non-mode): * lisp/transient.el (transient-format-key): * lisp/url/url-mailto.el (url-mailto): * lisp/vc/log-edit.el (log-edit-changelog-ours-p): * lisp/vc/vc-bzr.el (vc-bzr-status): * lisp/vc/vc-hg.el (vc-hg--glob-to-pcre): * lisp/vc/vc-svn.el (vc-svn-after-dir-status): * lisp/xdg.el (xdg-desktop-strings): * test/lisp/electric-tests.el (defun): * test/lisp/term-tests.el (term-simple-lines): * test/lisp/time-stamp-tests.el (formatz-mod-del-colons): * test/lisp/wdired-tests.el (wdired-test-bug32173-01) (wdired-test-unfinished-edit-01): * test/src/json-tests.el (json-parse-with-custom-null-and-false-objects): Use `string-replace` instead of `replace-regexp-in-string`.
135 lines
4.3 KiB
EmacsLisp
135 lines
4.3 KiB
EmacsLisp
;;; rfc2368.el --- support for rfc2368 -*- lexical-binding:t -*-
|
|
|
|
;; Copyright (C) 1998, 2000-2021 Free Software Foundation, Inc.
|
|
|
|
;; Author: Sen Nagata <sen@eccosys.com>
|
|
;; 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 <https://www.gnu.org/licenses/>.
|
|
|
|
;;; Commentary:
|
|
;;
|
|
;; notes:
|
|
;;
|
|
;; -repeat after me: "the colon is not part of the header name..."
|
|
;; -if w3 becomes part of emacs, then it may make sense to have this
|
|
;; file depend on w3 -- the maintainer of w3 says merging w/ Emacs
|
|
;; is planned!
|
|
;;
|
|
;; historical note:
|
|
;;
|
|
;; this is intended as a replacement for mailto.el
|
|
;;
|
|
;; acknowledgments:
|
|
;;
|
|
;; the functions that deal w/ unhexifying in this file were basically
|
|
;; taken from w3 -- i hope to replace them w/ something else soon OR
|
|
;; perhaps if w3 becomes a part of emacs soon, use the functions from w3.
|
|
|
|
;;; History:
|
|
;;
|
|
;; 0.3:
|
|
;;
|
|
;; added the constant rfc2368-version
|
|
;; implemented first potential fix for a bug in rfc2368-mailto-regexp
|
|
;; implemented first potential fix for a bug in rfc2368-parse-mailto
|
|
;; (both bugs reported by Kenichi OKADA)
|
|
;;
|
|
;; 0.2:
|
|
;;
|
|
;; started to use checkdoc
|
|
;;
|
|
;; 0.1:
|
|
;;
|
|
;; initial implementation
|
|
|
|
;;; Code:
|
|
|
|
;; only an approximation?
|
|
;; see rfc 1738
|
|
(defconst rfc2368-mailto-regexp
|
|
"^\\(mailto:\\)\\([^?]+\\)?\\(\\?\\(.*\\)\\)*"
|
|
"Regular expression to match and aid in parsing a mailto url.")
|
|
|
|
;; describes 'mailto:'
|
|
(defconst rfc2368-mailto-scheme-index 1
|
|
"Describes the `mailto:' portion of the url.")
|
|
;; i'm going to call this part the 'prequery'
|
|
(defconst rfc2368-mailto-prequery-index 2
|
|
"Describes the portion of the url between `mailto:' and `?'.")
|
|
;; i'm going to call this part the 'query'
|
|
(defconst rfc2368-mailto-query-index 4
|
|
"Describes the portion of the url after `?'.")
|
|
|
|
(defun rfc2368-unhexify-string (string)
|
|
"Unhexify STRING -- e.g. `hello%20there' -> `hello there'."
|
|
(replace-regexp-in-string "%[[:xdigit:]]\\{2\\}"
|
|
(lambda (match)
|
|
(string (string-to-number (substring match 1)
|
|
16)))
|
|
string t t))
|
|
|
|
(defun rfc2368-parse-mailto-url (mailto-url)
|
|
"Parse MAILTO-URL, and return an alist of header-name, header-value pairs.
|
|
MAILTO-URL should be a RFC 2368 (mailto) compliant url. A cons cell w/ a
|
|
key of `Body' is a special case and is considered a header for this purpose.
|
|
The returned alist is intended for use w/ the `compose-mail' interface.
|
|
Note: make sure MAILTO-URL has been \"unhtmlized\" (e.g., & -> &), before
|
|
calling this function."
|
|
(let ((case-fold-search t)
|
|
prequery query headers-alist)
|
|
(setq mailto-url (string-replace "\n" " " mailto-url))
|
|
(if (string-match rfc2368-mailto-regexp mailto-url)
|
|
(progn
|
|
(setq prequery
|
|
(match-string rfc2368-mailto-prequery-index mailto-url))
|
|
(setq query
|
|
(match-string rfc2368-mailto-query-index mailto-url))
|
|
|
|
;; build alist of header name-value pairs
|
|
(if (not (null query))
|
|
(setq headers-alist
|
|
(mapcar
|
|
(lambda (x)
|
|
(let* ((temp-list (split-string x "="))
|
|
(header-name (car temp-list))
|
|
(header-value (cadr temp-list)))
|
|
;; return ("Header-Name" . "header-value")
|
|
(cons
|
|
(capitalize (rfc2368-unhexify-string header-name))
|
|
(rfc2368-unhexify-string header-value))))
|
|
(split-string query "&"))))
|
|
|
|
;; deal w/ multiple 'To' recipients
|
|
(if prequery
|
|
(progn
|
|
(setq prequery (rfc2368-unhexify-string prequery))
|
|
(if (assoc "To" headers-alist)
|
|
(let* ((our-cons-cell
|
|
(assoc "To" headers-alist))
|
|
(our-cdr
|
|
(cdr our-cons-cell)))
|
|
(setcdr our-cons-cell (concat prequery ", " our-cdr)))
|
|
(setq headers-alist
|
|
(cons (cons "To" prequery) headers-alist)))))
|
|
|
|
headers-alist)
|
|
|
|
(error "Failed to match a mailto: url"))))
|
|
|
|
(provide 'rfc2368)
|
|
|
|
;;; rfc2368.el ends here
|