Mercurial > emacs
annotate lisp/url/url-mailto.el @ 91962:37c6e66c7e57
*** empty log message ***
author | Michael Albinus <michael.albinus@gmx.de> |
---|---|
date | Tue, 19 Feb 2008 19:23:19 +0000 |
parents | 107ccd98fa12 |
children | 8259d0d8e107 |
rev | line source |
---|---|
54695 | 1 ;;; url-mail.el --- Mail Uniform Resource Locator retrieval code |
54800
bab00fb32e72
(url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
2 |
64748
875dcc490074
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64084
diff
changeset
|
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2004, |
79720 | 4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
54800
bab00fb32e72
(url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
5 |
54695 | 6 ;; Keywords: comm, data, processes |
7 | |
54800
bab00fb32e72
(url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
8 ;; This file is part of GNU Emacs. |
bab00fb32e72
(url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
9 ;; |
bab00fb32e72
(url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
10 ;; GNU Emacs is free software; you can redistribute it and/or modify |
bab00fb32e72
(url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
11 ;; it under the terms of the GNU General Public License as published by |
78222
8932997d0b62
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
77834
diff
changeset
|
12 ;; the Free Software Foundation; either version 3, or (at your option) |
54800
bab00fb32e72
(url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
13 ;; any later version. |
bab00fb32e72
(url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
14 ;; |
bab00fb32e72
(url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
15 ;; GNU Emacs is distributed in the hope that it will be useful, |
bab00fb32e72
(url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
bab00fb32e72
(url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bab00fb32e72
(url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
18 ;; GNU General Public License for more details. |
bab00fb32e72
(url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
19 ;; |
bab00fb32e72
(url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
20 ;; You should have received a copy of the GNU General Public License |
bab00fb32e72
(url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
64084 | 22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
23 ;; Boston, MA 02110-1301, USA. | |
54800
bab00fb32e72
(url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
24 |
bab00fb32e72
(url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
25 ;;; Commentary: |
bab00fb32e72
(url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
26 |
bab00fb32e72
(url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
27 ;;; Code: |
54695 | 28 |
29 (require 'url-vars) | |
30 (require 'url-parse) | |
31 (require 'url-util) | |
32 | |
33 ;;;###autoload | |
34 (defun url-mail (&rest args) | |
35 (interactive "P") | |
36 (if (fboundp 'message-mail) | |
37 (apply 'message-mail args) | |
38 (or (apply 'mail args) | |
39 (error "Mail aborted")))) | |
40 | |
41 (defun url-mail-goto-field (field) | |
42 (if (not field) | |
43 (goto-char (point-max)) | |
44 (let ((dest nil) | |
45 (lim nil) | |
46 (case-fold-search t)) | |
47 (save-excursion | |
48 (goto-char (point-min)) | |
49 (if (re-search-forward (regexp-quote mail-header-separator) nil t) | |
50 (setq lim (match-beginning 0))) | |
51 (goto-char (point-min)) | |
52 (if (re-search-forward (concat "^" (regexp-quote field) ":") lim t) | |
53 (setq dest (match-beginning 0)))) | |
54 (if dest | |
55 (progn | |
56 (goto-char dest) | |
57 (end-of-line)) | |
58 (goto-char lim) | |
59 (insert (capitalize field) ": ") | |
60 (save-excursion | |
61 (insert "\n")))))) | |
62 | |
87105
492c630f4a8b
Remove directory part from filenames in function declarations.
Glenn Morris <rgm@gnu.org>
parents:
86243
diff
changeset
|
63 (declare-function mail-send-and-exit "sendmail") |
86243
4d615a83cee2
* progmodes/idlw-help.el: Require browse-url unconditionally, it
Dan Nicolaescu <dann@ics.uci.edu>
parents:
83823
diff
changeset
|
64 |
54695 | 65 ;;;###autoload |
66 (defun url-mailto (url) | |
67 "Handle the mailto: URL syntax." | |
68 (if (url-user url) | |
58139
9eeb05e27d32
url-mailto.el (url-mailto): Fix a typo in the comment.
Masatake YAMATO <jet@gyve.org>
parents:
57511
diff
changeset
|
69 ;; malformed mailto URL (mailto://wmperry@gnu.org) instead of |
54695 | 70 ;; mailto:wmperry@gnu.org |
83823
dd2bcc6758a0
* url-parse.el (url): Use defstruct rather than macros. Update all callers.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78222
diff
changeset
|
71 (setf (url-filename url) (concat (url-user url) "@" (url-filename url)))) |
54695 | 72 (setq url (url-filename url)) |
73 (let (to args source-url subject func headers-start) | |
74 (if (string-match (regexp-quote "?") url) | |
75 (setq headers-start (match-end 0) | |
76 to (url-unhex-string (substring url 0 (match-beginning 0))) | |
77 args (url-parse-query-string | |
65312
915d671fef52
*** empty log message ***
Chong Yidong <cyd@stupidchicken.com>
parents:
64748
diff
changeset
|
78 (substring url headers-start nil) t t)) |
54695 | 79 (setq to (url-unhex-string url))) |
80 (setq source-url (url-view-url t)) | |
81 (if (and url-request-data (not (assoc "subject" args))) | |
82 (setq args (cons (list "subject" | |
83 (concat "Automatic submission from " | |
84 url-package-name "/" | |
85 url-package-version)) args))) | |
86 (if (and source-url (not (assoc "x-url-from" args))) | |
87 (setq args (cons (list "x-url-from" source-url) args))) | |
88 | |
65312
915d671fef52
*** empty log message ***
Chong Yidong <cyd@stupidchicken.com>
parents:
64748
diff
changeset
|
89 (let ((tolist (assoc "to" args))) |
915d671fef52
*** empty log message ***
Chong Yidong <cyd@stupidchicken.com>
parents:
64748
diff
changeset
|
90 (if tolist |
915d671fef52
*** empty log message ***
Chong Yidong <cyd@stupidchicken.com>
parents:
64748
diff
changeset
|
91 (if (not (string= to "")) |
915d671fef52
*** empty log message ***
Chong Yidong <cyd@stupidchicken.com>
parents:
64748
diff
changeset
|
92 (setcdr tolist |
65313
193da07ce98d
*** empty log message ***
Chong Yidong <cyd@stupidchicken.com>
parents:
65312
diff
changeset
|
93 (list (concat to ", " (cadr tolist))))) |
65312
915d671fef52
*** empty log message ***
Chong Yidong <cyd@stupidchicken.com>
parents:
64748
diff
changeset
|
94 (setq args (cons (list "to" to) args)))) |
915d671fef52
*** empty log message ***
Chong Yidong <cyd@stupidchicken.com>
parents:
64748
diff
changeset
|
95 |
54695 | 96 (setq subject (cdr-safe (assoc "subject" args))) |
65558
b0580e2544c0
(url-mailto): Special case `mail'.
Richard M. Stallman <rms@gnu.org>
parents:
65522
diff
changeset
|
97 (if (eq url-mail-command 'compose-mail) |
b0580e2544c0
(url-mailto): Special case `mail'.
Richard M. Stallman <rms@gnu.org>
parents:
65522
diff
changeset
|
98 (compose-mail nil nil nil 'new) |
b0580e2544c0
(url-mailto): Special case `mail'.
Richard M. Stallman <rms@gnu.org>
parents:
65522
diff
changeset
|
99 (if (eq url-mail-command 'mail) |
b0580e2544c0
(url-mailto): Special case `mail'.
Richard M. Stallman <rms@gnu.org>
parents:
65522
diff
changeset
|
100 (mail 'new) |
b0580e2544c0
(url-mailto): Special case `mail'.
Richard M. Stallman <rms@gnu.org>
parents:
65522
diff
changeset
|
101 (funcall url-mail-command))) |
54695 | 102 (while args |
103 (if (string= (caar args) "body") | |
104 (progn | |
77834
44d0773e88ea
(url-mailto): Insert body after mail-header-separator if present, so
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
105 (goto-char (point-min)) |
44d0773e88ea
(url-mailto): Insert body after mail-header-separator if present, so
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
106 (or (search-forward (concat "\n" mail-header-separator "\n") nil t) |
44d0773e88ea
(url-mailto): Insert body after mail-header-separator if present, so
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
107 (goto-char (point-max))) |
65312
915d671fef52
*** empty log message ***
Chong Yidong <cyd@stupidchicken.com>
parents:
64748
diff
changeset
|
108 (insert (mapconcat |
915d671fef52
*** empty log message ***
Chong Yidong <cyd@stupidchicken.com>
parents:
64748
diff
changeset
|
109 #'(lambda (string) |
915d671fef52
*** empty log message ***
Chong Yidong <cyd@stupidchicken.com>
parents:
64748
diff
changeset
|
110 (replace-regexp-in-string "\r\n" "\n" string)) |
915d671fef52
*** empty log message ***
Chong Yidong <cyd@stupidchicken.com>
parents:
64748
diff
changeset
|
111 (cdar args) "\n"))) |
54695 | 112 (url-mail-goto-field (caar args)) |
113 (setq func (intern-soft (concat "mail-" (caar args)))) | |
114 (insert (mapconcat 'identity (cdar args) ", "))) | |
115 (setq args (cdr args))) | |
116 ;; (url-mail-goto-field "User-Agent") | |
117 ;; (insert url-package-name "/" url-package-version " URL/" url-version) | |
118 (if (not url-request-data) | |
119 (progn | |
120 (set-buffer-modified-p nil) | |
121 (if subject | |
122 (url-mail-goto-field nil) | |
123 (url-mail-goto-field "subject"))) | |
124 (if url-request-extra-headers | |
125 (mapconcat | |
126 (lambda (x) | |
127 (url-mail-goto-field (car x)) | |
128 (insert (cdr x))) | |
129 url-request-extra-headers "")) | |
130 (goto-char (point-max)) | |
131 (insert url-request-data) | |
132 ;; It seems Microsoft-ish to send without warning. | |
133 ;; Fixme: presumably this should depend on a privacy setting. | |
134 (if (y-or-n-p "Send this auto-generated mail? ") | |
65520
d7d263fcbadc
2005-09-15 Chong Yidong <cyd@stupidchicken.com>
Chong Yidong <cyd@stupidchicken.com>
parents:
65483
diff
changeset
|
135 (let ((buffer (current-buffer))) |
d7d263fcbadc
2005-09-15 Chong Yidong <cyd@stupidchicken.com>
Chong Yidong <cyd@stupidchicken.com>
parents:
65483
diff
changeset
|
136 (cond ((eq url-mail-command 'compose-mail) |
d7d263fcbadc
2005-09-15 Chong Yidong <cyd@stupidchicken.com>
Chong Yidong <cyd@stupidchicken.com>
parents:
65483
diff
changeset
|
137 (funcall (get mail-user-agent 'sendfunc) nil)) |
d7d263fcbadc
2005-09-15 Chong Yidong <cyd@stupidchicken.com>
Chong Yidong <cyd@stupidchicken.com>
parents:
65483
diff
changeset
|
138 ;; otherwise, we can't be sure |
d7d263fcbadc
2005-09-15 Chong Yidong <cyd@stupidchicken.com>
Chong Yidong <cyd@stupidchicken.com>
parents:
65483
diff
changeset
|
139 ((fboundp 'message-send-and-exit) |
d7d263fcbadc
2005-09-15 Chong Yidong <cyd@stupidchicken.com>
Chong Yidong <cyd@stupidchicken.com>
parents:
65483
diff
changeset
|
140 (message-send-and-exit)) |
d7d263fcbadc
2005-09-15 Chong Yidong <cyd@stupidchicken.com>
Chong Yidong <cyd@stupidchicken.com>
parents:
65483
diff
changeset
|
141 (t (mail-send-and-exit nil))) |
d7d263fcbadc
2005-09-15 Chong Yidong <cyd@stupidchicken.com>
Chong Yidong <cyd@stupidchicken.com>
parents:
65483
diff
changeset
|
142 (kill-buffer buffer)))) |
54695 | 143 nil)) |
144 | |
145 (provide 'url-mailto) | |
54699 | 146 |
54800
bab00fb32e72
(url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
147 ;; arch-tag: 7b7ad52e-8760-497b-9444-75fae14e34c5 |
bab00fb32e72
(url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
148 ;;; url-mailto.el ends here |