Mercurial > emacs
annotate lisp/url/url-mailto.el @ 59496:3d286951fbc3
*** empty log message ***
author | Nick Roberts <nickrob@snap.net.nz> |
---|---|
date | Wed, 12 Jan 2005 06:12:34 +0000 |
parents | 9eeb05e27d32 |
children | a8fa7c632ee4 3ec251523b3e |
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 |
bab00fb32e72
(url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
3 ;; Copyright (c) 1996 - 1999 Free Software Foundation, Inc. |
bab00fb32e72
(url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
4 |
54695 | 5 ;; Keywords: comm, data, processes |
6 | |
54800
bab00fb32e72
(url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
7 ;; This file is part of GNU Emacs. |
bab00fb32e72
(url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
8 ;; |
bab00fb32e72
(url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
9 ;; 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
|
10 ;; it under the terms of the GNU General Public License as published by |
bab00fb32e72
(url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
11 ;; the Free Software Foundation; either version 2, or (at your option) |
bab00fb32e72
(url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
12 ;; any later version. |
bab00fb32e72
(url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
13 ;; |
bab00fb32e72
(url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
14 ;; 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
|
15 ;; 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
|
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bab00fb32e72
(url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
17 ;; GNU General Public License for more details. |
bab00fb32e72
(url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
18 ;; |
bab00fb32e72
(url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
19 ;; 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
|
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
bab00fb32e72
(url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
bab00fb32e72
(url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
22 ;; Boston, MA 02111-1307, USA. |
bab00fb32e72
(url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
23 |
bab00fb32e72
(url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
24 ;;; Commentary: |
bab00fb32e72
(url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
25 |
bab00fb32e72
(url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
26 ;;; Code: |
54695 | 27 |
28 (require 'url-vars) | |
29 (require 'url-parse) | |
30 (require 'url-util) | |
31 | |
32 ;;;###autoload | |
33 (defun url-mail (&rest args) | |
34 (interactive "P") | |
35 (if (fboundp 'message-mail) | |
36 (apply 'message-mail args) | |
37 (or (apply 'mail args) | |
38 (error "Mail aborted")))) | |
39 | |
40 (defun url-mail-goto-field (field) | |
41 (if (not field) | |
42 (goto-char (point-max)) | |
43 (let ((dest nil) | |
44 (lim nil) | |
45 (case-fold-search t)) | |
46 (save-excursion | |
47 (goto-char (point-min)) | |
48 (if (re-search-forward (regexp-quote mail-header-separator) nil t) | |
49 (setq lim (match-beginning 0))) | |
50 (goto-char (point-min)) | |
51 (if (re-search-forward (concat "^" (regexp-quote field) ":") lim t) | |
52 (setq dest (match-beginning 0)))) | |
53 (if dest | |
54 (progn | |
55 (goto-char dest) | |
56 (end-of-line)) | |
57 (goto-char lim) | |
58 (insert (capitalize field) ": ") | |
59 (save-excursion | |
60 (insert "\n")))))) | |
61 | |
62 ;;;###autoload | |
63 (defun url-mailto (url) | |
64 "Handle the mailto: URL syntax." | |
65 (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
|
66 ;; malformed mailto URL (mailto://wmperry@gnu.org) instead of |
54695 | 67 ;; mailto:wmperry@gnu.org |
68 (url-set-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)) | |
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 " | |
81 url-package-name "/" | |
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))) | |
85 | |
86 (if (assoc "to" args) | |
57511 | 87 (push (cdr (assoc "to" args)) to) |
54695 | 88 (setq args (cons (list "to" to) args))) |
89 (setq subject (cdr-safe (assoc "subject" args))) | |
90 (if (fboundp url-mail-command) (funcall url-mail-command) (mail)) | |
91 (while args | |
92 (if (string= (caar args) "body") | |
93 (progn | |
94 (goto-char (point-max)) | |
95 (insert (mapconcat 'identity (cdar args) "\n"))) | |
96 (url-mail-goto-field (caar args)) | |
97 (setq func (intern-soft (concat "mail-" (caar args)))) | |
98 (insert (mapconcat 'identity (cdar args) ", "))) | |
99 (setq args (cdr args))) | |
100 ;; (url-mail-goto-field "User-Agent") | |
101 ;; (insert url-package-name "/" url-package-version " URL/" url-version) | |
102 (if (not url-request-data) | |
103 (progn | |
104 (set-buffer-modified-p nil) | |
105 (if subject | |
106 (url-mail-goto-field nil) | |
107 (url-mail-goto-field "subject"))) | |
108 (if url-request-extra-headers | |
109 (mapconcat | |
110 (lambda (x) | |
111 (url-mail-goto-field (car x)) | |
112 (insert (cdr x))) | |
113 url-request-extra-headers "")) | |
114 (goto-char (point-max)) | |
115 (insert url-request-data) | |
116 ;; It seems Microsoft-ish to send without warning. | |
117 ;; Fixme: presumably this should depend on a privacy setting. | |
118 (if (y-or-n-p "Send this auto-generated mail? ") | |
119 (cond ((eq url-mail-command 'compose-mail) | |
120 (funcall (get mail-user-agent 'sendfunc) nil)) | |
121 ;; otherwise, we can't be sure | |
54800
bab00fb32e72
(url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
122 ((fboundp 'message-send-and-exit) |
54695 | 123 (message-send-and-exit)) |
124 (t (mail-send-and-exit nil))))) | |
125 nil)) | |
126 | |
127 (provide 'url-mailto) | |
54699 | 128 |
54800
bab00fb32e72
(url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
129 ;; arch-tag: 7b7ad52e-8760-497b-9444-75fae14e34c5 |
bab00fb32e72
(url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54770
diff
changeset
|
130 ;;; url-mailto.el ends here |