1 ;;; url-mail.el --- Mail Uniform Resource Locator retrieval code
3 ;; Copyright (C) 1996-1999, 2004-2012 Free Software Foundation, Inc.
5 ;; Keywords: comm, data, processes
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
31 (defun url-mail (&rest args
)
33 (if (fboundp 'message-mail
)
34 (apply 'message-mail args
)
35 (or (apply 'mail args
)
36 (error "Mail aborted"))))
38 (defun url-mail-goto-field (field)
40 (goto-char (point-max))
45 (goto-char (point-min))
46 (if (re-search-forward (regexp-quote mail-header-separator
) nil t
)
47 (setq lim
(match-beginning 0)))
48 (goto-char (point-min))
49 (if (re-search-forward (concat "^" (regexp-quote field
) ":") lim t
)
50 (setq dest
(match-beginning 0))))
56 (insert (capitalize field
) ": ")
60 (declare-function mail-send-and-exit
"sendmail")
63 (defun url-mailto (url)
64 "Handle the mailto: URL syntax."
66 ;; malformed mailto URL (mailto://wmperry@gnu.org) instead of
67 ;; mailto:wmperry@gnu.org
68 (setf (url-filename url
) (concat (url-user url
) "@" (url-filename url
))))
69 (setq url
(url-filename url
))
70 (let (to args source-url subject func headers-start
)
71 (if (string-match (regexp-quote "?") url
)
72 (setq headers-start
(match-end 0)
73 to
(url-unhex-string (substring url
0 (match-beginning 0)))
74 args
(url-parse-query-string
75 (substring url headers-start nil
) t t
))
76 (setq to
(url-unhex-string url
)))
77 (setq source-url
(url-view-url t
))
78 (if (and url-request-data
(not (assoc "subject" args
)))
79 (setq args
(cons (list "subject"
80 (concat "Automatic submission from "
82 url-package-version
)) args
)))
83 (if (and source-url
(not (assoc "x-url-from" args
)))
84 (setq args
(cons (list "x-url-from" source-url
) args
)))
86 (let ((tolist (assoc "to" args
)))
88 (if (not (string= to
""))
90 (list (concat to
", " (cadr tolist
)))))
91 (setq args
(cons (list "to" to
) args
))))
93 (setq subject
(cdr-safe (assoc "subject" args
)))
94 (if (eq url-mail-command
'compose-mail
)
95 (compose-mail nil nil nil
'new
)
96 (if (eq url-mail-command
'mail
)
98 (funcall url-mail-command
)))
100 (if (string= (caar args
) "body")
102 (goto-char (point-min))
103 (or (search-forward (concat "\n" mail-header-separator
"\n") nil t
)
104 (goto-char (point-max)))
107 (replace-regexp-in-string "\r\n" "\n" string
))
109 (url-mail-goto-field (caar args
))
110 (setq func
(intern-soft (concat "mail-" (caar args
))))
111 (insert (mapconcat 'identity
(cdar args
) ", ")))
112 (setq args
(cdr args
)))
113 ;; (url-mail-goto-field "User-Agent")
114 ;; (insert url-package-name "/" url-package-version " URL/" url-version)
115 (if (not url-request-data
)
117 (set-buffer-modified-p nil
)
119 (url-mail-goto-field nil
)
120 (url-mail-goto-field "subject")))
121 (if url-request-extra-headers
124 (url-mail-goto-field (car x
))
126 url-request-extra-headers
""))
127 (goto-char (point-max))
128 (insert url-request-data
)
129 ;; It seems Microsoft-ish to send without warning.
130 ;; Fixme: presumably this should depend on a privacy setting.
131 (if (y-or-n-p "Send this auto-generated mail? ")
132 (let ((buffer (current-buffer)))
133 (cond ((eq url-mail-command
'compose-mail
)
134 (funcall (get mail-user-agent
'sendfunc
) nil
))
135 ;; otherwise, we can't be sure
136 ((fboundp 'message-send-and-exit
)
137 (message-send-and-exit))
138 (t (mail-send-and-exit nil
)))
139 (kill-buffer buffer
))))
142 (provide 'url-mailto
)
144 ;;; url-mailto.el ends here