14
|
1 ;;; url-mail.el --- Mail Uniform Resource Locator retrieval code
|
|
2 ;; Author: wmperry
|
16
|
3 ;; Created: 1997/01/20 19:52:07
|
|
4 ;; Version: 1.7
|
14
|
5 ;; Keywords: comm, data, processes
|
|
6
|
|
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
8 ;;; Copyright (c) 1993-1996 by William M. Perry (wmperry@cs.indiana.edu)
|
16
|
9 ;;; Copyright (c) 1996, 1997 Free Software Foundation, Inc.
|
14
|
10 ;;;
|
|
11 ;;; This file is not part of GNU Emacs, but the same permissions apply.
|
|
12 ;;;
|
|
13 ;;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
14 ;;; it under the terms of the GNU General Public License as published by
|
|
15 ;;; the Free Software Foundation; either version 2, or (at your option)
|
|
16 ;;; any later version.
|
|
17 ;;;
|
|
18 ;;; GNU Emacs is distributed in the hope that it will be useful,
|
|
19 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
20 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
21 ;;; GNU General Public License for more details.
|
|
22 ;;;
|
|
23 ;;; You should have received a copy of the GNU General Public License
|
|
24 ;;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
25 ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
26 ;;; Boston, MA 02111-1307, USA.
|
|
27 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
28
|
|
29 (require 'url-vars)
|
|
30 (require 'url-parse)
|
|
31
|
|
32 (defmacro url-mailserver-skip-chunk ()
|
|
33 (` (while (and (not (looking-at "/"))
|
|
34 (not (eobp)))
|
|
35 (forward-sexp 1))))
|
|
36
|
|
37 (defun url-mail (&rest args)
|
|
38 (interactive "P")
|
16
|
39 (if (fboundp 'message-mail)
|
|
40 (apply 'message-mail args)
|
|
41 (or (apply 'mail args)
|
|
42 (error "Mail aborted"))))
|
14
|
43
|
|
44 (defun url-mail-goto-field (field)
|
|
45 (if (not field)
|
|
46 (goto-char (point-max))
|
|
47 (let ((dest nil)
|
|
48 (lim nil)
|
|
49 (case-fold-search t))
|
|
50 (save-excursion
|
|
51 (goto-char (point-min))
|
|
52 (if (re-search-forward (regexp-quote mail-header-separator) nil t)
|
|
53 (setq lim (match-beginning 0)))
|
|
54 (goto-char (point-min))
|
|
55 (if (re-search-forward (concat "^" (regexp-quote field) ":") lim t)
|
|
56 (setq dest (match-beginning 0))))
|
|
57 (if dest
|
|
58 (progn
|
|
59 (goto-char dest)
|
|
60 (end-of-line))
|
|
61 (goto-char lim)
|
|
62 (insert (capitalize field) ": ")
|
|
63 (save-excursion
|
|
64 (insert "\n"))))))
|
|
65
|
|
66 (defun url-mailto (url)
|
|
67 ;; Send mail to someone
|
|
68 (if (not (string-match "mailto:/*\\(.*\\)" url))
|
|
69 (error "Malformed mailto link: %s" url))
|
|
70 (setq url (substring url (match-beginning 1) nil))
|
|
71 (if (get-buffer url-working-buffer)
|
|
72 (kill-buffer url-working-buffer))
|
|
73 (let (to args source-url subject func)
|
|
74 (if (string-match (regexp-quote "?") url)
|
|
75 (setq to (url-unhex-string (substring url 0 (match-beginning 0)))
|
|
76 args (url-parse-query-string
|
|
77 (substring url (match-end 0) nil) t))
|
|
78 (setq to (url-unhex-string url)))
|
|
79 (setq source-url (url-view-url t))
|
|
80 (if (and url-request-data (not (assoc "subject" args)))
|
|
81 (setq args (cons (list "subject"
|
|
82 (concat "Automatic submission from "
|
|
83 url-package-name "/"
|
|
84 url-package-version)) args)))
|
|
85 (if (and source-url (not (assoc "x-url-from" args)))
|
|
86 (setq args (cons (list "x-url-from" source-url) args)))
|
|
87 (setq args (cons (list "to" to) args)
|
|
88 subject (cdr-safe (assoc "subject" args)))
|
|
89 (if (fboundp url-mail-command) (funcall url-mail-command) (mail))
|
|
90 (while args
|
|
91 (url-mail-goto-field (caar args))
|
|
92 (setq func (intern-soft (concat "mail-" (caar args))))
|
|
93 (insert (mapconcat 'identity (cdar args) ", "))
|
|
94 (setq args (cdr args)))
|
|
95 (url-mail-goto-field "X-Mailer")
|
|
96 (insert url-package-name "/" url-package-version)
|
|
97 (if (not url-request-data)
|
|
98 (if subject
|
|
99 (url-mail-goto-field nil)
|
|
100 (url-mail-goto-field "subject"))
|
|
101 (if url-request-extra-headers
|
|
102 (mapconcat
|
|
103 (function
|
|
104 (lambda (x)
|
|
105 (url-mail-goto-field (car x))
|
|
106 (insert (cdr x))))
|
|
107 url-request-extra-headers ""))
|
|
108 (goto-char (point-max))
|
|
109 (insert url-request-data)
|
|
110 (mail-send-and-exit nil))))
|
|
111
|
|
112 (defun url-mailserver (url)
|
|
113 ;; Send mail to someone, much cooler/functional than mailto
|
|
114 (if (get-buffer url-working-buffer)
|
|
115 (kill-buffer url-working-buffer))
|
|
116 (set-buffer (get-buffer-create " *mailserver*"))
|
|
117 (erase-buffer)
|
|
118 (insert url)
|
|
119 (goto-char (point-min))
|
|
120 (set-syntax-table url-mailserver-syntax-table)
|
|
121 (skip-chars-forward "^:") ; Get past mailserver
|
|
122 (skip-chars-forward ":") ; Get past :
|
|
123 ;; Handle some ugly malformed URLs, but bitch about it.
|
|
124 (if (looking-at "/")
|
|
125 (progn
|
|
126 (url-warn 'url "Invalid mailserver URL... attempting to cope.")
|
|
127 (skip-chars-forward "/")))
|
|
128
|
|
129 (let ((save-pos (point))
|
|
130 (url (url-view-url t))
|
|
131 (rfc822-addr nil)
|
|
132 (subject nil)
|
|
133 (body nil))
|
|
134 (url-mailserver-skip-chunk)
|
|
135 (setq rfc822-addr (buffer-substring save-pos (point)))
|
|
136 (forward-char 1)
|
|
137 (setq save-pos (point))
|
|
138 (url-mailserver-skip-chunk)
|
|
139 (setq subject (buffer-substring save-pos (point)))
|
|
140 (if (not (eobp))
|
|
141 (progn ; There is some text to use
|
|
142 (forward-char 1) ; as the body of the message
|
|
143 (setq body (buffer-substring (point) (point-max)))))
|
|
144 (if (fboundp url-mail-command) (funcall url-mail-command) (mail))
|
|
145 (url-mail-goto-field "to")
|
|
146 (insert rfc822-addr)
|
|
147 (if (and url (not (string= url "")))
|
|
148 (progn
|
|
149 (url-mail-goto-field "X-URL-From")
|
|
150 (insert url)))
|
|
151 (url-mail-goto-field "X-Mailer")
|
|
152 (insert url-package-name "/" url-package-version)
|
|
153 (url-mail-goto-field "subject")
|
|
154 ;; Massage the subject from URLEncoded garbage
|
|
155 ;; Note that we do not allow any newlines in the subject,
|
|
156 ;; as recommended by the Internet Draft on the mailserver
|
|
157 ;; URL - this means the document author cannot spoof additional
|
|
158 ;; header lines, which is a 'Good Thing'
|
|
159 (if subject
|
|
160 (progn
|
|
161 (setq subject (url-unhex-string subject))
|
|
162 (let ((x (1- (length subject)))
|
|
163 (y 0))
|
|
164 (while (<= y x)
|
|
165 (if (memq (aref subject y) '(?\r ?\n))
|
|
166 (aset subject y ? ))
|
|
167 (setq y (1+ y))))))
|
|
168 (insert subject)
|
|
169 (if url-request-extra-headers
|
|
170 (progn
|
|
171 (goto-char (point-min))
|
|
172 (insert
|
|
173 (mapconcat
|
|
174 (function
|
|
175 (lambda (x)
|
|
176 (url-mail-goto-field (car x))
|
|
177 (insert (cdr x))))
|
|
178 url-request-extra-headers ""))))
|
|
179 (goto-char (point-max))
|
|
180 ;; Massage the body from URLEncoded garbage
|
|
181 (if body
|
|
182 (let ((x (1- (length body)))
|
|
183 (y 0))
|
|
184 (while (<= y x)
|
|
185 (if (= (aref body y) ?/)
|
|
186 (aset body y ?\n))
|
|
187 (setq y (1+ y)))
|
|
188 (setq body (url-unhex-string body))))
|
|
189 (and body (insert body))
|
|
190 (and url-request-data (insert url-request-data))
|
|
191 (if (and (or body url-request-data)
|
|
192 (funcall url-confirmation-func
|
|
193 (concat "Send message to " rfc822-addr "? ")))
|
|
194 (mail-send-and-exit nil))))
|
|
195
|
|
196 (provide 'url-mail)
|