annotate lisp/url/url-mail.el @ 9:6f2bbbbbe05a

Added tag r19-15b5 for changeset 4b173ad71786
author cvs
date Mon, 13 Aug 2007 08:47:36 +0200
parents 376386a54a3c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; url-mail.el,v --- Mail Uniform Resource Locator retrieval code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;; Author: wmperry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Created: 1996/06/03 15:04:49
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; Version: 1.5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Keywords: comm, data, processes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;;; Copyright (c) 1993, 1994, 1995 by William M. Perry (wmperry@spry.com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;;; This file is not part of GNU Emacs, but the same permissions apply.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;;; GNU Emacs is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;;; it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;;; GNU Emacs is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;;; GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;;; along with GNU Emacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 (require 'url-vars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 (require 'url-parse)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 (defmacro url-mailserver-skip-chunk ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 (` (while (and (not (looking-at "/"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 (not (eobp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 (forward-sexp 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 (defun url-mail (&rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 (or (apply 'mail args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 (error "Mail aborted")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 (defun url-mailto (url)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;; Send mail to someone
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (if (not (string-match "mailto:/*\\(.*\\)" url))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 (error "Malformed mailto link: %s" url))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (if (get-buffer url-working-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (kill-buffer url-working-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (let ((to (url-unhex-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (substring url (match-beginning 1) (match-end 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (url (url-view-url t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (if (fboundp url-mail-command) (funcall url-mail-command) (mail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (mail-to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (insert (concat to "\nX-URL-From: " url))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (mail-subject)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (if (not url-request-data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 nil ; Not automatic posting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (insert "Automatic submission from "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 url-package-name "/" url-package-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (if url-request-extra-headers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (mapconcat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (lambda (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (concat (capitalize (car x)) ": " (cdr x) "\n")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 url-request-extra-headers ""))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (insert url-request-data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (mail-send-and-exit nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (defun url-mailserver (url)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 ;; Send mail to someone, much cooler/functional than mailto
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (if (get-buffer url-working-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (kill-buffer url-working-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (set-buffer (get-buffer-create " *mailserver*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (insert url)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (set-syntax-table url-mailserver-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (skip-chars-forward "^:") ; Get past mailserver
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (skip-chars-forward ":") ; Get past :
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ;; Handle some ugly malformed URLs, but bitch about it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (if (looking-at "/")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (url-warn 'url "Invalid mailserver URL... attempting to cope.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (skip-chars-forward "/")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (let ((save-pos (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (url (url-view-url t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (rfc822-addr nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (subject nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (body nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (url-mailserver-skip-chunk)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (setq rfc822-addr (buffer-substring save-pos (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (setq save-pos (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (url-mailserver-skip-chunk)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (setq subject (buffer-substring save-pos (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (if (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (progn ; There is some text to use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (forward-char 1) ; as the body of the message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (setq body (buffer-substring (point) (point-max)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (if (fboundp url-mail-command) (funcall url-mail-command) (mail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (mail-to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (insert (concat rfc822-addr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (if (and url (not (string= url "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (concat "\nX-URL-From: " url) "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 "\nX-User-Agent: " url-package-name "/"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 url-package-version))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (mail-subject)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 ;; Massage the subject from URLEncoded garbage
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 ;; Note that we do not allow any newlines in the subject,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 ;; as recommended by the Internet Draft on the mailserver
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 ;; URL - this means the document author cannot spoof additional
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 ;; header lines, which is a 'Good Thing'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (if subject
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (setq subject (url-unhex-string subject))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (let ((x (1- (length subject)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (y 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (while (<= y x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (if (memq (aref subject y) '(?\r ?\n))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (aset subject y ? ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (setq y (1+ y))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (insert subject)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (if url-request-extra-headers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (mapconcat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (lambda (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (concat (capitalize (car x)) ": " (cdr x) "\n")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 url-request-extra-headers ""))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 ;; Massage the body from URLEncoded garbage
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (if body
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (let ((x (1- (length body)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (y 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (while (<= y x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (if (= (aref body y) ?/)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (aset body y ?\n))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (setq y (1+ y)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (setq body (url-unhex-string body))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (and body (insert body))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (and url-request-data (insert url-request-data))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (if (and (or body url-request-data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (funcall url-confirmation-func
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (concat "Send message to " rfc822-addr "? ")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (mail-send-and-exit nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (provide 'url-mail)