annotate lisp/utils/smtpmail.el @ 151:59463afc5666 r20-3b2

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