mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-01-06 11:50:51 -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`.
145 lines
4.6 KiB
EmacsLisp
145 lines
4.6 KiB
EmacsLisp
;;; url-mailto.el --- Mail Uniform Resource Locator retrieval code -*- lexical-binding: t; -*-
|
|
|
|
;; Copyright (C) 1996-1999, 2004-2021 Free Software Foundation, Inc.
|
|
|
|
;; Keywords: comm, data, processes
|
|
|
|
;; 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:
|
|
|
|
;;; Code:
|
|
|
|
(require 'url-vars)
|
|
(require 'url-parse)
|
|
(require 'url-util)
|
|
|
|
;;;###autoload
|
|
(defun url-mail (&rest args)
|
|
(interactive "P")
|
|
(if (fboundp 'message-mail)
|
|
(apply 'message-mail args)
|
|
(or (apply 'mail args)
|
|
(error "Mail aborted"))))
|
|
|
|
(defun url-mail-goto-field (field)
|
|
(if (not field)
|
|
(goto-char (point-max))
|
|
(let ((dest nil)
|
|
(lim nil)
|
|
(case-fold-search t))
|
|
(save-excursion
|
|
(goto-char (point-min))
|
|
(if (re-search-forward (regexp-quote mail-header-separator) nil t)
|
|
(setq lim (match-beginning 0)))
|
|
(goto-char (point-min))
|
|
(if (re-search-forward (concat "^" (regexp-quote field) ":") lim t)
|
|
(setq dest (match-beginning 0))))
|
|
(if dest
|
|
(progn
|
|
(goto-char dest)
|
|
(end-of-line))
|
|
(goto-char lim)
|
|
(insert (capitalize field) ": ")
|
|
(save-excursion
|
|
(insert "\n"))))))
|
|
|
|
(declare-function mail-send-and-exit "sendmail")
|
|
|
|
;;;###autoload
|
|
(defun url-mailto (url)
|
|
"Handle the mailto: URL syntax."
|
|
(if (url-user url)
|
|
;; malformed mailto URL (mailto://wmperry@gnu.org) instead of
|
|
;; mailto:wmperry@gnu.org
|
|
(setf (url-filename url) (concat (url-user url) "@" (url-filename url))))
|
|
(setq url (url-filename url))
|
|
(let (to args source-url subject headers-start) ;; func
|
|
(if (string-match (regexp-quote "?") url)
|
|
(setq headers-start (match-end 0)
|
|
to (url-unhex-string (substring url 0 (match-beginning 0)))
|
|
args (url-parse-query-string
|
|
(substring url headers-start nil) t t))
|
|
(setq to (url-unhex-string url)))
|
|
(setq source-url (url-view-url t))
|
|
(if (and url-request-data (not (assoc "subject" args)))
|
|
(push (list "subject"
|
|
(concat "Automatic submission from "
|
|
url-package-name "/"
|
|
url-package-version))
|
|
args))
|
|
(if (and source-url (not (assoc "x-url-from" args)))
|
|
(setq args (cons (list "x-url-from" source-url) args)))
|
|
|
|
(let ((tolist (assoc "to" args)))
|
|
(if tolist
|
|
(if (not (string= to ""))
|
|
(setcdr tolist
|
|
(list (concat to ", " (cadr tolist)))))
|
|
(setq args (cons (list "to" to) args))))
|
|
|
|
(setq subject (cdr-safe (assoc "subject" args)))
|
|
(if (eq url-mail-command 'compose-mail)
|
|
(compose-mail nil nil nil 'new)
|
|
(if (eq url-mail-command 'mail)
|
|
(mail 'new)
|
|
(funcall url-mail-command)))
|
|
(while args
|
|
(if (string= (caar args) "body")
|
|
(progn
|
|
(goto-char (point-min))
|
|
(or (search-forward (concat "\n" mail-header-separator "\n") nil t)
|
|
(goto-char (point-max)))
|
|
(insert (mapconcat
|
|
(lambda (string)
|
|
(string-replace "\r\n" "\n" string))
|
|
(cdar args) "\n")))
|
|
(url-mail-goto-field (caar args))
|
|
;; (setq func (intern-soft (concat "mail-" (caar args))))
|
|
(insert (mapconcat 'identity (cdar args) ", ")))
|
|
(setq args (cdr args)))
|
|
;; (url-mail-goto-field "User-Agent")
|
|
;; (insert url-package-name "/" url-package-version " URL/" url-version)
|
|
(if (not url-request-data)
|
|
(progn
|
|
(set-buffer-modified-p nil)
|
|
(if subject
|
|
(url-mail-goto-field nil)
|
|
(url-mail-goto-field "subject")))
|
|
(if url-request-extra-headers
|
|
(mapconcat
|
|
(lambda (x)
|
|
(url-mail-goto-field (car x))
|
|
(insert (cdr x)))
|
|
url-request-extra-headers ""))
|
|
(goto-char (point-max))
|
|
(insert url-request-data)
|
|
;; It seems Microsoft-ish to send without warning.
|
|
;; Fixme: presumably this should depend on a privacy setting.
|
|
(if (y-or-n-p "Send this auto-generated mail? ")
|
|
(let ((buffer (current-buffer)))
|
|
(cond ((eq url-mail-command 'compose-mail)
|
|
(funcall (get mail-user-agent 'sendfunc) nil))
|
|
;; otherwise, we can't be sure
|
|
((fboundp 'message-send-and-exit)
|
|
(message-send-and-exit))
|
|
(t (mail-send-and-exit nil)))
|
|
(kill-buffer buffer))))
|
|
nil))
|
|
|
|
(provide 'url-mailto)
|
|
|
|
;;; url-mailto.el ends here
|