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