Mercurial > emacs
annotate lisp/mail/smtpmail.el @ 19011:96c53acede23
Comment change.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 27 Jul 1997 20:04:29 +0000 |
parents | 54cf1b43247b |
children | 7077ba8a265b |
rev | line source |
---|---|
17517 | 1 ;;; smtpmail.el --- simple SMTP protocol (RFC 821) for sending mail |
15345 | 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> |
18092
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
7 ;; ESMTP support: Simon Leinen <simon@switch.ch> |
15345 | 8 ;; Keywords: mail |
9 | |
10 ;; This file is part of GNU Emacs. | |
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 the | |
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
25 ;; Boston, MA 02111-1307, USA. | |
26 | |
27 ;;; Commentary: | |
28 | |
29 ;; Send Mail to smtp host from smtpmail temp buffer. | |
30 | |
31 ;; Please add these lines in your .emacs(_emacs). | |
32 ;; | |
33 ;;(setq send-mail-function 'smtpmail-send-it) | |
34 ;;(setq smtpmail-default-smtp-server "YOUR SMTP HOST") | |
35 ;;(setq smtpmail-smtp-service "smtp") | |
36 ;;(setq smtpmail-local-domain "YOUR DOMAIN NAME") | |
37 ;;(setq smtpmail-debug-info t) | |
38 ;;(load-library "smtpmail") | |
39 ;;(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
|
40 ;;(setq user-full-name "YOUR NAME HERE") |
15345 | 41 |
18094 | 42 ;; To queue mail, set smtpmail-queue-mail to t and use |
43 ;; smtpmail-send-queued-mail to send. | |
44 | |
45 | |
15345 | 46 ;;; Code: |
47 | |
48 (require 'sendmail) | |
18094 | 49 (require 'time-stamp) |
15345 | 50 |
51 ;;; | |
17436
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16907
diff
changeset
|
52 (defgroup smtpmail nil |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16907
diff
changeset
|
53 "SMTP protocol for sending mail." |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16907
diff
changeset
|
54 :group 'mail) |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16907
diff
changeset
|
55 |
15345 | 56 |
17436
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16907
diff
changeset
|
57 (defcustom smtpmail-default-smtp-server nil |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16907
diff
changeset
|
58 "*Specify default SMTP server." |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16907
diff
changeset
|
59 :type '(choice (const nil) string) |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16907
diff
changeset
|
60 :group 'smtpmail) |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16907
diff
changeset
|
61 |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16907
diff
changeset
|
62 (defcustom smtpmail-smtp-server |
15451
89c1e7fe879a
(smtpmail-smtp-service): Use port 25 as default.
Richard M. Stallman <rms@gnu.org>
parents:
15372
diff
changeset
|
63 (or (getenv "SMTPSERVER") smtpmail-default-smtp-server) |
17436
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16907
diff
changeset
|
64 "*The name of the host running SMTP server." |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16907
diff
changeset
|
65 :type '(choice (const nil) string) |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16907
diff
changeset
|
66 :group 'smtpmail) |
15345 | 67 |
17436
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16907
diff
changeset
|
68 (defcustom smtpmail-smtp-service 25 |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16907
diff
changeset
|
69 "*SMTP service port number. smtp or 25 ." |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16907
diff
changeset
|
70 :type 'integer |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16907
diff
changeset
|
71 :group 'smtpmail) |
15345 | 72 |
17436
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16907
diff
changeset
|
73 (defcustom smtpmail-local-domain nil |
15345 | 74 "*Local domain name without a host name. |
75 If the function (system-name) returns the full internet address, | |
17436
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16907
diff
changeset
|
76 don't define this value." |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16907
diff
changeset
|
77 :type '(choice (const nil) string) |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16907
diff
changeset
|
78 :group 'smtpmail) |
15345 | 79 |
17436
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16907
diff
changeset
|
80 (defcustom smtpmail-debug-info nil |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16907
diff
changeset
|
81 "*smtpmail debug info printout. messages and process buffer." |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16907
diff
changeset
|
82 :type 'boolean |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16907
diff
changeset
|
83 :group 'smtpmail) |
15345 | 84 |
17436
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16907
diff
changeset
|
85 (defcustom smtpmail-code-conv-from nil ;; *junet* |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16907
diff
changeset
|
86 "*smtpmail code convert from this code to *internal*..for tiny-mime.." |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16907
diff
changeset
|
87 :type 'boolean |
2a9fdbfcb993
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16907
diff
changeset
|
88 :group 'smtpmail) |
15345 | 89 |
18094 | 90 (defcustom smtpmail-queue-mail nil |
91 "*Specify if mail is queued (if t) or sent immediately (if nil). | |
92 If queued, it is stored in the directory `smtpmail-queue-dir' | |
93 and sent with `smtpmail-send-queued-mail'." | |
94 :type 'boolean | |
95 :group 'smtpmail) | |
96 | |
97 (defcustom smtpmail-queue-dir "~/Mail/queued-mail/" | |
98 "*Directory where `smtpmail.el' stores queued mail." | |
99 :type 'directory | |
100 :group 'smtpmail) | |
101 | |
102 (defvar smtpmail-queue-index-file "index" | |
103 "File name of queued mail index, | |
104 This is relative to `smtpmail-queue-dir'.") | |
105 | |
106 (defvar smtpmail-queue-index (concat smtpmail-queue-dir | |
107 smtpmail-queue-index-file)) | |
108 | |
15345 | 109 ;;; |
110 ;;; | |
111 ;;; | |
112 | |
113 (defun smtpmail-send-it () | |
15451
89c1e7fe879a
(smtpmail-smtp-service): Use port 25 as default.
Richard M. Stallman <rms@gnu.org>
parents:
15372
diff
changeset
|
114 (require 'mail-utils) |
15345 | 115 (let ((errbuf (if mail-interactive |
116 (generate-new-buffer " smtpmail errors") | |
117 0)) | |
118 (tembuf (generate-new-buffer " smtpmail temp")) | |
119 (case-fold-search nil) | |
120 resend-to-addresses | |
121 delimline | |
122 (mailbuf (current-buffer))) | |
123 (unwind-protect | |
124 (save-excursion | |
125 (set-buffer tembuf) | |
126 (erase-buffer) | |
127 (insert-buffer-substring mailbuf) | |
128 (goto-char (point-max)) | |
129 ;; require one newline at the end. | |
130 (or (= (preceding-char) ?\n) | |
131 (insert ?\n)) | |
132 ;; Change header-delimiter to be what sendmail expects. | |
133 (goto-char (point-min)) | |
134 (re-search-forward | |
135 (concat "^" (regexp-quote mail-header-separator) "\n")) | |
136 (replace-match "\n") | |
137 (backward-char 1) | |
138 (setq delimline (point-marker)) | |
15451
89c1e7fe879a
(smtpmail-smtp-service): Use port 25 as default.
Richard M. Stallman <rms@gnu.org>
parents:
15372
diff
changeset
|
139 ;; (sendmail-synch-aliases) |
15345 | 140 (if mail-aliases |
141 (expand-mail-aliases (point-min) delimline)) | |
142 (goto-char (point-min)) | |
143 ;; ignore any blank lines in the header | |
144 (while (and (re-search-forward "\n\n\n*" delimline t) | |
145 (< (point) delimline)) | |
146 (replace-match "\n")) | |
147 (let ((case-fold-search t)) | |
148 (goto-char (point-min)) | |
149 (goto-char (point-min)) | |
150 (while (re-search-forward "^Resent-to:" delimline t) | |
151 (setq resend-to-addresses | |
152 (save-restriction | |
153 (narrow-to-region (point) | |
154 (save-excursion | |
155 (end-of-line) | |
156 (point))) | |
157 (append (mail-parse-comma-list) | |
158 resend-to-addresses)))) | |
159 ;;; Apparently this causes a duplicate Sender. | |
160 ;;; ;; If the From is different than current user, insert Sender. | |
161 ;;; (goto-char (point-min)) | |
162 ;;; (and (re-search-forward "^From:" delimline t) | |
163 ;;; (progn | |
164 ;;; (require 'mail-utils) | |
165 ;;; (not (string-equal | |
166 ;;; (mail-strip-quoted-names | |
167 ;;; (save-restriction | |
168 ;;; (narrow-to-region (point-min) delimline) | |
169 ;;; (mail-fetch-field "From"))) | |
170 ;;; (user-login-name)))) | |
171 ;;; (progn | |
172 ;;; (forward-line 1) | |
173 ;;; (insert "Sender: " (user-login-name) "\n"))) | |
174 ;; Don't send out a blank subject line | |
175 (goto-char (point-min)) | |
176 (if (re-search-forward "^Subject:[ \t]*\n" delimline t) | |
177 (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
|
178 ;; 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
|
179 ;; 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
|
180 (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
|
181 (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
|
182 (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
|
183 (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
|
184 (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
|
185 (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
|
186 (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
|
187 (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
|
188 (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
|
189 ;; 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
|
190 ;; 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
|
191 (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
|
192 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
|
193 (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
|
194 ;; 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
|
195 (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
|
196 (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
|
197 (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
|
198 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
|
199 (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
|
200 (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
|
201 (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
|
202 ((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
|
203 (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
|
204 (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
|
205 (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
|
206 (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
|
207 (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
|
208 ;; 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
|
209 ;; 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
|
210 ;; 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
|
211 (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
|
212 (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
|
213 ;; ... 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
|
214 ;; 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
|
215 (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
|
216 (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
|
217 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)" |
6f41e17b3452
(smtpmail-send-it): Don't handle FCC fields until after determining FROM field.
Richard M. Stallman <rms@gnu.org>
parents:
15451
diff
changeset
|
218 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
|
219 (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
|
220 (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
|
221 (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
|
222 ((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
|
223 (insert "From: " login "\n"))))) |
15345 | 224 ;; Insert an extra newline if we need it to work around |
225 ;; Sun's bug that swallows newlines. | |
226 (goto-char (1+ delimline)) | |
227 (if (eval mail-mailer-swallows-blank-line) | |
228 (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
|
229 ;; 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
|
230 (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
|
231 (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
|
232 (mail-do-fcc delimline)) |
15345 | 233 (if mail-interactive |
234 (save-excursion | |
235 (set-buffer errbuf) | |
236 (erase-buffer)))) | |
237 ;; | |
238 ;; | |
239 ;; | |
240 (setq smtpmail-address-buffer (generate-new-buffer "*smtp-mail*")) | |
241 (setq smtpmail-recipient-address-list | |
15595
0d4a7f47f31d
(smtpmail-send-it): Ignore `To:' if there is a `Resent-to':.
Miles Bader <miles@gnu.org>
parents:
15454
diff
changeset
|
242 (or resend-to-addresses |
0d4a7f47f31d
(smtpmail-send-it): Ignore `To:' if there is a `Resent-to':.
Miles Bader <miles@gnu.org>
parents:
15454
diff
changeset
|
243 (smtpmail-deduce-address-list tembuf (point-min) delimline))) |
15345 | 244 (kill-buffer smtpmail-address-buffer) |
18094 | 245 |
15345 | 246 (smtpmail-do-bcc delimline) |
18094 | 247 ; Send or queue |
248 (if (not smtpmail-queue-mail) | |
249 (if (not (null smtpmail-recipient-address-list)) | |
250 (if (not (smtpmail-via-smtp | |
251 smtpmail-recipient-address-list tembuf)) | |
252 (error "Sending failed; SMTP protocol error")) | |
253 (error "Sending failed; no recipients")) | |
254 (let* ((file-data (concat | |
255 smtpmail-queue-dir | |
256 (time-stamp-strftime | |
257 "%02y%02m%02d-%02H%02M%02S"))) | |
258 (file-elisp (concat file-data ".el")) | |
259 (buffer-data (create-file-buffer file-data)) | |
260 (buffer-elisp (create-file-buffer file-elisp)) | |
261 (buffer-scratch "*queue-mail*")) | |
262 (save-excursion | |
263 (set-buffer buffer-data) | |
264 (erase-buffer) | |
265 (insert-buffer tembuf) | |
266 (write-file file-data) | |
267 (set-buffer buffer-elisp) | |
268 (erase-buffer) | |
269 (insert (concat | |
270 "(setq smtpmail-recipient-address-list '" | |
271 (prin1-to-string smtpmail-recipient-address-list) | |
272 ")\n")) | |
273 (write-file file-elisp) | |
274 (set-buffer (generate-new-buffer buffer-scratch)) | |
275 (insert (concat file-data "\n")) | |
276 (append-to-file (point-min) | |
277 (point-max) | |
278 smtpmail-queue-index) | |
279 ) | |
280 (kill-buffer buffer-scratch) | |
281 (kill-buffer buffer-data) | |
282 (kill-buffer buffer-elisp)))) | |
15345 | 283 (kill-buffer tembuf) |
284 (if (bufferp errbuf) | |
285 (kill-buffer errbuf))))) | |
286 | |
18094 | 287 (defun smtpmail-send-queued-mail () |
288 "Send mail that was queued as a result of setting `smtpmail-queue-mail'." | |
289 (interactive) | |
290 ;;; Get index, get first mail, send it, get second mail, etc... | |
291 (let ((buffer-index (find-file-noselect smtpmail-queue-index)) | |
292 (file-msg "") | |
293 (tembuf nil)) | |
294 (save-excursion | |
295 (set-buffer buffer-index) | |
296 (beginning-of-buffer) | |
297 (while (not (eobp)) | |
298 (setq file-msg (buffer-substring (point) (save-excursion | |
299 (end-of-line) | |
300 (point)))) | |
301 (load file-msg) | |
302 (setq tembuf (find-file-noselect file-msg)) | |
303 (if (not (null smtpmail-recipient-address-list)) | |
304 (if (not (smtpmail-via-smtp smtpmail-recipient-address-list | |
305 tembuf)) | |
306 (error "Sending failed; SMTP protocol error")) | |
307 (error "Sending failed; no recipients")) | |
308 (delete-file file-msg) | |
309 (delete-file (concat file-msg ".el")) | |
310 (kill-buffer tembuf) | |
311 (kill-line 1)) | |
312 (set-buffer buffer-index) | |
313 (save-buffer smtpmail-queue-index) | |
314 (kill-buffer buffer-index) | |
315 ))) | |
15345 | 316 |
317 ;(defun smtpmail-via-smtp (host,port,sender,destination,smtpmail-text-buffer) | |
318 | |
319 (defun smtpmail-fqdn () | |
320 (if smtpmail-local-domain | |
321 (concat (system-name) "." smtpmail-local-domain) | |
322 (system-name))) | |
323 | |
324 (defun smtpmail-via-smtp (recipient smtpmail-text-buffer) | |
325 (let ((process nil) | |
15346
4cd6ff2384dc
(smtpmail-send-it): Fix error messages.
Richard M. Stallman <rms@gnu.org>
parents:
15345
diff
changeset
|
326 (host smtpmail-smtp-server) |
4cd6ff2384dc
(smtpmail-send-it): Fix error messages.
Richard M. Stallman <rms@gnu.org>
parents:
15345
diff
changeset
|
327 (port smtpmail-smtp-service) |
15345 | 328 response-code |
15346
4cd6ff2384dc
(smtpmail-send-it): Fix error messages.
Richard M. Stallman <rms@gnu.org>
parents:
15345
diff
changeset
|
329 greeting |
18092
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
330 process-buffer |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
331 (supported-extensions '())) |
15345 | 332 (unwind-protect |
333 (catch 'done | |
334 ;; get or create the trace buffer | |
335 (setq process-buffer | |
336 (get-buffer-create (format "*trace of SMTP session to %s*" host))) | |
337 | |
338 ;; clear the trace buffer of old output | |
339 (save-excursion | |
340 (set-buffer process-buffer) | |
341 (erase-buffer)) | |
342 | |
343 ;; open the connection to the server | |
344 (setq process (open-network-stream "SMTP" process-buffer host port)) | |
345 (and (null process) (throw 'done nil)) | |
346 | |
347 ;; set the send-filter | |
348 (set-process-filter process 'smtpmail-process-filter) | |
349 | |
350 (save-excursion | |
351 (set-buffer process-buffer) | |
352 (make-local-variable 'smtpmail-read-point) | |
353 (setq smtpmail-read-point (point-min)) | |
354 | |
355 | |
356 (if (or (null (car (setq greeting (smtpmail-read-response process)))) | |
357 (not (integerp (car greeting))) | |
358 (>= (car greeting) 400)) | |
359 (throw 'done nil) | |
360 ) | |
361 | |
18092
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
362 ;; EHLO |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
363 (smtpmail-send-command process (format "EHLO %s" (smtpmail-fqdn))) |
15345 | 364 |
365 (if (or (null (car (setq response-code (smtpmail-read-response process)))) | |
366 (not (integerp (car response-code))) | |
367 (>= (car response-code) 400)) | |
18092
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
368 (progn |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
369 ;; HELO |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
370 (smtpmail-send-command process (format "HELO %s" (smtpmail-fqdn))) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
371 |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
372 (if (or (null (car (setq response-code (smtpmail-read-response process)))) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
373 (not (integerp (car response-code))) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
374 (>= (car response-code) 400)) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
375 (throw 'done nil))) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
376 (let ((extension-lines (cdr (cdr response-code)))) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
377 (while extension-lines |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
378 (let ((name (intern (downcase (substring (car extension-lines) 4))))) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
379 (and name |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
380 (cond ((memq name '(verb xvrb 8bitmime onex xone |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
381 expn size dsn etrn |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
382 help xusr)) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
383 (setq supported-extensions |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
384 (cons name supported-extensions))) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
385 (t (message "unknown extension %s" |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
386 name))))) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
387 (setq extension-lines (cdr extension-lines))))) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
388 |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
389 (if (or (member 'onex supported-extensions) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
390 (member 'xone supported-extensions)) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
391 (progn |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
392 (smtpmail-send-command process (format "ONEX")) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
393 (if (or (null (car (setq response-code (smtpmail-read-response process)))) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
394 (not (integerp (car response-code))) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
395 (>= (car response-code) 400)) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
396 (throw 'done nil)))) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
397 |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
398 (if (and smtpmail-debug-info |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
399 (or (member 'verb supported-extensions) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
400 (member 'xvrb supported-extensions))) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
401 (progn |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
402 (smtpmail-send-command process (format "VERB")) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
403 (if (or (null (car (setq response-code (smtpmail-read-response process)))) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
404 (not (integerp (car response-code))) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
405 (>= (car response-code) 400)) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
406 (throw 'done nil)))) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
407 |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
408 (if (member 'xusr supported-extensions) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
409 (progn |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
410 (smtpmail-send-command process (format "XUSR")) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
411 (if (or (null (car (setq response-code (smtpmail-read-response process)))) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
412 (not (integerp (car response-code))) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
413 (>= (car response-code) 400)) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
414 (throw 'done nil)))) |
15345 | 415 |
416 ;; MAIL FROM: <sender> | |
18092
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
417 (let ((size-part |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
418 (if (member 'size supported-extensions) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
419 (format " SIZE=%d" |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
420 (save-excursion |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
421 (set-buffer smtpmail-text-buffer) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
422 ;; size estimate: |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
423 (+ (- (point-max) (point-min)) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
424 ;; Add one byte for each change-of-line |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
425 ;; because or CR-LF representation: |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
426 (count-lines (point-min) (point-max)) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
427 ;; For some reason, an empty line is |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
428 ;; added to the message. Maybe this |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
429 ;; is a bug, but it can't hurt to add |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
430 ;; those two bytes anyway: |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
431 2))) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
432 "")) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
433 (body-part |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
434 (if (member '8bitmime supported-extensions) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
435 ;; FIXME: |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
436 ;; Code should be added here that transforms |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
437 ;; the contents of the message buffer into |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
438 ;; something the receiving SMTP can handle. |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
439 ;; For a receiver that supports 8BITMIME, this |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
440 ;; may mean converting BINARY to BASE64, or |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
441 ;; adding Content-Transfer-Encoding and the |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
442 ;; other MIME headers. The code should also |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
443 ;; return an indication of what encoding the |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
444 ;; message buffer is now, i.e. ASCII or |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
445 ;; 8BITMIME. |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
446 (if nil |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
447 " BODY=8BITMIME" |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
448 "") |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
449 ""))) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
450 ; (smtpmail-send-command process (format "MAIL FROM:%s@%s" (user-login-name) (smtpmail-fqdn))) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
451 (smtpmail-send-command process (format "MAIL FROM: <%s>%s%s" |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
452 user-mail-address |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
453 size-part |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
454 body-part)) |
15345 | 455 |
18092
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
456 (if (or (null (car (setq response-code (smtpmail-read-response process)))) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
457 (not (integerp (car response-code))) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
458 (>= (car response-code) 400)) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
459 (throw 'done nil) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
460 )) |
15345 | 461 |
462 ;; RCPT TO: <recipient> | |
15346
4cd6ff2384dc
(smtpmail-send-it): Fix error messages.
Richard M. Stallman <rms@gnu.org>
parents:
15345
diff
changeset
|
463 (let ((n 0)) |
4cd6ff2384dc
(smtpmail-send-it): Fix error messages.
Richard M. Stallman <rms@gnu.org>
parents:
15345
diff
changeset
|
464 (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
|
465 (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
|
466 (setq n (1+ n)) |
15345 | 467 |
18092
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
468 (setq response-code (smtpmail-read-response process)) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
469 (if (or (null (car response-code)) |
15346
4cd6ff2384dc
(smtpmail-send-it): Fix error messages.
Richard M. Stallman <rms@gnu.org>
parents:
15345
diff
changeset
|
470 (not (integerp (car response-code))) |
4cd6ff2384dc
(smtpmail-send-it): Fix error messages.
Richard M. Stallman <rms@gnu.org>
parents:
15345
diff
changeset
|
471 (>= (car response-code) 400)) |
4cd6ff2384dc
(smtpmail-send-it): Fix error messages.
Richard M. Stallman <rms@gnu.org>
parents:
15345
diff
changeset
|
472 (throw 'done nil) |
4cd6ff2384dc
(smtpmail-send-it): Fix error messages.
Richard M. Stallman <rms@gnu.org>
parents:
15345
diff
changeset
|
473 ) |
4cd6ff2384dc
(smtpmail-send-it): Fix error messages.
Richard M. Stallman <rms@gnu.org>
parents:
15345
diff
changeset
|
474 )) |
15345 | 475 |
476 ;; DATA | |
477 (smtpmail-send-command process "DATA") | |
478 | |
479 (if (or (null (car (setq response-code (smtpmail-read-response process)))) | |
480 (not (integerp (car response-code))) | |
481 (>= (car response-code) 400)) | |
482 (throw 'done nil) | |
483 ) | |
484 | |
485 ;; Mail contents | |
486 (smtpmail-send-data process smtpmail-text-buffer) | |
487 | |
488 ;;DATA end "." | |
489 (smtpmail-send-command process ".") | |
490 | |
491 (if (or (null (car (setq response-code (smtpmail-read-response process)))) | |
492 (not (integerp (car response-code))) | |
493 (>= (car response-code) 400)) | |
494 (throw 'done nil) | |
495 ) | |
496 | |
497 ;;QUIT | |
498 ; (smtpmail-send-command process "QUIT") | |
499 ; (and (null (car (smtpmail-read-response process))) | |
500 ; (throw 'done nil)) | |
501 t )) | |
502 (if process | |
503 (save-excursion | |
504 (set-buffer (process-buffer process)) | |
505 (smtpmail-send-command process "QUIT") | |
506 (smtpmail-read-response process) | |
507 | |
508 ; (if (or (null (car (setq response-code (smtpmail-read-response process)))) | |
509 ; (not (integerp (car response-code))) | |
510 ; (>= (car response-code) 400)) | |
511 ; (throw 'done nil) | |
512 ; ) | |
513 (delete-process process)))))) | |
514 | |
515 | |
516 (defun smtpmail-process-filter (process output) | |
517 (save-excursion | |
518 (set-buffer (process-buffer process)) | |
519 (goto-char (point-max)) | |
520 (insert output))) | |
521 | |
522 (defun smtpmail-read-response (process) | |
523 (let ((case-fold-search nil) | |
18092
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
524 (response-strings nil) |
15345 | 525 (response-continue t) |
18092
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
526 (return-value '(nil ())) |
15345 | 527 match-end) |
528 | |
529 (while response-continue | |
15454
85313b347ed9
(smtpmail-read-response): Goto smtpmail-read-point
Richard M. Stallman <rms@gnu.org>
parents:
15453
diff
changeset
|
530 (goto-char smtpmail-read-point) |
15345 | 531 (while (not (search-forward "\r\n" nil t)) |
532 (accept-process-output process) | |
533 (goto-char smtpmail-read-point)) | |
534 | |
535 (setq match-end (point)) | |
18092
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
536 (setq response-strings |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
537 (cons (buffer-substring smtpmail-read-point (- match-end 2)) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
538 response-strings)) |
15345 | 539 |
540 (goto-char smtpmail-read-point) | |
541 (if (looking-at "[0-9]+ ") | |
18092
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
542 (let ((begin (match-beginning 0)) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
543 (end (match-end 0))) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
544 (if smtpmail-debug-info |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
545 (message "%s" (car response-strings))) |
15345 | 546 |
18092
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
547 (setq smtpmail-read-point match-end) |
15345 | 548 |
18092
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
549 ;; ignore lines that start with "0" |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
550 (if (looking-at "0[0-9]+ ") |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
551 nil |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
552 (setq response-continue nil) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
553 (setq return-value |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
554 (cons (string-to-int |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
555 (buffer-substring begin end)) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
556 (nreverse response-strings))))) |
15345 | 557 |
558 (if (looking-at "[0-9]+-") | |
18092
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
559 (progn (if smtpmail-debug-info |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
560 (message "%s" (car response-strings))) |
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
561 (setq smtpmail-read-point match-end) |
15345 | 562 (setq response-continue t)) |
563 (progn | |
564 (setq smtpmail-read-point match-end) | |
565 (setq response-continue nil) | |
566 (setq return-value | |
18092
8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
Richard M. Stallman <rms@gnu.org>
parents:
17517
diff
changeset
|
567 (cons nil (nreverse response-strings))) |
15345 | 568 ) |
569 ))) | |
570 (setq smtpmail-read-point match-end) | |
571 return-value)) | |
572 | |
573 | |
574 (defun smtpmail-send-command (process command) | |
575 (goto-char (point-max)) | |
576 (if (= (aref command 0) ?P) | |
577 (insert "PASS <omitted>\r\n") | |
578 (insert command "\r\n")) | |
579 (setq smtpmail-read-point (point)) | |
580 (process-send-string process command) | |
581 (process-send-string process "\r\n")) | |
582 | |
583 (defun smtpmail-send-data-1 (process data) | |
584 (goto-char (point-max)) | |
585 | |
586 (if (not (null smtpmail-code-conv-from)) | |
587 (setq data (code-convert-string data smtpmail-code-conv-from *internal*))) | |
588 | |
589 (if smtpmail-debug-info | |
590 (insert data "\r\n")) | |
591 | |
592 (setq smtpmail-read-point (point)) | |
15676
46d74bda4351
(smtpmail-send-data-1): Escape "." at the start of
Karl Heuer <kwzh@gnu.org>
parents:
15648
diff
changeset
|
593 ;; Escape "." at start of a line |
46d74bda4351
(smtpmail-send-data-1): Escape "." at the start of
Karl Heuer <kwzh@gnu.org>
parents:
15648
diff
changeset
|
594 (if (eq (string-to-char data) ?.) |
46d74bda4351
(smtpmail-send-data-1): Escape "." at the start of
Karl Heuer <kwzh@gnu.org>
parents:
15648
diff
changeset
|
595 (process-send-string process ".")) |
15345 | 596 (process-send-string process data) |
597 (process-send-string process "\r\n") | |
598 ) | |
599 | |
600 (defun smtpmail-send-data (process buffer) | |
601 (let | |
602 ((data-continue t) | |
603 (sending-data nil) | |
604 this-line | |
605 this-line-end) | |
606 | |
607 (save-excursion | |
608 (set-buffer buffer) | |
609 (goto-char (point-min))) | |
610 | |
611 (while data-continue | |
612 (save-excursion | |
613 (set-buffer buffer) | |
614 (beginning-of-line) | |
615 (setq this-line (point)) | |
616 (end-of-line) | |
617 (setq this-line-end (point)) | |
618 (setq sending-data nil) | |
619 (setq sending-data (buffer-substring this-line this-line-end)) | |
620 (if (/= (forward-line 1) 0) | |
621 (setq data-continue nil))) | |
622 | |
623 (smtpmail-send-data-1 process sending-data) | |
624 ) | |
625 ) | |
626 ) | |
627 | |
628 | |
629 (defun smtpmail-deduce-address-list (smtpmail-text-buffer header-start header-end) | |
630 "Get address list suitable for smtp RCPT TO: <address>." | |
631 (require 'mail-utils) ;; pick up mail-strip-quoted-names | |
632 (let | |
633 ((case-fold-search t) | |
634 (simple-address-list "") | |
635 this-line | |
15648
2feeabc94834
(smtpmail-deduce-address-list): Handle RESENT-* fields.
Karl Heuer <kwzh@gnu.org>
parents:
15595
diff
changeset
|
636 this-line-end |
2feeabc94834
(smtpmail-deduce-address-list): Handle RESENT-* fields.
Karl Heuer <kwzh@gnu.org>
parents:
15595
diff
changeset
|
637 addr-regexp) |
15345 | 638 |
639 (unwind-protect | |
640 (save-excursion | |
641 ;; | |
642 (set-buffer smtpmail-address-buffer) (erase-buffer) | |
643 (insert-buffer-substring smtpmail-text-buffer header-start header-end) | |
644 (goto-char (point-min)) | |
15648
2feeabc94834
(smtpmail-deduce-address-list): Handle RESENT-* fields.
Karl Heuer <kwzh@gnu.org>
parents:
15595
diff
changeset
|
645 ;; RESENT-* fields should stop processing of regular fields. |
2feeabc94834
(smtpmail-deduce-address-list): Handle RESENT-* fields.
Karl Heuer <kwzh@gnu.org>
parents:
15595
diff
changeset
|
646 (save-excursion |
2feeabc94834
(smtpmail-deduce-address-list): Handle RESENT-* fields.
Karl Heuer <kwzh@gnu.org>
parents:
15595
diff
changeset
|
647 (if (re-search-forward "^RESENT-TO:" header-end t) |
2feeabc94834
(smtpmail-deduce-address-list): Handle RESENT-* fields.
Karl Heuer <kwzh@gnu.org>
parents:
15595
diff
changeset
|
648 (setq addr-regexp "^\\(RESENT-TO:\\|RESENT-CC:\\|RESENT-BCC:\\)") |
2feeabc94834
(smtpmail-deduce-address-list): Handle RESENT-* fields.
Karl Heuer <kwzh@gnu.org>
parents:
15595
diff
changeset
|
649 (setq addr-regexp "^\\(TO:\\|CC:\\|BCC:\\)"))) |
2feeabc94834
(smtpmail-deduce-address-list): Handle RESENT-* fields.
Karl Heuer <kwzh@gnu.org>
parents:
15595
diff
changeset
|
650 |
2feeabc94834
(smtpmail-deduce-address-list): Handle RESENT-* fields.
Karl Heuer <kwzh@gnu.org>
parents:
15595
diff
changeset
|
651 (while (re-search-forward addr-regexp header-end t) |
15345 | 652 (replace-match "") |
653 (setq this-line (match-beginning 0)) | |
654 (forward-line 1) | |
655 ;; get any continuation lines | |
656 (while (and (looking-at "^[ \t]+") (< (point) header-end)) | |
657 (forward-line 1)) | |
658 (setq this-line-end (point-marker)) | |
659 (setq simple-address-list | |
660 (concat simple-address-list " " | |
661 (mail-strip-quoted-names (buffer-substring this-line this-line-end)))) | |
662 ) | |
663 (erase-buffer) | |
664 (insert-string " ") | |
665 (insert-string simple-address-list) | |
666 (insert-string "\n") | |
667 (subst-char-in-region (point-min) (point-max) 10 ? t);; newline --> blank | |
668 (subst-char-in-region (point-min) (point-max) ?, ? t);; comma --> blank | |
669 (subst-char-in-region (point-min) (point-max) 9 ? t);; tab --> blank | |
670 | |
671 (goto-char (point-min)) | |
672 ;; tidyness in case hook is not robust when it looks at this | |
673 (while (re-search-forward "[ \t]+" header-end t) (replace-match " ")) | |
674 | |
675 (goto-char (point-min)) | |
15346
4cd6ff2384dc
(smtpmail-send-it): Fix error messages.
Richard M. Stallman <rms@gnu.org>
parents:
15345
diff
changeset
|
676 (let (recipient-address-list) |
15451
89c1e7fe879a
(smtpmail-smtp-service): Use port 25 as default.
Richard M. Stallman <rms@gnu.org>
parents:
15372
diff
changeset
|
677 (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
|
678 (backward-char 1) |
15451
89c1e7fe879a
(smtpmail-smtp-service): Use port 25 as default.
Richard M. Stallman <rms@gnu.org>
parents:
15372
diff
changeset
|
679 (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
|
680 recipient-address-list)) |
15346
4cd6ff2384dc
(smtpmail-send-it): Fix error messages.
Richard M. Stallman <rms@gnu.org>
parents:
15345
diff
changeset
|
681 ) |
4cd6ff2384dc
(smtpmail-send-it): Fix error messages.
Richard M. Stallman <rms@gnu.org>
parents:
15345
diff
changeset
|
682 (setq smtpmail-recipient-address-list recipient-address-list)) |
15345 | 683 |
684 ) | |
685 ) | |
686 ) | |
687 ) | |
688 | |
689 | |
690 (defun smtpmail-do-bcc (header-end) | |
691 "Delete BCC: and their continuation lines from the header area. | |
692 There may be multiple BCC: lines, and each may have arbitrarily | |
693 many continuation lines." | |
694 (let ((case-fold-search t)) | |
695 (save-excursion (goto-char (point-min)) | |
696 ;; iterate over all BCC: lines | |
697 (while (re-search-forward "^BCC:" header-end t) | |
698 (delete-region (match-beginning 0) (progn (forward-line 1) (point))) | |
699 ;; get rid of any continuation lines | |
700 (while (and (looking-at "^[ \t].*\n") (< (point) header-end)) | |
701 (replace-match "")) | |
702 ) | |
703 ) ;; save-excursion | |
704 ) ;; let | |
705 ) | |
706 | |
707 | |
708 | |
709 (provide 'smtpmail) | |
710 | |
17517 | 711 ;;; smtpmail.el ends here |