annotate lisp/url/url-mailto.el @ 55399:5bf40b98f529

*** empty log message ***
author Nick Roberts <nickrob@snap.net.nz>
date Thu, 06 May 2004 22:56:22 +0000
parents bab00fb32e72
children 01934125951e eb7e8d483840
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
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 ;; Copyright (c) 1993 - 1996 by William M. Perry <wmperry@cs.indiana.edu>
bab00fb32e72 (url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
5
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
6 ;; Keywords: comm, data, processes
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
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
bab00fb32e72 (url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
12 ;; 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
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
bab00fb32e72 (url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
bab00fb32e72 (url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
23 ;; Boston, MA 02111-1307, USA.
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
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
28
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
29 (eval-when-compile (require 'cl))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
30 (require 'url-vars)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
31 (require 'url-parse)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
32 (require 'url-util)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
33
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
34 ;;;###autoload
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
35 (defun url-mail (&rest args)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
36 (interactive "P")
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
37 (if (fboundp 'message-mail)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
38 (apply 'message-mail args)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
39 (or (apply 'mail args)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
40 (error "Mail aborted"))))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
41
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
42 (defun url-mail-goto-field (field)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
43 (if (not field)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
44 (goto-char (point-max))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
45 (let ((dest nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
46 (lim nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
47 (case-fold-search t))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
48 (save-excursion
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
49 (goto-char (point-min))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
50 (if (re-search-forward (regexp-quote mail-header-separator) nil t)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
51 (setq lim (match-beginning 0)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
52 (goto-char (point-min))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
53 (if (re-search-forward (concat "^" (regexp-quote field) ":") lim t)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
54 (setq dest (match-beginning 0))))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
55 (if dest
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
56 (progn
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
57 (goto-char dest)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
58 (end-of-line))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
59 (goto-char lim)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
60 (insert (capitalize field) ": ")
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
61 (save-excursion
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
62 (insert "\n"))))))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
63
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
64 ;;;###autoload
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
65 (defun url-mailto (url)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
66 "Handle the mailto: URL syntax."
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
67 (if (url-user url)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
68 ;; malformed mailto URL (mailto://wmperry@gnu.org instead of
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
69 ;; mailto:wmperry@gnu.org
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
70 (url-set-filename url (concat (url-user url) "@" (url-filename url))))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
71 (setq url (url-filename url))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
72 (let (to args source-url subject func headers-start)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
73 (if (string-match (regexp-quote "?") url)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
74 (setq headers-start (match-end 0)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
75 to (url-unhex-string (substring url 0 (match-beginning 0)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
76 args (url-parse-query-string
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
77 (substring url headers-start nil) t))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
78 (setq to (url-unhex-string url)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
79 (setq source-url (url-view-url t))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
80 (if (and url-request-data (not (assoc "subject" args)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
81 (setq args (cons (list "subject"
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
82 (concat "Automatic submission from "
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
83 url-package-name "/"
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
84 url-package-version)) args)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
85 (if (and source-url (not (assoc "x-url-from" args)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
86 (setq args (cons (list "x-url-from" source-url) args)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
87
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
88 (if (assoc "to" args)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
89 (push to (cdr (assoc "to" args)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
90 (setq args (cons (list "to" to) args)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
91 (setq subject (cdr-safe (assoc "subject" args)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
92 (if (fboundp url-mail-command) (funcall url-mail-command) (mail))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
93 (while args
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
94 (if (string= (caar args) "body")
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
95 (progn
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
96 (goto-char (point-max))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
97 (insert (mapconcat 'identity (cdar args) "\n")))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
98 (url-mail-goto-field (caar args))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
99 (setq func (intern-soft (concat "mail-" (caar args))))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
100 (insert (mapconcat 'identity (cdar args) ", ")))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
101 (setq args (cdr args)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
102 ;; (url-mail-goto-field "User-Agent")
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
103 ;; (insert url-package-name "/" url-package-version " URL/" url-version)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
104 (if (not url-request-data)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
105 (progn
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
106 (set-buffer-modified-p nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
107 (if subject
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
108 (url-mail-goto-field nil)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
109 (url-mail-goto-field "subject")))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
110 (if url-request-extra-headers
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
111 (mapconcat
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
112 (lambda (x)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
113 (url-mail-goto-field (car x))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
114 (insert (cdr x)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
115 url-request-extra-headers ""))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
116 (goto-char (point-max))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
117 (insert url-request-data)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
118 ;; It seems Microsoft-ish to send without warning.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
119 ;; Fixme: presumably this should depend on a privacy setting.
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
120 (if (y-or-n-p "Send this auto-generated mail? ")
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
121 (cond ((eq url-mail-command 'compose-mail)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
122 (funcall (get mail-user-agent 'sendfunc) nil))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
123 ;; otherwise, we can't be sure
54800
bab00fb32e72 (url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
124 ((fboundp 'message-send-and-exit)
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
125 (message-send-and-exit))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
126 (t (mail-send-and-exit nil)))))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
127 nil))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
128
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
129 (provide 'url-mailto)
54699
7784ae10206d Resolve CVS conflicts
Miles Bader <miles@gnu.org>
parents: 54695
diff changeset
130
54800
bab00fb32e72 (url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
131 ;; arch-tag: 7b7ad52e-8760-497b-9444-75fae14e34c5
bab00fb32e72 (url-mailto): Avoid warning.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
132 ;;; url-mailto.el ends here