annotate lisp/utils/smtpmail.el @ 114:8619ce7e4c50 r20-1b9

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