Mercurial > emacs
annotate lisp/mail/smtpmail.el @ 15577:e369d2f12bc7
Load `gnus-score-mode' from "score-mode".
author | Lars Magne Ingebrigtsen <larsi@gnus.org> |
---|---|
date | Sun, 30 Jun 1996 18:19:19 +0000 |
parents | 85313b347ed9 |
children | 0d4a7f47f31d |
rev | line source |
---|---|
15345 | 1 ;; Simple SMTP protocol (RFC 821) for sending mail |
2 | |
15451
89c1e7fe879a
(smtpmail-smtp-service): Use port 25 as default.
Richard M. Stallman <rms@gnu.org>
parents:
15372
diff
changeset
|
3 ;; Copyright (C) 1995, 1996 Free Software Foundation, Inc. |
15345 | 4 |
5 ;; Author: Tomoji Kagatani <kagatani@rbc.ncl.omron.co.jp> | |
15452
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
6 ;; Maintainer: Brian D. Carlstrom <bdc@ai.mit.edu> |
15345 | 7 ;; Keywords: mail |
8 | |
9 ;; This file is part of GNU Emacs. | |
10 | |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
13 ;; the Free Software Foundation; either version 2, or (at your option) | |
14 ;; any later version. | |
15 | |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 ;; Boston, MA 02111-1307, USA. | |
25 | |
26 ;;; Commentary: | |
27 | |
28 ;; Send Mail to smtp host from smtpmail temp buffer. | |
29 | |
30 ;; Please add these lines in your .emacs(_emacs). | |
31 ;; | |
32 ;;(setq send-mail-function 'smtpmail-send-it) | |
33 ;;(setq smtpmail-default-smtp-server "YOUR SMTP HOST") | |
34 ;;(setq smtpmail-smtp-service "smtp") | |
35 ;;(setq smtpmail-local-domain "YOUR DOMAIN NAME") | |
36 ;;(setq smtpmail-debug-info t) | |
37 ;;(load-library "smtpmail") | |
38 ;;(setq smtpmail-code-conv-from nil) | |
15452
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
39 ;;(setq user-full-name "YOUR NAME HERE") |
15345 | 40 |
41 ;;; Code: | |
42 | |
43 (require 'sendmail) | |
44 | |
45 ;;; | |
46 (defvar smtpmail-default-smtp-server nil | |
47 "*Specify default SMTP server.") | |
48 | |
15451
89c1e7fe879a
(smtpmail-smtp-service): Use port 25 as default.
Richard M. Stallman <rms@gnu.org>
parents:
15372
diff
changeset
|
49 (defvar smtpmail-smtp-server |
89c1e7fe879a
(smtpmail-smtp-service): Use port 25 as default.
Richard M. Stallman <rms@gnu.org>
parents:
15372
diff
changeset
|
50 (or (getenv "SMTPSERVER") smtpmail-default-smtp-server) |
15345 | 51 "*The name of the host running SMTP server.") |
52 | |
15451
89c1e7fe879a
(smtpmail-smtp-service): Use port 25 as default.
Richard M. Stallman <rms@gnu.org>
parents:
15372
diff
changeset
|
53 (defvar smtpmail-smtp-service 25 |
15345 | 54 "*SMTP service port number. smtp or 25 .") |
55 | |
56 (defvar smtpmail-local-domain nil | |
57 "*Local domain name without a host name. | |
58 If the function (system-name) returns the full internet address, | |
59 don't define this value.") | |
60 | |
61 (defvar smtpmail-debug-info nil | |
62 "*smtpmail debug info printout. messages and process buffer.") | |
63 | |
64 (defvar smtpmail-code-conv-from nil ;; *junet* | |
65 "*smtpmail code convert from this code to *internal*..for tiny-mime..") | |
66 | |
67 ;;; | |
68 ;;; | |
69 ;;; | |
70 | |
71 (defun smtpmail-send-it () | |
15451
89c1e7fe879a
(smtpmail-smtp-service): Use port 25 as default.
Richard M. Stallman <rms@gnu.org>
parents:
15372
diff
changeset
|
72 (require 'mail-utils) |
15345 | 73 (let ((errbuf (if mail-interactive |
74 (generate-new-buffer " smtpmail errors") | |
75 0)) | |
76 (tembuf (generate-new-buffer " smtpmail temp")) | |
77 (case-fold-search nil) | |
78 resend-to-addresses | |
79 delimline | |
80 (mailbuf (current-buffer))) | |
81 (unwind-protect | |
82 (save-excursion | |
83 (set-buffer tembuf) | |
84 (erase-buffer) | |
85 (insert-buffer-substring mailbuf) | |
86 (goto-char (point-max)) | |
87 ;; require one newline at the end. | |
88 (or (= (preceding-char) ?\n) | |
89 (insert ?\n)) | |
90 ;; Change header-delimiter to be what sendmail expects. | |
91 (goto-char (point-min)) | |
92 (re-search-forward | |
93 (concat "^" (regexp-quote mail-header-separator) "\n")) | |
94 (replace-match "\n") | |
95 (backward-char 1) | |
96 (setq delimline (point-marker)) | |
15451
89c1e7fe879a
(smtpmail-smtp-service): Use port 25 as default.
Richard M. Stallman <rms@gnu.org>
parents:
15372
diff
changeset
|
97 ;; (sendmail-synch-aliases) |
15345 | 98 (if mail-aliases |
99 (expand-mail-aliases (point-min) delimline)) | |
100 (goto-char (point-min)) | |
101 ;; ignore any blank lines in the header | |
102 (while (and (re-search-forward "\n\n\n*" delimline t) | |
103 (< (point) delimline)) | |
104 (replace-match "\n")) | |
105 (let ((case-fold-search t)) | |
106 (goto-char (point-min)) | |
107 (goto-char (point-min)) | |
108 (while (re-search-forward "^Resent-to:" delimline t) | |
109 (setq resend-to-addresses | |
110 (save-restriction | |
111 (narrow-to-region (point) | |
112 (save-excursion | |
113 (end-of-line) | |
114 (point))) | |
115 (append (mail-parse-comma-list) | |
116 resend-to-addresses)))) | |
117 ;;; Apparently this causes a duplicate Sender. | |
118 ;;; ;; If the From is different than current user, insert Sender. | |
119 ;;; (goto-char (point-min)) | |
120 ;;; (and (re-search-forward "^From:" delimline t) | |
121 ;;; (progn | |
122 ;;; (require 'mail-utils) | |
123 ;;; (not (string-equal | |
124 ;;; (mail-strip-quoted-names | |
125 ;;; (save-restriction | |
126 ;;; (narrow-to-region (point-min) delimline) | |
127 ;;; (mail-fetch-field "From"))) | |
128 ;;; (user-login-name)))) | |
129 ;;; (progn | |
130 ;;; (forward-line 1) | |
131 ;;; (insert "Sender: " (user-login-name) "\n"))) | |
132 ;; Don't send out a blank subject line | |
133 (goto-char (point-min)) | |
134 (if (re-search-forward "^Subject:[ \t]*\n" delimline t) | |
135 (replace-match "")) | |
15452
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
136 ;; Put the "From:" field in unless for some odd reason |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
137 ;; they put one in themselves. |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
138 (goto-char (point-min)) |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
139 (if (not (re-search-forward "^From:" delimline t)) |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
140 (let* ((login user-mail-address) |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
141 (fullname (user-full-name))) |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
142 (cond ((eq mail-from-style 'angles) |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
143 (insert "From: " fullname) |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
144 (let ((fullname-start (+ (point-min) 6)) |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
145 (fullname-end (point-marker))) |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
146 (goto-char fullname-start) |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
147 ;; Look for a character that cannot appear unquoted |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
148 ;; according to RFC 822. |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
149 (if (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
150 fullname-end 1) |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
151 (progn |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
152 ;; Quote fullname, escaping specials. |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
153 (goto-char fullname-start) |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
154 (insert "\"") |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
155 (while (re-search-forward "[\"\\]" |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
156 fullname-end 1) |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
157 (replace-match "\\\\\\&" t)) |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
158 (insert "\"")))) |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
159 (insert " <" login ">\n")) |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
160 ((eq mail-from-style 'parens) |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
161 (insert "From: " login " (") |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
162 (let ((fullname-start (point))) |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
163 (insert fullname) |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
164 (let ((fullname-end (point-marker))) |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
165 (goto-char fullname-start) |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
166 ;; RFC 822 says \ and nonmatching parentheses |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
167 ;; must be escaped in comments. |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
168 ;; Escape every instance of ()\ ... |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
169 (while (re-search-forward "[()\\]" fullname-end 1) |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
170 (replace-match "\\\\\\&" t)) |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
171 ;; ... then undo escaping of matching parentheses, |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
172 ;; including matching nested parentheses. |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
173 (goto-char fullname-start) |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
174 (while (re-search-forward |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
175 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)" |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
176 fullname-end 1) |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
177 (replace-match "\\1(\\3)" t) |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
178 (goto-char fullname-start)))) |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
179 (insert ")\n")) |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
180 ((null mail-from-style) |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
181 (insert "From: " login "\n"))))) |
15345 | 182 ;; Insert an extra newline if we need it to work around |
183 ;; Sun's bug that swallows newlines. | |
184 (goto-char (1+ delimline)) | |
185 (if (eval mail-mailer-swallows-blank-line) | |
186 (newline)) | |
15452
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
187 ;; Find and handle any FCC fields. |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
188 (goto-char (point-min)) |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
189 (if (re-search-forward "^FCC:" delimline t) |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
190 (mail-do-fcc delimline)) |
15345 | 191 (if mail-interactive |
192 (save-excursion | |
193 (set-buffer errbuf) | |
194 (erase-buffer)))) | |
195 ;; | |
196 ;; | |
197 ;; | |
198 (setq smtpmail-address-buffer (generate-new-buffer "*smtp-mail*")) | |
199 (setq smtpmail-recipient-address-list | |
200 (smtpmail-deduce-address-list tembuf (point-min) delimline)) | |
201 (kill-buffer smtpmail-address-buffer) | |
202 | |
203 (smtpmail-do-bcc delimline) | |
204 | |
205 (if (not (null smtpmail-recipient-address-list)) | |
206 (if (not (smtpmail-via-smtp smtpmail-recipient-address-list tembuf)) | |
15346
4cd6ff2384dc
(smtpmail-send-it): Fix error messages.
Richard M. Stallman <rms@gnu.org>
parents:
15345
diff
changeset
|
207 (error "Sending failed; SMTP protocol error")) |
4cd6ff2384dc
(smtpmail-send-it): Fix error messages.
Richard M. Stallman <rms@gnu.org>
parents:
15345
diff
changeset
|
208 (error "Sending failed; no recipients")) |
15345 | 209 ) |
210 (kill-buffer tembuf) | |
211 (if (bufferp errbuf) | |
212 (kill-buffer errbuf))))) | |
213 | |
214 | |
215 ;(defun smtpmail-via-smtp (host,port,sender,destination,smtpmail-text-buffer) | |
216 | |
217 (defun smtpmail-fqdn () | |
218 (if smtpmail-local-domain | |
219 (concat (system-name) "." smtpmail-local-domain) | |
220 (system-name))) | |
221 | |
222 (defun smtpmail-via-smtp (recipient smtpmail-text-buffer) | |
223 (let ((process nil) | |
15346
4cd6ff2384dc
(smtpmail-send-it): Fix error messages.
Richard M. Stallman <rms@gnu.org>
parents:
15345
diff
changeset
|
224 (host smtpmail-smtp-server) |
4cd6ff2384dc
(smtpmail-send-it): Fix error messages.
Richard M. Stallman <rms@gnu.org>
parents:
15345
diff
changeset
|
225 (port smtpmail-smtp-service) |
15345 | 226 response-code |
15346
4cd6ff2384dc
(smtpmail-send-it): Fix error messages.
Richard M. Stallman <rms@gnu.org>
parents:
15345
diff
changeset
|
227 greeting |
4cd6ff2384dc
(smtpmail-send-it): Fix error messages.
Richard M. Stallman <rms@gnu.org>
parents:
15345
diff
changeset
|
228 process-buffer) |
15345 | 229 (unwind-protect |
230 (catch 'done | |
231 ;; get or create the trace buffer | |
232 (setq process-buffer | |
233 (get-buffer-create (format "*trace of SMTP session to %s*" host))) | |
234 | |
235 ;; clear the trace buffer of old output | |
236 (save-excursion | |
237 (set-buffer process-buffer) | |
238 (erase-buffer)) | |
239 | |
240 ;; open the connection to the server | |
241 (setq process (open-network-stream "SMTP" process-buffer host port)) | |
242 (and (null process) (throw 'done nil)) | |
243 | |
244 ;; set the send-filter | |
245 (set-process-filter process 'smtpmail-process-filter) | |
246 | |
247 (save-excursion | |
248 (set-buffer process-buffer) | |
249 (make-local-variable 'smtpmail-read-point) | |
250 (setq smtpmail-read-point (point-min)) | |
251 | |
252 | |
253 (if (or (null (car (setq greeting (smtpmail-read-response process)))) | |
254 (not (integerp (car greeting))) | |
255 (>= (car greeting) 400)) | |
256 (throw 'done nil) | |
257 ) | |
258 | |
259 ;; HELO | |
260 (smtpmail-send-command process (format "HELO %s" (smtpmail-fqdn))) | |
261 | |
262 (if (or (null (car (setq response-code (smtpmail-read-response process)))) | |
263 (not (integerp (car response-code))) | |
264 (>= (car response-code) 400)) | |
265 (throw 'done nil) | |
266 ) | |
267 | |
268 ;; MAIL FROM: <sender> | |
269 ; (smtpmail-send-command process (format "MAIL FROM:%s@%s" (user-login-name) (smtpmail-fqdn))) | |
15453
ad4f0ac5e7ef
(smtpmail-via-smtp): Bracket names in FROM and RCPT TO commands.
Richard M. Stallman <rms@gnu.org>
parents:
15452
diff
changeset
|
270 (smtpmail-send-command process (format "MAIL FROM: <%s>" user-mail-address)) |
15345 | 271 |
272 (if (or (null (car (setq response-code (smtpmail-read-response process)))) | |
273 (not (integerp (car response-code))) | |
274 (>= (car response-code) 400)) | |
275 (throw 'done nil) | |
276 ) | |
277 | |
278 ;; RCPT TO: <recipient> | |
15346
4cd6ff2384dc
(smtpmail-send-it): Fix error messages.
Richard M. Stallman <rms@gnu.org>
parents:
15345
diff
changeset
|
279 (let ((n 0)) |
4cd6ff2384dc
(smtpmail-send-it): Fix error messages.
Richard M. Stallman <rms@gnu.org>
parents:
15345
diff
changeset
|
280 (while (not (null (nth n recipient))) |
15453
ad4f0ac5e7ef
(smtpmail-via-smtp): Bracket names in FROM and RCPT TO commands.
Richard M. Stallman <rms@gnu.org>
parents:
15452
diff
changeset
|
281 (smtpmail-send-command process (format "RCPT TO: <%s>" (nth n recipient))) |
15346
4cd6ff2384dc
(smtpmail-send-it): Fix error messages.
Richard M. Stallman <rms@gnu.org>
parents:
15345
diff
changeset
|
282 (setq n (1+ n)) |
15345 | 283 |
15346
4cd6ff2384dc
(smtpmail-send-it): Fix error messages.
Richard M. Stallman <rms@gnu.org>
parents:
15345
diff
changeset
|
284 (if (or (null (car (setq response-code (smtpmail-read-response process)))) |
4cd6ff2384dc
(smtpmail-send-it): Fix error messages.
Richard M. Stallman <rms@gnu.org>
parents:
15345
diff
changeset
|
285 (not (integerp (car response-code))) |
4cd6ff2384dc
(smtpmail-send-it): Fix error messages.
Richard M. Stallman <rms@gnu.org>
parents:
15345
diff
changeset
|
286 (>= (car response-code) 400)) |
4cd6ff2384dc
(smtpmail-send-it): Fix error messages.
Richard M. Stallman <rms@gnu.org>
parents:
15345
diff
changeset
|
287 (throw 'done nil) |
4cd6ff2384dc
(smtpmail-send-it): Fix error messages.
Richard M. Stallman <rms@gnu.org>
parents:
15345
diff
changeset
|
288 ) |
4cd6ff2384dc
(smtpmail-send-it): Fix error messages.
Richard M. Stallman <rms@gnu.org>
parents:
15345
diff
changeset
|
289 )) |
15345 | 290 |
291 ;; DATA | |
292 (smtpmail-send-command process "DATA") | |
293 | |
294 (if (or (null (car (setq response-code (smtpmail-read-response process)))) | |
295 (not (integerp (car response-code))) | |
296 (>= (car response-code) 400)) | |
297 (throw 'done nil) | |
298 ) | |
299 | |
300 ;; Mail contents | |
301 (smtpmail-send-data process smtpmail-text-buffer) | |
302 | |
303 ;;DATA end "." | |
304 (smtpmail-send-command process ".") | |
305 | |
306 (if (or (null (car (setq response-code (smtpmail-read-response process)))) | |
307 (not (integerp (car response-code))) | |
308 (>= (car response-code) 400)) | |
309 (throw 'done nil) | |
310 ) | |
311 | |
312 ;;QUIT | |
313 ; (smtpmail-send-command process "QUIT") | |
314 ; (and (null (car (smtpmail-read-response process))) | |
315 ; (throw 'done nil)) | |
316 t )) | |
317 (if process | |
318 (save-excursion | |
319 (set-buffer (process-buffer process)) | |
320 (smtpmail-send-command process "QUIT") | |
321 (smtpmail-read-response process) | |
322 | |
323 ; (if (or (null (car (setq response-code (smtpmail-read-response process)))) | |
324 ; (not (integerp (car response-code))) | |
325 ; (>= (car response-code) 400)) | |
326 ; (throw 'done nil) | |
327 ; ) | |
328 (delete-process process)))))) | |
329 | |
330 | |
331 (defun smtpmail-process-filter (process output) | |
332 (save-excursion | |
333 (set-buffer (process-buffer process)) | |
334 (goto-char (point-max)) | |
335 (insert output))) | |
336 | |
337 (defun smtpmail-read-response (process) | |
338 (let ((case-fold-search nil) | |
339 (response-string nil) | |
340 (response-continue t) | |
341 (return-value '(nil "")) | |
342 match-end) | |
343 | |
344 ; (setq response-string nil) | |
345 ; (setq response-continue t) | |
346 ; (setq return-value '(nil "")) | |
347 | |
348 (while response-continue | |
15454
85313b347ed9
(smtpmail-read-response): Goto smtpmail-read-point
Richard M. Stallman <rms@gnu.org>
parents:
15453
diff
changeset
|
349 (goto-char smtpmail-read-point) |
15345 | 350 (while (not (search-forward "\r\n" nil t)) |
351 (accept-process-output process) | |
352 (goto-char smtpmail-read-point)) | |
353 | |
354 (setq match-end (point)) | |
355 (if (null response-string) | |
356 (setq response-string | |
357 (buffer-substring smtpmail-read-point (- match-end 2)))) | |
358 | |
359 (goto-char smtpmail-read-point) | |
360 (if (looking-at "[0-9]+ ") | |
361 (progn (setq response-continue nil) | |
362 ; (setq return-value response-string) | |
363 | |
364 (if smtpmail-debug-info | |
365 (message response-string)) | |
366 | |
367 (setq smtpmail-read-point match-end) | |
368 (setq return-value | |
369 (cons (string-to-int | |
370 (buffer-substring (match-beginning 0) (match-end 0))) | |
371 response-string))) | |
372 | |
373 (if (looking-at "[0-9]+-") | |
374 (progn (setq smtpmail-read-point match-end) | |
375 (setq response-continue t)) | |
376 (progn | |
377 (setq smtpmail-read-point match-end) | |
378 (setq response-continue nil) | |
379 (setq return-value | |
380 (cons nil response-string)) | |
381 ) | |
382 ))) | |
383 (setq smtpmail-read-point match-end) | |
384 return-value)) | |
385 | |
386 | |
387 (defun smtpmail-send-command (process command) | |
388 (goto-char (point-max)) | |
389 (if (= (aref command 0) ?P) | |
390 (insert "PASS <omitted>\r\n") | |
391 (insert command "\r\n")) | |
392 (setq smtpmail-read-point (point)) | |
393 (process-send-string process command) | |
394 (process-send-string process "\r\n")) | |
395 | |
396 (defun smtpmail-send-data-1 (process data) | |
397 (goto-char (point-max)) | |
398 | |
399 (if (not (null smtpmail-code-conv-from)) | |
400 (setq data (code-convert-string data smtpmail-code-conv-from *internal*))) | |
401 | |
402 (if smtpmail-debug-info | |
403 (insert data "\r\n")) | |
404 | |
405 (setq smtpmail-read-point (point)) | |
406 (process-send-string process data) | |
407 ;; . -> .. | |
408 (if (string-equal data ".") | |
409 (process-send-string process ".")) | |
410 (process-send-string process "\r\n") | |
411 ) | |
412 | |
413 (defun smtpmail-send-data (process buffer) | |
414 (let | |
415 ((data-continue t) | |
416 (sending-data nil) | |
417 this-line | |
418 this-line-end) | |
419 | |
420 (save-excursion | |
421 (set-buffer buffer) | |
422 (goto-char (point-min))) | |
423 | |
424 (while data-continue | |
425 (save-excursion | |
426 (set-buffer buffer) | |
427 (beginning-of-line) | |
428 (setq this-line (point)) | |
429 (end-of-line) | |
430 (setq this-line-end (point)) | |
431 (setq sending-data nil) | |
432 (setq sending-data (buffer-substring this-line this-line-end)) | |
433 (if (/= (forward-line 1) 0) | |
434 (setq data-continue nil))) | |
435 | |
436 (smtpmail-send-data-1 process sending-data) | |
437 ) | |
438 ) | |
439 ) | |
440 | |
441 | |
442 (defun smtpmail-deduce-address-list (smtpmail-text-buffer header-start header-end) | |
443 "Get address list suitable for smtp RCPT TO: <address>." | |
444 (require 'mail-utils) ;; pick up mail-strip-quoted-names | |
445 (let | |
446 ((case-fold-search t) | |
447 (simple-address-list "") | |
448 this-line | |
449 this-line-end) | |
450 | |
451 (unwind-protect | |
452 (save-excursion | |
453 ;; | |
454 (set-buffer smtpmail-address-buffer) (erase-buffer) | |
455 (insert-buffer-substring smtpmail-text-buffer header-start header-end) | |
456 (goto-char (point-min)) | |
457 (while (re-search-forward "^\\(TO:\\|CC:\\|BCC:\\)" header-end t) | |
458 (replace-match "") | |
459 (setq this-line (match-beginning 0)) | |
460 (forward-line 1) | |
461 ;; get any continuation lines | |
462 (while (and (looking-at "^[ \t]+") (< (point) header-end)) | |
463 (forward-line 1)) | |
464 (setq this-line-end (point-marker)) | |
465 (setq simple-address-list | |
466 (concat simple-address-list " " | |
467 (mail-strip-quoted-names (buffer-substring this-line this-line-end)))) | |
468 ) | |
469 (erase-buffer) | |
470 (insert-string " ") | |
471 (insert-string simple-address-list) | |
472 (insert-string "\n") | |
473 (subst-char-in-region (point-min) (point-max) 10 ? t);; newline --> blank | |
474 (subst-char-in-region (point-min) (point-max) ?, ? t);; comma --> blank | |
475 (subst-char-in-region (point-min) (point-max) 9 ? t);; tab --> blank | |
476 | |
477 (goto-char (point-min)) | |
478 ;; tidyness in case hook is not robust when it looks at this | |
479 (while (re-search-forward "[ \t]+" header-end t) (replace-match " ")) | |
480 | |
481 (goto-char (point-min)) | |
15346
4cd6ff2384dc
(smtpmail-send-it): Fix error messages.
Richard M. Stallman <rms@gnu.org>
parents:
15345
diff
changeset
|
482 (let (recipient-address-list) |
15451
89c1e7fe879a
(smtpmail-smtp-service): Use port 25 as default.
Richard M. Stallman <rms@gnu.org>
parents:
15372
diff
changeset
|
483 (while (re-search-forward " \\([^ ]+\\) " (point-max) t) |
15346
4cd6ff2384dc
(smtpmail-send-it): Fix error messages.
Richard M. Stallman <rms@gnu.org>
parents:
15345
diff
changeset
|
484 (backward-char 1) |
15451
89c1e7fe879a
(smtpmail-smtp-service): Use port 25 as default.
Richard M. Stallman <rms@gnu.org>
parents:
15372
diff
changeset
|
485 (setq recipient-address-list (cons (buffer-substring (match-beginning 1) (match-end 1)) |
89c1e7fe879a
(smtpmail-smtp-service): Use port 25 as default.
Richard M. Stallman <rms@gnu.org>
parents:
15372
diff
changeset
|
486 recipient-address-list)) |
15346
4cd6ff2384dc
(smtpmail-send-it): Fix error messages.
Richard M. Stallman <rms@gnu.org>
parents:
15345
diff
changeset
|
487 ) |
4cd6ff2384dc
(smtpmail-send-it): Fix error messages.
Richard M. Stallman <rms@gnu.org>
parents:
15345
diff
changeset
|
488 (setq smtpmail-recipient-address-list recipient-address-list)) |
15345 | 489 |
490 ) | |
491 ) | |
492 ) | |
493 ) | |
494 | |
495 | |
496 (defun smtpmail-do-bcc (header-end) | |
497 "Delete BCC: and their continuation lines from the header area. | |
498 There may be multiple BCC: lines, and each may have arbitrarily | |
499 many continuation lines." | |
500 (let ((case-fold-search t)) | |
501 (save-excursion (goto-char (point-min)) | |
502 ;; iterate over all BCC: lines | |
503 (while (re-search-forward "^BCC:" header-end t) | |
504 (delete-region (match-beginning 0) (progn (forward-line 1) (point))) | |
505 ;; get rid of any continuation lines | |
506 (while (and (looking-at "^[ \t].*\n") (< (point) header-end)) | |
507 (replace-match "")) | |
508 ) | |
509 ) ;; save-excursion | |
510 ) ;; let | |
511 ) | |
512 | |
513 | |
514 | |
515 (provide 'smtpmail) | |
516 | |
517 ;; smtpmail.el ends here |