2 |
2 |
/*
|
3 |
3 |
* smtp.php
|
4 |
4 |
*
|
5 |
|
* @(#) $Header$
|
|
5 |
* @(#) $Header: /opt2/ena/metal/smtp/smtp.php,v 1.48 2014/11/23 22:45:30 mlemos Exp $
|
6 |
6 |
*
|
7 |
7 |
*/
|
8 |
8 |
|
|
9 |
/*
|
|
10 |
{metadocument}<?xml version="1.0" encoding="ISO-8859-1"?>
|
|
11 |
<class>
|
|
12 |
|
|
13 |
<package>net.manuellemos.smtp</package>
|
|
14 |
|
|
15 |
<version>@(#) $Id: smtp.php,v 1.48 2014/11/23 22:45:30 mlemos Exp $</version>
|
|
16 |
<copyright>Copyright (C) Manuel Lemos 1999-2011</copyright>
|
|
17 |
<title>Sending e-mail messages via SMTP protocol</title>
|
|
18 |
<author>Manuel Lemos</author>
|
|
19 |
<authoraddress>mlemos-at-acm.org</authoraddress>
|
|
20 |
|
|
21 |
<documentation>
|
|
22 |
<idiom>en</idiom>
|
|
23 |
<purpose>Sending e-mail messages via SMTP protocol</purpose>
|
|
24 |
<translation>If you are interested in translating the documentation of
|
|
25 |
this class to your own idiom, please <link>
|
|
26 |
<data>contact the author</data>
|
|
27 |
<url>mailto:<getclassproperty>authoraddress</getclassproperty></url>
|
|
28 |
</link>.</translation>
|
|
29 |
<support>Technical support for using this class may be obtained in the
|
|
30 |
<tt>smtpclass</tt> support forum. Just go to the support forum pages
|
|
31 |
page to browse the forum archives and post support request
|
|
32 |
messages:<paragraphbreak />
|
|
33 |
<link>
|
|
34 |
<data>http://www.phpclasses.org/discuss/package/14/</data>
|
|
35 |
<url>http://www.phpclasses.org/discuss/package/14/</url>
|
|
36 |
</link></support>
|
|
37 |
<usage>To use this class just create a new object, set any variables
|
|
38 |
to configure its options and call the
|
|
39 |
<functionlink>SendMessage</functionlink> function to send a
|
|
40 |
message.<paragraphbreak />It is not recommended that you use this
|
|
41 |
class alone unless you have deep understanding of Internet mail
|
|
42 |
standards on how to compose compliant e-mail messages. Instead, use
|
|
43 |
the <link>
|
|
44 |
<data>MIME message composing and sending class</data>
|
|
45 |
<url>http://www.phpclasses.org/mimemessage</url>
|
|
46 |
</link> and its sub-class SMTP message together with this SMTP class
|
|
47 |
to properly compose e-mail messages, so your messages are not
|
|
48 |
discarded for not being correctly composed.</usage>
|
|
49 |
</documentation>
|
|
50 |
|
|
51 |
{/metadocument}
|
|
52 |
*/
|
|
53 |
|
9 |
54 |
class smtp_class
|
10 |
55 |
{
|
|
56 |
/*
|
|
57 |
{metadocument}
|
|
58 |
<variable>
|
|
59 |
<name>user</name>
|
|
60 |
<type>STRING</type>
|
|
61 |
<value></value>
|
|
62 |
<documentation>
|
|
63 |
<purpose>Define the authorized user when sending messages to a SMTP
|
|
64 |
server.</purpose>
|
|
65 |
<usage>Set this variable to the user name when the SMTP server
|
|
66 |
requires authentication.</usage>
|
|
67 |
</documentation>
|
|
68 |
</variable>
|
|
69 |
{/metadocument}
|
|
70 |
*/
|
11 |
71 |
var $user="";
|
|
72 |
|
|
73 |
/*
|
|
74 |
{metadocument}
|
|
75 |
<variable>
|
|
76 |
<name>realm</name>
|
|
77 |
<type>STRING</type>
|
|
78 |
<value></value>
|
|
79 |
<documentation>
|
|
80 |
<purpose>Define the authentication realm when sending messages to a
|
|
81 |
SMTP server.</purpose>
|
|
82 |
<usage>Set this variable when the SMTP server requires
|
|
83 |
authentication and if more than one authentication realm is
|
|
84 |
supported.</usage>
|
|
85 |
</documentation>
|
|
86 |
</variable>
|
|
87 |
{/metadocument}
|
|
88 |
*/
|
12 |
89 |
var $realm="";
|
|
90 |
|
|
91 |
/*
|
|
92 |
{metadocument}
|
|
93 |
<variable>
|
|
94 |
<name>password</name>
|
|
95 |
<type>STRING</type>
|
|
96 |
<value></value>
|
|
97 |
<documentation>
|
|
98 |
<purpose>Define the authorized user password when sending messages
|
|
99 |
to a SMTP server.</purpose>
|
|
100 |
<usage>Set this variable to the user password when the SMTP server
|
|
101 |
requires authentication.</usage>
|
|
102 |
</documentation>
|
|
103 |
</variable>
|
|
104 |
{/metadocument}
|
|
105 |
*/
|
13 |
106 |
var $password="";
|
|
107 |
|
|
108 |
/*
|
|
109 |
{metadocument}
|
|
110 |
<variable>
|
|
111 |
<name>workstation</name>
|
|
112 |
<type>STRING</type>
|
|
113 |
<value></value>
|
|
114 |
<documentation>
|
|
115 |
<purpose>Define the client workstation name when sending messages
|
|
116 |
to a SMTP server.</purpose>
|
|
117 |
<usage>Set this variable to the client workstation when the SMTP
|
|
118 |
server requires authentication identifiying the origin workstation
|
|
119 |
name.</usage>
|
|
120 |
</documentation>
|
|
121 |
</variable>
|
|
122 |
{/metadocument}
|
|
123 |
*/
|
14 |
124 |
var $workstation="";
|
|
125 |
|
|
126 |
/*
|
|
127 |
{metadocument}
|
|
128 |
<variable>
|
|
129 |
<name>authentication_mechanism</name>
|
|
130 |
<type>STRING</type>
|
|
131 |
<value></value>
|
|
132 |
<documentation>
|
|
133 |
<purpose>Force the use of a specific authentication mechanism.</purpose>
|
|
134 |
<usage>Set it to an empty string to let the class determine the
|
|
135 |
authentication mechanism to use automatically based on the
|
|
136 |
supported mechanisms by the server and by the SASL client library
|
|
137 |
classes.<paragraphbreak />
|
|
138 |
Set this variable to a specific mechanism name if you want to
|
|
139 |
override the automatic authentication mechanism selection.</usage>
|
|
140 |
</documentation>
|
|
141 |
</variable>
|
|
142 |
{/metadocument}
|
|
143 |
*/
|
15 |
144 |
var $authentication_mechanism="";
|
|
145 |
|
|
146 |
/*
|
|
147 |
{metadocument}
|
|
148 |
<variable>
|
|
149 |
<name>host_name</name>
|
|
150 |
<type>STRING</type>
|
|
151 |
<value></value>
|
|
152 |
<documentation>
|
|
153 |
<purpose>Define the SMTP server host name.</purpose>
|
|
154 |
<usage>Set to the host name of the SMTP server to which you want to
|
|
155 |
relay the messages.</usage>
|
|
156 |
</documentation>
|
|
157 |
</variable>
|
|
158 |
{/metadocument}
|
|
159 |
*/
|
16 |
160 |
var $host_name="";
|
|
161 |
|
|
162 |
/*
|
|
163 |
{metadocument}
|
|
164 |
<variable>
|
|
165 |
<name>host_port</name>
|
|
166 |
<type>INTEGER</type>
|
|
167 |
<value>25</value>
|
|
168 |
<documentation>
|
|
169 |
<purpose>Define the SMTP server host port.</purpose>
|
|
170 |
<usage>Set to the TCP port of the SMTP server host to connect.</usage>
|
|
171 |
</documentation>
|
|
172 |
</variable>
|
|
173 |
{/metadocument}
|
|
174 |
*/
|
17 |
175 |
var $host_port=25;
|
|
176 |
|
|
177 |
/*
|
|
178 |
{metadocument}
|
|
179 |
<variable>
|
|
180 |
<name>socks_host_name</name>
|
|
181 |
<type>STRING</type>
|
|
182 |
<value></value>
|
|
183 |
<documentation>
|
|
184 |
<purpose>Define the SOCKS server host name.</purpose>
|
|
185 |
<usage>Set to the SOCKS server host name through which the SMTP
|
|
186 |
connection should be routed. Leave it empty if you do not want the
|
|
187 |
connections to be established through a SOCKS server.</usage>
|
|
188 |
</documentation>
|
|
189 |
</variable>
|
|
190 |
{/metadocument}
|
|
191 |
*/
|
|
192 |
var $socks_host_name = '';
|
|
193 |
|
|
194 |
/*
|
|
195 |
{metadocument}
|
|
196 |
<variable>
|
|
197 |
<name>socks_host_port</name>
|
|
198 |
<type>INTEGER</type>
|
|
199 |
<value>1080</value>
|
|
200 |
<documentation>
|
|
201 |
<purpose>Define the SOCKS server host port.</purpose>
|
|
202 |
<usage>Set to the port of the SOCKS server host through which the
|
|
203 |
the SMTP connection should be routed.</usage>
|
|
204 |
</documentation>
|
|
205 |
</variable>
|
|
206 |
{/metadocument}
|
|
207 |
*/
|
|
208 |
var $socks_host_port=1080;
|
|
209 |
|
|
210 |
/*
|
|
211 |
{metadocument}
|
|
212 |
<variable>
|
|
213 |
<name>socks_version</name>
|
|
214 |
<type>STRING</type>
|
|
215 |
<value>5</value>
|
|
216 |
<documentation>
|
|
217 |
<purpose>Set the SOCKS protocol version.</purpose>
|
|
218 |
<usage>Change this value if SOCKS server you want to use is
|
|
219 |
listening to a different port.</usage>
|
|
220 |
</documentation>
|
|
221 |
</variable>
|
|
222 |
{/metadocument}
|
|
223 |
*/
|
|
224 |
var $socks_version='5';
|
|
225 |
|
|
226 |
/*
|
|
227 |
{metadocument}
|
|
228 |
<variable>
|
|
229 |
<name>http_proxy_host_name</name>
|
|
230 |
<type>STRING</type>
|
|
231 |
<value></value>
|
|
232 |
<documentation>
|
|
233 |
<purpose>Define the HTTP proxy server host name.</purpose>
|
|
234 |
<usage>Set to the HTTP proxy server host name through which the
|
|
235 |
SMTP connection should be routed. Leave it empty if you do not
|
|
236 |
want the connections to be established through an HTTP proxy.</usage>
|
|
237 |
</documentation>
|
|
238 |
</variable>
|
|
239 |
{/metadocument}
|
|
240 |
*/
|
|
241 |
var $http_proxy_host_name = '';
|
|
242 |
|
|
243 |
/*
|
|
244 |
{metadocument}
|
|
245 |
<variable>
|
|
246 |
<name>http_proxy_host_port</name>
|
|
247 |
<type>INTEGER</type>
|
|
248 |
<value>80</value>
|
|
249 |
<documentation>
|
|
250 |
<purpose>Define the HTTP proxy server host port.</purpose>
|
|
251 |
<usage>Set to the port of the HTTP proxy server host through which
|
|
252 |
the SMTP connection should be routed.</usage>
|
|
253 |
</documentation>
|
|
254 |
</variable>
|
|
255 |
{/metadocument}
|
|
256 |
*/
|
|
257 |
var $http_proxy_host_port=80;
|
|
258 |
|
|
259 |
/*
|
|
260 |
{metadocument}
|
|
261 |
<variable>
|
|
262 |
<name>user_agent</name>
|
|
263 |
<type>STRING</type>
|
|
264 |
<value>SMTP Class (http://www.phpclasses.org/smtpclass $Revision: 1.48 $)</value>
|
|
265 |
<documentation>
|
|
266 |
<purpose>Set the user agent used when connecting via an HTTP proxy.</purpose>
|
|
267 |
<usage>Change this value only if for some reason you want emulate a
|
|
268 |
certain e-mail client.</usage>
|
|
269 |
</documentation>
|
|
270 |
</variable>
|
|
271 |
{/metadocument}
|
|
272 |
*/
|
|
273 |
var $user_agent='SMTP Class (http://www.phpclasses.org/smtpclass $Revision: 1.48 $)';
|
|
274 |
|
|
275 |
/*
|
|
276 |
{metadocument}
|
|
277 |
<variable>
|
|
278 |
<name>ssl</name>
|
|
279 |
<type>BOOLEAN</type>
|
|
280 |
<value>0</value>
|
|
281 |
<documentation>
|
|
282 |
<purpose>Define whether the connection to the SMTP server should be
|
|
283 |
established securely using SSL protocol.</purpose>
|
|
284 |
<usage>Set to <booleanvalue>1</booleanvalue> if the SMTP server
|
|
285 |
requires secure connections using SSL protocol.</usage>
|
|
286 |
</documentation>
|
|
287 |
</variable>
|
|
288 |
{/metadocument}
|
|
289 |
*/
|
18 |
290 |
var $ssl=0;
|
19 |
|
var $tls=0;
|
|
291 |
|
|
292 |
/*
|
|
293 |
{metadocument}
|
|
294 |
<variable>
|
|
295 |
<name>start_tls</name>
|
|
296 |
<type>BOOLEAN</type>
|
|
297 |
<value>0</value>
|
|
298 |
<documentation>
|
|
299 |
<purpose>Define whether the connection to the SMTP server should use
|
|
300 |
encryption after the connection is established using TLS
|
|
301 |
protocol.</purpose>
|
|
302 |
<usage>Set to <booleanvalue>1</booleanvalue> if the SMTP server
|
|
303 |
requires that authentication be done securely starting the TLS
|
|
304 |
protocol after the connection is established.</usage>
|
|
305 |
</documentation>
|
|
306 |
</variable>
|
|
307 |
{/metadocument}
|
|
308 |
*/
|
|
309 |
var $start_tls = 0;
|
|
310 |
|
|
311 |
/*
|
|
312 |
{metadocument}
|
|
313 |
<variable>
|
|
314 |
<name>localhost</name>
|
|
315 |
<type>STRING</type>
|
|
316 |
<value></value>
|
|
317 |
<documentation>
|
|
318 |
<purpose>Name of the local host computer</purpose>
|
|
319 |
<usage>Set to the name of the computer connecting to the SMTP
|
|
320 |
server from the local network.</usage>
|
|
321 |
</documentation>
|
|
322 |
</variable>
|
|
323 |
{/metadocument}
|
|
324 |
*/
|
20 |
325 |
var $localhost="";
|
|
326 |
|
|
327 |
/*
|
|
328 |
{metadocument}
|
|
329 |
<variable>
|
|
330 |
<name>timeout</name>
|
|
331 |
<type>INTEGER</type>
|
|
332 |
<value>0</value>
|
|
333 |
<documentation>
|
|
334 |
<purpose>Specify the connection timeout period in seconds.</purpose>
|
|
335 |
<usage>Leave it set to <integervalue>0</integervalue> if you want
|
|
336 |
the connection attempts to wait forever. Change this value if for
|
|
337 |
some reason the timeout period seems insufficient or otherwise it
|
|
338 |
seems too long.</usage>
|
|
339 |
</documentation>
|
|
340 |
</variable>
|
|
341 |
{/metadocument}
|
|
342 |
*/
|
21 |
343 |
var $timeout=0;
|
|
344 |
|
|
345 |
/*
|
|
346 |
{metadocument}
|
|
347 |
<variable>
|
|
348 |
<name>data_timeout</name>
|
|
349 |
<type>INTEGER</type>
|
|
350 |
<value>0</value>
|
|
351 |
<documentation>
|
|
352 |
<purpose>Specify the timeout period in seconds to wait for data from
|
|
353 |
the server.</purpose>
|
|
354 |
<usage>Leave it set to <integervalue>0</integervalue> if you want
|
|
355 |
to use the same value defined in the
|
|
356 |
<variablelink>timeout</variablelink> variable. Change this value
|
|
357 |
if for some reason the default data timeout period seems
|
|
358 |
insufficient or otherwise it seems too long.</usage>
|
|
359 |
</documentation>
|
|
360 |
</variable>
|
|
361 |
{/metadocument}
|
|
362 |
*/
|
22 |
363 |
var $data_timeout=0;
|
|
364 |
|
|
365 |
/*
|
|
366 |
{metadocument}
|
|
367 |
<variable>
|
|
368 |
<name>direct_delivery</name>
|
|
369 |
<type>BOOLEAN</type>
|
|
370 |
<value>0</value>
|
|
371 |
<documentation>
|
|
372 |
<purpose>Boolean flag that indicates whether the message should be
|
|
373 |
sent in direct delivery mode, i.e. the message is sent to the SMTP
|
|
374 |
server associated to the domain of the recipient instead of
|
|
375 |
relaying to the server specified by the
|
|
376 |
<variablelink>host_name</variablelink> variable.</purpose>
|
|
377 |
<usage>Set this to <tt><booleanvalue>1</booleanvalue></tt> if you
|
|
378 |
want to send urgent messages directly to the recipient domain SMTP
|
|
379 |
server.</usage>
|
|
380 |
</documentation>
|
|
381 |
</variable>
|
|
382 |
{/metadocument}
|
|
383 |
*/
|
23 |
384 |
var $direct_delivery=0;
|
|
385 |
|
|
386 |
/*
|
|
387 |
{metadocument}
|
|
388 |
<variable>
|
|
389 |
<name>error</name>
|
|
390 |
<type>STRING</type>
|
|
391 |
<value></value>
|
|
392 |
<documentation>
|
|
393 |
<purpose>Message that describes the error when a call to a class
|
|
394 |
function fails.</purpose>
|
|
395 |
<usage>Check this variable when an error occurs to understand what
|
|
396 |
happened.</usage>
|
|
397 |
</documentation>
|
|
398 |
</variable>
|
|
399 |
{/metadocument}
|
|
400 |
*/
|
24 |
401 |
var $error="";
|
|
402 |
|
|
403 |
/*
|
|
404 |
{metadocument}
|
|
405 |
<variable>
|
|
406 |
<name>debug</name>
|
|
407 |
<type>BOOLEAN</type>
|
|
408 |
<value>0</value>
|
|
409 |
<documentation>
|
|
410 |
<purpose>Specify whether it is necessary to output SMTP connection
|
|
411 |
debug information.</purpose>
|
|
412 |
<usage>Set this variable to
|
|
413 |
<tt><booleanvalue>1</booleanvalue></tt> if you need to see
|
|
414 |
the progress of the SMTP connection and protocol dialog when you
|
|
415 |
need to understand the reason for delivery problems.</usage>
|
|
416 |
</documentation>
|
|
417 |
</variable>
|
|
418 |
{/metadocument}
|
|
419 |
*/
|
25 |
420 |
var $debug=0;
|
|
421 |
|
|
422 |
/*
|
|
423 |
{metadocument}
|
|
424 |
<variable>
|
|
425 |
<name>html_debug</name>
|
|
426 |
<type>BOOLEAN</type>
|
|
427 |
<value>0</value>
|
|
428 |
<documentation>
|
|
429 |
<purpose>Specify whether the debug information should be outputted in
|
|
430 |
HTML format.</purpose>
|
|
431 |
<usage>Set this variable to
|
|
432 |
<tt><booleanvalue>1</booleanvalue></tt> if you need to see
|
|
433 |
the debug output in a Web page.</usage>
|
|
434 |
</documentation>
|
|
435 |
</variable>
|
|
436 |
{/metadocument}
|
|
437 |
*/
|
26 |
438 |
var $html_debug=0;
|
|
439 |
|
|
440 |
/*
|
|
441 |
{metadocument}
|
|
442 |
<variable>
|
|
443 |
<name>esmtp</name>
|
|
444 |
<type>BOOLEAN</type>
|
|
445 |
<value>1</value>
|
|
446 |
<documentation>
|
|
447 |
<purpose>Specify whether the class should attempt to use ESMTP
|
|
448 |
extensions supported by the server.</purpose>
|
|
449 |
<usage>Set this variable to
|
|
450 |
<tt><booleanvalue>0</booleanvalue></tt> if for some reason you
|
|
451 |
want to avoid benefitting from ESMTP extensions.</usage>
|
|
452 |
</documentation>
|
|
453 |
</variable>
|
|
454 |
{/metadocument}
|
|
455 |
*/
|
27 |
456 |
var $esmtp=1;
|
28 |
|
var $esmtp_host="";
|
|
457 |
|
|
458 |
/*
|
|
459 |
{metadocument}
|
|
460 |
<variable>
|
|
461 |
<name>esmtp_extensions</name>
|
|
462 |
<type>HASH</type>
|
|
463 |
<value></value>
|
|
464 |
<documentation>
|
|
465 |
<purpose>Associative array with the list of ESMTP extensions
|
|
466 |
supported by the SMTP server.</purpose>
|
|
467 |
<usage>Check this variable after connecting to the SMTP server to
|
|
468 |
determine which ESMTP extensions are supported.</usage>
|
|
469 |
</documentation>
|
|
470 |
</variable>
|
|
471 |
{/metadocument}
|
|
472 |
*/
|
29 |
473 |
var $esmtp_extensions=array();
|
30 |
|
var $maximum_piped_recipients=100;
|
|
474 |
|
|
475 |
/*
|
|
476 |
{metadocument}
|
|
477 |
<variable>
|
|
478 |
<name>exclude_address</name>
|
|
479 |
<type>STRING</type>
|
|
480 |
<value></value>
|
|
481 |
<documentation>
|
|
482 |
<purpose>Specify an address that should be considered invalid
|
|
483 |
when resolving host name addresses.</purpose>
|
|
484 |
<usage>In some networks any domain name that does not exist is
|
|
485 |
resolved as a sub-domain of the default local domain. If the DNS is
|
|
486 |
configured in such way that it always resolves any sub-domain of
|
|
487 |
the default local domain to a given address, it is hard to
|
|
488 |
determine whether a given domain does not exist.<paragraphbreak />
|
|
489 |
If your network is configured this way, you may set this variable
|
|
490 |
to the address that all sub-domains of the default local domain
|
|
491 |
resolves, so the class can assume that such address is invalid.</usage>
|
|
492 |
</documentation>
|
|
493 |
</variable>
|
|
494 |
{/metadocument}
|
|
495 |
*/
|
31 |
496 |
var $exclude_address="";
|
|
497 |
|
|
498 |
/*
|
|
499 |
{metadocument}
|
|
500 |
<variable>
|
|
501 |
<name>getmxrr</name>
|
|
502 |
<type>STRING</type>
|
|
503 |
<value>getmxrr</value>
|
|
504 |
<documentation>
|
|
505 |
<purpose>Specify the name of the function that is called to determine
|
|
506 |
the SMTP server address of a given domain.</purpose>
|
|
507 |
<usage>Change this to a working replacement of the PHP
|
|
508 |
<tt>getmxrr()</tt> function if this is not working in your system
|
|
509 |
and you want to send messages in direct delivery mode.</usage>
|
|
510 |
</documentation>
|
|
511 |
</variable>
|
|
512 |
{/metadocument}
|
|
513 |
*/
|
32 |
514 |
var $getmxrr="GetMXRR";
|
|
515 |
|
|
516 |
/*
|
|
517 |
{metadocument}
|
|
518 |
<variable>
|
|
519 |
<name>pop3_auth_host</name>
|
|
520 |
<type>STRING</type>
|
|
521 |
<value></value>
|
|
522 |
<documentation>
|
|
523 |
<purpose>Specify the server address for POP3 based authentication.</purpose>
|
|
524 |
<usage>Set this variable to the address of the POP3 server if the
|
|
525 |
SMTP server requires POP3 based authentication.</usage>
|
|
526 |
</documentation>
|
|
527 |
</variable>
|
|
528 |
{/metadocument}
|
|
529 |
*/
|
33 |
530 |
var $pop3_auth_host="";
|
|
531 |
|
|
532 |
/*
|
|
533 |
{metadocument}
|
|
534 |
<variable>
|
|
535 |
<name>pop3_auth_port</name>
|
|
536 |
<type>INTEGER</type>
|
|
537 |
<value>110</value>
|
|
538 |
<documentation>
|
|
539 |
<purpose>Specify the server port for POP3 based authentication.</purpose>
|
|
540 |
<usage>Set this variable to the port of the POP3 server if the
|
|
541 |
SMTP server requires POP3 based authentication.</usage>
|
|
542 |
</documentation>
|
|
543 |
</variable>
|
|
544 |
{/metadocument}
|
|
545 |
*/
|
34 |
546 |
var $pop3_auth_port=110;
|
35 |
547 |
|
36 |
548 |
/* private variables - DO NOT ACCESS */
|
... | ... | |
43 |
555 |
var $connected_domain="";
|
44 |
556 |
var $result_code;
|
45 |
557 |
var $disconnected_error=0;
|
|
558 |
var $esmtp_host="";
|
|
559 |
var $maximum_piped_recipients=100;
|
46 |
560 |
|
47 |
561 |
/* Private methods - DO NOT CALL */
|
48 |
562 |
|
... | ... | |
86 |
600 |
{
|
87 |
601 |
$status=socket_get_status($this->connection);
|
88 |
602 |
if($status["timed_out"])
|
89 |
|
$this->error.=gettext(": data access time out");
|
|
603 |
$this->error.=": data access time out";
|
90 |
604 |
elseif($status["eof"])
|
91 |
605 |
{
|
92 |
|
$this->error.=gettext(": the server disconnected");
|
|
606 |
$this->error.=": the server disconnected";
|
93 |
607 |
$this->disconnected_error=1;
|
94 |
608 |
}
|
95 |
609 |
}
|
|
610 |
return($this->error);
|
|
611 |
}
|
|
612 |
|
|
613 |
Function SetError($error)
|
|
614 |
{
|
|
615 |
return($this->error=$error);
|
96 |
616 |
}
|
97 |
617 |
|
98 |
618 |
Function GetLine()
|
... | ... | |
101 |
621 |
{
|
102 |
622 |
if(feof($this->connection))
|
103 |
623 |
{
|
104 |
|
$this->error=gettext("reached the end of data while reading from the SMTP server connection");
|
|
624 |
$this->error="reached the end of data while reading from the SMTP server conection";
|
105 |
625 |
return("");
|
106 |
626 |
}
|
107 |
627 |
if(GetType($data=@fgets($this->connection,100))!="string"
|
108 |
628 |
|| strlen($data)==0)
|
109 |
629 |
{
|
110 |
|
$this->SetDataAccessError(gettext("it was not possible to read line from the SMTP server"));
|
|
630 |
$this->SetDataAccessError("it was not possible to read line from the SMTP server");
|
111 |
631 |
return("");
|
112 |
632 |
}
|
113 |
633 |
$line.=$data;
|
... | ... | |
129 |
649 |
$this->OutputDebug("C $line");
|
130 |
650 |
if(!@fputs($this->connection,"$line\r\n"))
|
131 |
651 |
{
|
132 |
|
$this->SetDataAccessError(gettext("it was not possible to send a line to the SMTP server"));
|
|
652 |
$this->SetDataAccessError("it was not possible to send a line to the SMTP server");
|
133 |
653 |
return(0);
|
134 |
654 |
}
|
135 |
655 |
return(1);
|
... | ... | |
143 |
663 |
$this->OutputDebug("C $data");
|
144 |
664 |
if(!@fputs($this->connection,$data))
|
145 |
665 |
{
|
146 |
|
$this->SetDataAccessError(gettext("it was not possible to send data to the SMTP server"));
|
|
666 |
$this->SetDataAccessError("it was not possible to send data to the SMTP server");
|
147 |
667 |
return(0);
|
148 |
668 |
}
|
149 |
669 |
}
|
... | ... | |
208 |
728 |
return(1);
|
209 |
729 |
}
|
210 |
730 |
|
|
731 |
Function Resolve($domain, &$ip, $server_type)
|
|
732 |
{
|
|
733 |
if(preg_match('/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/',$domain))
|
|
734 |
$ip=$domain;
|
|
735 |
else
|
|
736 |
{
|
|
737 |
if($this->debug)
|
|
738 |
$this->OutputDebug('Resolving '.$server_type.' server domain "'.$domain.'"...');
|
|
739 |
if(!strcmp($ip=@gethostbyname($domain),$domain))
|
|
740 |
$ip="";
|
|
741 |
}
|
|
742 |
if(strlen($ip)==0
|
|
743 |
|| (strlen($this->exclude_address)
|
|
744 |
&& !strcmp(@gethostbyname($this->exclude_address),$ip)))
|
|
745 |
return($this->SetError("could not resolve the host domain \"".$domain."\""));
|
|
746 |
return('');
|
|
747 |
}
|
|
748 |
|
211 |
749 |
Function ConnectToHost($domain, $port, $resolve_message)
|
212 |
750 |
{
|
213 |
|
if($this->ssl || $this->tls)
|
|
751 |
if($this->ssl)
|
214 |
752 |
{
|
215 |
753 |
$version=explode(".",function_exists("phpversion") ? phpversion() : "3.0.7");
|
216 |
754 |
$php_version=intval($version[0])*1000000+intval($version[1])*1000+intval($version[2]);
|
217 |
755 |
if($php_version<4003000)
|
218 |
|
return(gettext("establishing SSL connections requires at least PHP version 4.3.0"));
|
|
756 |
return("establishing SSL connections requires at least PHP version 4.3.0");
|
219 |
757 |
if(!function_exists("extension_loaded")
|
220 |
758 |
|| !extension_loaded("openssl"))
|
221 |
|
return(gettext("establishing SSL connections requires the OpenSSL extension enabled"));
|
|
759 |
return("establishing SSL connections requires the OpenSSL extension enabled");
|
|
760 |
}
|
|
761 |
if(strlen($this->Resolve($domain, $ip, 'SMTP')))
|
|
762 |
return($this->error);
|
|
763 |
if(strlen($this->socks_host_name))
|
|
764 |
{
|
|
765 |
switch($this->socks_version)
|
|
766 |
{
|
|
767 |
case '4':
|
|
768 |
$version = 4;
|
|
769 |
break;
|
|
770 |
case '5':
|
|
771 |
$version = 5;
|
|
772 |
break;
|
|
773 |
default:
|
|
774 |
return('it was not specified a supported SOCKS protocol version');
|
|
775 |
break;
|
|
776 |
}
|
|
777 |
$host_ip = $ip;
|
|
778 |
$host_port = $port;
|
|
779 |
if(strlen($this->error = $this->Resolve($this->socks_host_name, $ip, 'SOCKS')))
|
|
780 |
return($this->error);
|
|
781 |
if($this->ssl)
|
|
782 |
$ip="ssl://".($socks_host = $this->socks_host_name);
|
|
783 |
else
|
|
784 |
$socks_host = $ip;
|
|
785 |
if($this->debug)
|
|
786 |
$this->OutputDebug("Connecting to SOCKS server \"".$socks_host."\" port ".$this->http_proxy_host_port."...");
|
|
787 |
if(($this->connection=($this->timeout ? fsockopen($ip, $this->socks_host_port, $errno, $error, $this->timeout) : fsockopen($ip, $this->socks_host_port, $errno, $error))))
|
|
788 |
{
|
|
789 |
$timeout=($this->data_timeout ? $this->data_timeout : $this->timeout);
|
|
790 |
if($timeout
|
|
791 |
&& function_exists("socket_set_timeout"))
|
|
792 |
socket_set_timeout($this->connection,$timeout,0);
|
|
793 |
if(strlen($this->socks_host_name))
|
|
794 |
{
|
|
795 |
if($this->debug)
|
|
796 |
$this->OutputDebug('Connected to the SOCKS server '.$this->socks_host_name);
|
|
797 |
$send_error = 'it was not possible to send data to the SOCKS server';
|
|
798 |
$receive_error = 'it was not possible to receive data from the SOCKS server';
|
|
799 |
switch($version)
|
|
800 |
{
|
|
801 |
case 4:
|
|
802 |
$command = 1;
|
|
803 |
$user = '';
|
|
804 |
if(!fputs($this->connection, chr($version).chr($command).pack('nN', $host_port, ip2long($host_ip)).$user.Chr(0)))
|
|
805 |
$error = $this->SetDataAccessError($send_error);
|
|
806 |
else
|
|
807 |
{
|
|
808 |
$response = fgets($this->connection, 9);
|
|
809 |
if(strlen($response) != 8)
|
|
810 |
$error = $this->SetDataAccessError($receive_error);
|
|
811 |
else
|
|
812 |
{
|
|
813 |
$socks_errors = array(
|
|
814 |
"\x5a"=>'',
|
|
815 |
"\x5b"=>'request rejected',
|
|
816 |
"\x5c"=>'request failed because client is not running identd (or not reachable from the server)',
|
|
817 |
"\x5d"=>'request failed because client\'s identd could not confirm the user ID string in the request',
|
|
818 |
);
|
|
819 |
$error_code = $response[1];
|
|
820 |
$error = (IsSet($socks_errors[$error_code]) ? $socks_errors[$error_code] : 'unknown');
|
|
821 |
if(strlen($error))
|
|
822 |
$error = 'SOCKS error: '.$error;
|
|
823 |
}
|
|
824 |
}
|
|
825 |
break;
|
|
826 |
case 5:
|
|
827 |
if($this->debug)
|
|
828 |
$this->OutputDebug('Negotiating the authentication method ...');
|
|
829 |
$methods = 1;
|
|
830 |
$method = 0;
|
|
831 |
if(!fputs($this->connection, chr($version).chr($methods).chr($method)))
|
|
832 |
$error = $this->SetDataAccessError($send_error);
|
|
833 |
else
|
|
834 |
{
|
|
835 |
$response = fgets($this->connection, 3);
|
|
836 |
if(strlen($response) != 2)
|
|
837 |
$error = $this->SetDataAccessError($receive_error);
|
|
838 |
elseif(Ord($response[1]) != $method)
|
|
839 |
$error = 'the SOCKS server requires an authentication method that is not yet supported';
|
|
840 |
else
|
|
841 |
{
|
|
842 |
if($this->debug)
|
|
843 |
$this->OutputDebug('Connecting to SMTP server IP '.$host_ip.' port '.$host_port.'...');
|
|
844 |
$command = 1;
|
|
845 |
$address_type = 1;
|
|
846 |
if(!fputs($this->connection, chr($version).chr($command)."\x00".chr($address_type).pack('Nn', ip2long($host_ip), $host_port)))
|
|
847 |
$error = $this->SetDataAccessError($send_error);
|
|
848 |
else
|
|
849 |
{
|
|
850 |
$response = fgets($this->connection, 11);
|
|
851 |
if(strlen($response) != 10)
|
|
852 |
$error = $this->SetDataAccessError($receive_error);
|
|
853 |
else
|
|
854 |
{
|
|
855 |
$socks_errors = array(
|
|
856 |
"\x00"=>'',
|
|
857 |
"\x01"=>'general SOCKS server failure',
|
|
858 |
"\x02"=>'connection not allowed by ruleset',
|
|
859 |
"\x03"=>'Network unreachable',
|
|
860 |
"\x04"=>'Host unreachable',
|
|
861 |
"\x05"=>'Connection refused',
|
|
862 |
"\x06"=>'TTL expired',
|
|
863 |
"\x07"=>'Command not supported',
|
|
864 |
"\x08"=>'Address type not supported'
|
|
865 |
);
|
|
866 |
$error_code = $response[1];
|
|
867 |
$error = (IsSet($socks_errors[$error_code]) ? $socks_errors[$error_code] : 'unknown');
|
|
868 |
if(strlen($error))
|
|
869 |
$error = 'SOCKS error: '.$error;
|
|
870 |
}
|
|
871 |
}
|
|
872 |
}
|
|
873 |
}
|
|
874 |
break;
|
|
875 |
default:
|
|
876 |
$error = 'support for SOCKS protocol version '.$this->socks_version.' is not yet implemented';
|
|
877 |
break;
|
|
878 |
}
|
|
879 |
if(strlen($this->error = $error))
|
|
880 |
{
|
|
881 |
fclose($this->connection);
|
|
882 |
return($error);
|
|
883 |
}
|
|
884 |
}
|
|
885 |
return('');
|
|
886 |
}
|
|
887 |
}
|
|
888 |
elseif(strlen($this->http_proxy_host_name))
|
|
889 |
{
|
|
890 |
if(strlen($error = $this->Resolve($this->http_proxy_host_name, $ip, 'SMTP')))
|
|
891 |
return($error);
|
|
892 |
if($this->ssl)
|
|
893 |
$ip = 'ssl://'.($proxy_host = $this->http_proxy_host_name);
|
|
894 |
else
|
|
895 |
$proxy_host = $ip;
|
|
896 |
if($this->debug)
|
|
897 |
$this->OutputDebug("Connecting to HTTP proxy server \"".$ip."\" port ".$this->http_proxy_host_port."...");
|
|
898 |
if(($this->connection=($this->timeout ? @fsockopen($ip, $this->http_proxy_host_port, $errno, $error, $this->timeout) : @fsockopen($ip, $this->http_proxy_host_port, $errno, $error))))
|
|
899 |
{
|
|
900 |
if($this->debug)
|
|
901 |
$this->OutputDebug('Connected to HTTP proxy host "'.$this->http_proxy_host_name.'".');
|
|
902 |
$timeout=($this->data_timeout ? $this->data_timeout : $this->timeout);
|
|
903 |
if($timeout
|
|
904 |
&& function_exists("socket_set_timeout"))
|
|
905 |
socket_set_timeout($this->connection,$timeout,0);
|
|
906 |
if($this->PutLine('CONNECT '.$domain.':'.$port.' HTTP/1.0')
|
|
907 |
&& $this->PutLine('User-Agent: '.$this->user_agent)
|
|
908 |
&& $this->PutLine(''))
|
|
909 |
{
|
|
910 |
if(GetType($response = $this->GetLine()) == 'string')
|
|
911 |
{
|
|
912 |
if(!preg_match('/^http\\/[0-9]+\\.[0-9]+[ \t]+([0-9]+)[ \t]*(.*)$/i', $response,$matches))
|
|
913 |
return($this->SetError("3 it was received an unexpected HTTP response status"));
|
|
914 |
$error = $matches[1];
|
|
915 |
switch($error)
|
|
916 |
{
|
|
917 |
case '200':
|
|
918 |
for(;;)
|
|
919 |
{
|
|
920 |
if(GetType($response = $this->GetLine()) != 'string')
|
|
921 |
break;
|
|
922 |
if(strlen($response) == 0)
|
|
923 |
return('');
|
|
924 |
}
|
|
925 |
break;
|
|
926 |
default:
|
|
927 |
$this->error = 'the HTTP proxy returned error '.$error.' '.$matches[2];
|
|
928 |
break;
|
|
929 |
}
|
|
930 |
}
|
|
931 |
}
|
|
932 |
if($this->debug)
|
|
933 |
$this->OutputDebug("Disconnected.");
|
|
934 |
fclose($this->connection);
|
|
935 |
$this->connection = 0;
|
|
936 |
return($this->error);
|
|
937 |
}
|
222 |
938 |
}
|
223 |
|
if(preg_match('/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/',$domain))
|
224 |
|
$ip=$domain;
|
225 |
939 |
else
|
226 |
940 |
{
|
|
941 |
if($this->ssl)
|
|
942 |
$ip = 'ssl://'.($host = $domain);
|
|
943 |
elseif($this->start_tls)
|
|
944 |
$ip = $host = $domain;
|
|
945 |
else
|
|
946 |
$host = $ip;
|
227 |
947 |
if($this->debug)
|
228 |
|
$this->OutputDebug($resolve_message);
|
229 |
|
if(!strcmp($ip=@gethostbyname($domain),$domain))
|
230 |
|
return(sprintf(gettext("could not resolve host \"%s\""), $domain));
|
|
948 |
$this->OutputDebug("Connecting to SMTP server \"".$host."\" port ".$port."...");
|
|
949 |
if(($this->connection=($this->timeout ? @fsockopen($ip, $port, $errno, $error, $this->timeout) : @fsockopen($ip, $port, $errno, $error))))
|
|
950 |
return("");
|
231 |
951 |
}
|
232 |
|
if(strlen($this->exclude_address)
|
233 |
|
&& !strcmp(@gethostbyname($this->exclude_address),$ip))
|
234 |
|
return(sprintf(gettext("domain \"%s\" resolved to an address excluded to be valid"), $domain));
|
235 |
|
if($this->debug)
|
236 |
|
$this->OutputDebug(sprintf(gettext('Connecting to host address "%1$s" port %2$s...'), $ip, $port));
|
237 |
|
if(($this->connection=($this->timeout ? @fsockopen(($this->ssl ? "ssl://" : "").$ip,$port,$errno,$error,$this->timeout) : @fsockopen(($this->ssl ? "ssl://" : "").$ip,$port))))
|
238 |
|
return("");
|
239 |
952 |
$error=($this->timeout ? strval($error) : "??");
|
240 |
953 |
switch($error)
|
241 |
954 |
{
|
242 |
955 |
case "-3":
|
243 |
|
return(gettext("-3 socket could not be created"));
|
|
956 |
return("-3 socket could not be created");
|
244 |
957 |
case "-4":
|
245 |
|
return(sprintf(gettext("-4 dns lookup on hostname \"%s\" failed"), $domain));
|
|
958 |
return("-4 dns lookup on hostname \"".$domain."\" failed");
|
246 |
959 |
case "-5":
|
247 |
|
return(gettext("-5 connection refused or timed out"));
|
|
960 |
return("-5 connection refused or timed out");
|
248 |
961 |
case "-6":
|
249 |
|
return(gettext("-6 fdopen() call failed"));
|
|
962 |
return("-6 fdopen() call failed");
|
250 |
963 |
case "-7":
|
251 |
|
return(gettext("-7 setvbuf() call failed"));
|
|
964 |
return("-7 setvbuf() call failed");
|
252 |
965 |
}
|
253 |
|
return(sprintf(gettext('could not connect to the host "%1$s": %2$s'), $domain, $error));
|
|
966 |
return("could not connect to the host \"".$domain."\": ".$error);
|
254 |
967 |
}
|
255 |
968 |
|
256 |
969 |
Function SASLAuthenticate($mechanisms, $credentials, &$authenticated, &$mechanism)
|
... | ... | |
259 |
972 |
if(!function_exists("class_exists")
|
260 |
973 |
|| !class_exists("sasl_client_class"))
|
261 |
974 |
{
|
262 |
|
$this->error=gettext("it is not possible to authenticate using the specified mechanism because the SASL library class is not loaded");
|
|
975 |
$this->error="it is not possible to authenticate using the specified mechanism because the SASL library class is not loaded";
|
263 |
976 |
return(0);
|
264 |
977 |
}
|
265 |
978 |
$sasl=new sasl_client_class;
|
... | ... | |
283 |
996 |
case SASL_NOMECH:
|
284 |
997 |
if(strlen($this->authentication_mechanism))
|
285 |
998 |
{
|
286 |
|
$this->error=printf(gettext('authenticated mechanism %1$s may not be used: %2$s'), $this->authentication_mechanism, $sasl->error);
|
|
999 |
$this->error="authenticated mechanism ".$this->authentication_mechanism." may not be used: ".$sasl->error;
|
287 |
1000 |
return(0);
|
288 |
1001 |
}
|
289 |
1002 |
break;
|
290 |
1003 |
default:
|
291 |
|
$this->error=gettext("Could not start the SASL authentication client:") . " ".$sasl->error;
|
|
1004 |
$this->error="Could not start the SASL authentication client: ".$sasl->error;
|
292 |
1005 |
return(0);
|
293 |
1006 |
}
|
294 |
1007 |
if(strlen($mechanism=$sasl->mechanism))
|
295 |
1008 |
{
|
296 |
1009 |
if($this->PutLine("AUTH ".$sasl->mechanism.(IsSet($message) ? " ".base64_encode($message) : ""))==0)
|
297 |
1010 |
{
|
298 |
|
$this->error=gettext("Could not send the AUTH command");
|
|
1011 |
$this->error="Could not send the AUTH command";
|
299 |
1012 |
return(0);
|
300 |
1013 |
}
|
301 |
1014 |
if(!$this->VerifyResultLines(array("235","334"),$responses))
|
... | ... | |
310 |
1023 |
$response=base64_decode($responses[0]);
|
311 |
1024 |
break;
|
312 |
1025 |
default:
|
313 |
|
$this->error=gettext("Authentication error:") . " ".$responses[0];
|
|
1026 |
$this->error="Authentication error: ".$responses[0];
|
314 |
1027 |
return(0);
|
315 |
1028 |
}
|
316 |
1029 |
for(;!$authenticated;)
|
... | ... | |
325 |
1038 |
case SASL_CONTINUE:
|
326 |
1039 |
if($this->PutLine(base64_encode($message))==0)
|
327 |
1040 |
{
|
328 |
|
$this->error=gettext("Could not send the authentication step message");
|
|
1041 |
$this->error="Could not send the authentication step message";
|
329 |
1042 |
return(0);
|
330 |
1043 |
}
|
331 |
1044 |
if(!$this->VerifyResultLines(array("235","334"),$responses))
|
... | ... | |
340 |
1053 |
$response=base64_decode($responses[0]);
|
341 |
1054 |
break;
|
342 |
1055 |
default:
|
343 |
|
$this->error=gettext("Authentication error:") . " ".$responses[0];
|
|
1056 |
$this->error="Authentication error: ".$responses[0];
|
344 |
1057 |
return(0);
|
345 |
1058 |
}
|
346 |
1059 |
break;
|
347 |
1060 |
default:
|
348 |
|
$this->error=gettext("Could not process the SASL authentication step:") . " ".$sasl->error;
|
|
1061 |
$this->error="Could not process the SASL authentication step: ".$sasl->error;
|
349 |
1062 |
return(0);
|
350 |
1063 |
}
|
351 |
1064 |
}
|
352 |
1065 |
}
|
353 |
1066 |
return(1);
|
354 |
1067 |
}
|
|
1068 |
|
|
1069 |
Function StartSMTP($localhost)
|
|
1070 |
{
|
|
1071 |
$success = 1;
|
|
1072 |
$this->esmtp_extensions = array();
|
|
1073 |
$fallback=1;
|
|
1074 |
if($this->esmtp
|
|
1075 |
|| strlen($this->user))
|
|
1076 |
{
|
|
1077 |
if($this->PutLine('EHLO '.$localhost))
|
|
1078 |
{
|
|
1079 |
if(($success_code=$this->VerifyResultLines('250',$responses))>0)
|
|
1080 |
{
|
|
1081 |
$this->esmtp_host=$this->Tokenize($responses[0]," ");
|
|
1082 |
for($response=1;$response<count($responses);$response++)
|
|
1083 |
{
|
|
1084 |
$extension=strtoupper($this->Tokenize($responses[$response]," "));
|
|
1085 |
$this->esmtp_extensions[$extension]=$this->Tokenize("");
|
|
1086 |
}
|
|
1087 |
$success=1;
|
|
1088 |
$fallback=0;
|
|
1089 |
}
|
|
1090 |
else
|
|
1091 |
{
|
|
1092 |
if($success_code==0)
|
|
1093 |
{
|
|
1094 |
$code=$this->Tokenize($this->error," -");
|
|
1095 |
switch($code)
|
|
1096 |
{
|
|
1097 |
case "421":
|
|
1098 |
$fallback=0;
|
|
1099 |
break;
|
|
1100 |
}
|
|
1101 |
}
|
|
1102 |
}
|
|
1103 |
}
|
|
1104 |
else
|
|
1105 |
$fallback=0;
|
|
1106 |
}
|
|
1107 |
if($fallback)
|
|
1108 |
{
|
|
1109 |
if($this->PutLine("HELO $localhost")
|
|
1110 |
&& $this->VerifyResultLines("250",$responses)>0)
|
|
1111 |
$success=1;
|
|
1112 |
}
|
|
1113 |
return($success);
|
|
1114 |
}
|
355 |
1115 |
|
356 |
1116 |
/* Public methods */
|
357 |
1117 |
|
|
1118 |
/*
|
|
1119 |
{metadocument}
|
|
1120 |
<function>
|
|
1121 |
<name>Connect</name>
|
|
1122 |
<type>BOOLEAN</type>
|
|
1123 |
<documentation>
|
|
1124 |
<purpose>Connect to an SMTP server.</purpose>
|
|
1125 |
<usage>Call this function as first step to send e-mail messages.</usage>
|
|
1126 |
<returnvalue>The function returns
|
|
1127 |
<tt><booleanvalue>1</booleanvalue></tt> if the connection is
|
|
1128 |
successfully established.</returnvalue>
|
|
1129 |
</documentation>
|
|
1130 |
<argument>
|
|
1131 |
<name>domain</name>
|
|
1132 |
<type>STRING</type>
|
|
1133 |
<defaultvalue></defaultvalue>
|
|
1134 |
<documentation>
|
|
1135 |
<purpose>Specify the domain of the recipient when using the direct
|
|
1136 |
delivery mode.</purpose>
|
|
1137 |
</documentation>
|
|
1138 |
</argument>
|
|
1139 |
<do>
|
|
1140 |
{/metadocument}
|
|
1141 |
*/
|
358 |
1142 |
Function Connect($domain="")
|
359 |
1143 |
{
|
360 |
1144 |
if(strcmp($this->state,"Disconnected"))
|
361 |
1145 |
{
|
362 |
|
$this->error=gettext("connection is already established");
|
|
1146 |
$this->error="connection is already established";
|
363 |
1147 |
return(0);
|
364 |
1148 |
}
|
365 |
1149 |
$this->disconnected_error=0;
|
... | ... | |
397 |
1181 |
$user=$this->user;
|
398 |
1182 |
if(strlen($user)==0)
|
399 |
1183 |
{
|
400 |
|
$this->error=gettext("it was not specified the POP3 authentication user");
|
|
1184 |
$this->error="it was not specified the POP3 authentication user";
|
401 |
1185 |
return(0);
|
402 |
1186 |
}
|
403 |
1187 |
$password=$this->password;
|
404 |
1188 |
if(strlen($password)==0)
|
405 |
1189 |
{
|
406 |
|
$this->error=gettext("it was not specified the POP3 authentication password");
|
|
1190 |
$this->error="it was not specified the POP3 authentication password";
|
407 |
1191 |
return(0);
|
408 |
1192 |
}
|
409 |
1193 |
$domain=$this->pop3_auth_host;
|
410 |
|
$this->error=$this->ConnectToHost($domain, $this->pop3_auth_port, sprintf(gettext("Resolving POP3 authentication host \"%s\"..."), $domain));
|
|
1194 |
$this->error=$this->ConnectToHost($domain, $this->pop3_auth_port, "Resolving POP3 authentication host \"".$domain."\"...");
|
411 |
1195 |
if(strlen($this->error))
|
412 |
1196 |
return(0);
|
413 |
1197 |
if(strlen($response=$this->GetLine())==0)
|
414 |
1198 |
return(0);
|
415 |
1199 |
if(strcmp($this->Tokenize($response," "),"+OK"))
|
416 |
1200 |
{
|
417 |
|
$this->error=gettext("POP3 authentication server greeting was not found");
|
|
1201 |
$this->error="POP3 authentication server greeting was not found";
|
418 |
1202 |
return(0);
|
419 |
1203 |
}
|
420 |
1204 |
if(!$this->PutLine("USER ".$this->user)
|
... | ... | |
422 |
1206 |
return(0);
|
423 |
1207 |
if(strcmp($this->Tokenize($response," "),"+OK"))
|
424 |
1208 |
{
|
425 |
|
$this->error=gettext("POP3 authentication user was not accepted:") . " ".$this->Tokenize("\r\n");
|
|
1209 |
$this->error="POP3 authentication user was not accepted: ".$this->Tokenize("\r\n");
|
426 |
1210 |
return(0);
|
427 |
1211 |
}
|
428 |
1212 |
if(!$this->PutLine("PASS ".$password)
|
... | ... | |
430 |
1214 |
return(0);
|
431 |
1215 |
if(strcmp($this->Tokenize($response," "),"+OK"))
|
432 |
1216 |
{
|
433 |
|
$this->error=gettext("POP3 authentication password was not accepted:") . " ".$this->Tokenize("\r\n");
|
|
1217 |
$this->error="POP3 authentication password was not accepted: ".$this->Tokenize("\r\n");
|
434 |
1218 |
return(0);
|
435 |
1219 |
}
|
436 |
1220 |
fclose($this->connection);
|
... | ... | |
439 |
1223 |
}
|
440 |
1224 |
if(count($hosts)==0)
|
441 |
1225 |
{
|
442 |
|
$this->error=gettext("could not determine the SMTP to connect");
|
|
1226 |
$this->error="could not determine the SMTP to connect";
|
443 |
1227 |
return(0);
|
444 |
1228 |
}
|
445 |
1229 |
for($host=0, $error="not connected";strlen($error) && $host<count($hosts);$host++)
|
446 |
1230 |
{
|
447 |
1231 |
$domain=$hosts[$host];
|
448 |
|
$error=$this->ConnectToHost($domain, $this->host_port, sprintf(gettext("Resolving SMTP server domain \"%s\"..."), $domain));
|
|
1232 |
$error=$this->ConnectToHost($domain, $this->host_port, "Resolving SMTP server domain \"$domain\"...");
|
449 |
1233 |
}
|
450 |
1234 |
if(strlen($error))
|
451 |
1235 |
{
|
... | ... | |
457 |
1241 |
&& function_exists("socket_set_timeout"))
|
458 |
1242 |
socket_set_timeout($this->connection,$timeout,0);
|
459 |
1243 |
if($this->debug)
|
460 |
|
$this->OutputDebug(sprintf(gettext("Connected to SMTP server \"%s\"."), $domain));
|
|
1244 |
$this->OutputDebug("Connected to SMTP server \"".$domain."\".");
|
|
1245 |
if(!strcmp($localhost=$this->localhost,"")
|
|
1246 |
&& !strcmp($localhost=getenv("SERVER_NAME"),"")
|
|
1247 |
&& !strcmp($localhost=getenv("HOST"),""))
|
|
1248 |
$localhost="localhost";
|
|
1249 |
$success=0;
|
461 |
1250 |
if($this->VerifyResultLines("220",$responses)>0)
|
462 |
1251 |
{
|
463 |
|
// Send our HELLO
|
464 |
|
$success = $this->hello($this->hostname());
|
465 |
|
if ($this->tls)
|
466 |
|
$success = $this->startTLS();
|
467 |
|
|
|
1252 |
$success = $this->StartSMTP($localhost);
|
|
1253 |
if($this->start_tls)
|
|
1254 |
{
|
|
1255 |
if(!IsSet($this->esmtp_extensions["STARTTLS"]))
|
|
1256 |
{
|
|
1257 |
$this->error="server does not support starting TLS";
|
|
1258 |
$success=0;
|
|
1259 |
}
|
|
1260 |
elseif(!function_exists('stream_socket_enable_crypto'))
|
|
1261 |
{
|
|
1262 |
$this->error="this PHP installation or version does not support starting TLS";
|
|
1263 |
$success=0;
|
|
1264 |
}
|
|
1265 |
elseif($success = ($this->PutLine('STARTTLS')
|
|
1266 |
&& $this->VerifyResultLines('220',$responses)>0))
|
|
1267 |
{
|
|
1268 |
$this->OutputDebug('Starting TLS cryptograpic protocol');
|
|
1269 |
if(!($success = stream_socket_enable_crypto($this->connection, 1, STREAM_CRYPTO_METHOD_TLS_CLIENT)))
|
|
1270 |
$this->error = 'could not start TLS connection encryption protocol';
|
|
1271 |
else
|
|
1272 |
{
|
|
1273 |
$this->OutputDebug('TLS started');
|
|
1274 |
$success = $this->StartSMTP($localhost);
|
|
1275 |
}
|
|
1276 |
}
|
|
1277 |
}
|
468 |
1278 |
if($success
|
469 |
1279 |
&& strlen($this->user)
|
470 |
1280 |
&& strlen($this->pop3_auth_host)==0)
|
471 |
1281 |
{
|
472 |
1282 |
if(!IsSet($this->esmtp_extensions["AUTH"]))
|
473 |
1283 |
{
|
474 |
|
$this->error = gettext("server does not require authentication");
|
|
1284 |
$this->error="server does not require authentication";
|
|
1285 |
if(IsSet($this->esmtp_extensions["STARTTLS"]))
|
|
1286 |
$this->error .= ', it probably requires starting TLS';
|
475 |
1287 |
$success=0;
|
476 |
1288 |
}
|
477 |
1289 |
else
|
... | ... | |
535 |
1347 |
if($success
|
536 |
1348 |
&& strlen($mechanism)==0)
|
537 |
1349 |
{
|
538 |
|
$this->error=gettext("it is not supported any of the authentication mechanisms required by the server");
|
|
1350 |
$this->error="it is not supported any of the authentication mechanisms required by the server";
|
539 |
1351 |
$success=0;
|
540 |
1352 |
}
|
541 |
1353 |
}
|
... | ... | |
553 |
1365 |
}
|
554 |
1366 |
return($success);
|
555 |
1367 |
}
|
|
1368 |
/*
|
|
1369 |
{metadocument}
|
|
1370 |
</do>
|
|
1371 |
</function>
|
|
1372 |
{/metadocument}
|
|
1373 |
*/
|
556 |
1374 |
|
557 |
|
Function hostname() {
|
558 |
|
if(!strcmp($localhost=$this->localhost,"")
|
559 |
|
&& !strcmp($localhost=getenv("SERVER_NAME"),"")
|
560 |
|
&& !strcmp($localhost=getenv("HOST"),"")
|
561 |
|
&& !strcmp($localhost=getenv("HOSTNAME"),"")
|
562 |
|
&& !strcmp($localhost=gethostname(),""))
|
563 |
|
$localhost="localhost";
|
564 |
|
|
565 |
|
return $localhost;
|
566 |
|
}
|
567 |
|
|
568 |
|
Function hello()
|
569 |
|
{
|
570 |
|
$success = 0;
|
571 |
|
$fallback = 1;
|
572 |
|
if ($this->esmtp || strlen($this->user)) {
|
573 |
|
if ($this->PutLine("EHLO ".$this->hostname())) {
|
574 |
|
if (($success_code = $this->VerifyResultLines("250",$responses)) > 0) {
|
575 |
|
$this->esmtp_host = $this->Tokenize($responses[0]," ");
|
576 |
|
for($response=1;$response<count($responses);$response++) {
|
577 |
|
$extension = strtoupper($this->Tokenize($responses[$response]," "));
|
578 |
|
$this->esmtp_extensions[$extension]=$this->Tokenize("");
|
579 |
|
}
|
580 |
|
$success = 1;
|
581 |
|
$fallback = 0;
|
582 |
|
} else {
|
583 |
|
if ($success_code == 0) {
|
584 |
|
$code = $this->Tokenize($this->error," -");
|
585 |
|
switch($code) {
|
586 |
|
case "421":
|
587 |
|
$fallback=0;
|
588 |
|
break;
|
589 |
|
}
|
590 |
|
}
|
591 |
|
}
|
592 |
|
} else
|
593 |
|
$fallback=0;
|
594 |
|
}
|
595 |
|
|
596 |
|
if ($fallback) {
|
597 |
|
if ($this->PutLine("HELO $localhost") && $this->VerifyResultLines("250",$responses)>0)
|
598 |
|
$success=1;
|
599 |
|
}
|
600 |
|
return $success;
|
601 |
|
}
|
602 |
|
|
603 |
|
Function startTLS() {
|
604 |
|
if ($this->PutLine("STARTTLS") && $this->VerifyResultLines("220",$responses)>0) {
|
605 |
|
if (!stream_socket_enable_crypto($this->connection,true,STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
|
606 |
|
return false;
|
607 |
|
} else {
|
608 |
|
// Resend HELO since session has been reset
|
609 |
|
return $this->hello($this->hostname);
|
610 |
|
}
|
611 |
|
} else
|
612 |
|
return false;
|
613 |
|
}
|
614 |
|
|
|
1375 |
/*
|
|
1376 |
{metadocument}
|
|
1377 |
<function>
|
|
1378 |
<name>MailFrom</name>
|
|
1379 |
<type>BOOLEAN</type>
|
|
1380 |
<documentation>
|
|
1381 |
<purpose>Set the address of the message sender.</purpose>
|
|
1382 |
<usage>Call this function right after establishing a connection with
|
|
1383 |
the <functionlink>Connect</functionlink> function.</usage>
|
|
1384 |
<returnvalue>The function returns
|
|
1385 |
<tt><booleanvalue>1</booleanvalue></tt> if the sender address is
|
|
1386 |
successfully set.</returnvalue>
|
|
1387 |
</documentation>
|
|
1388 |
<argument>
|
|
1389 |
<name>sender</name>
|
|
1390 |
<type>STRING</type>
|
|
1391 |
<documentation>
|
|
1392 |
<purpose>E-mail address of the sender.</purpose>
|
|
1393 |
</documentation>
|
|
1394 |
</argument>
|
|
1395 |
<do>
|
|
1396 |
{/metadocument}
|
|
1397 |
*/
|
615 |
1398 |
Function MailFrom($sender)
|
616 |
1399 |
{
|
617 |
1400 |
if($this->direct_delivery)
|
... | ... | |
625 |
1408 |
$sender=$this->direct_sender;
|
626 |
1409 |
break;
|
627 |
1410 |
default:
|
628 |
|
$this->error=gettext("direct delivery connection is already established and sender is already set");
|
|
1411 |
$this->error="direct delivery connection is already established and sender is already set";
|
629 |
1412 |
return(0);
|
630 |
1413 |
}
|
631 |
1414 |
}
|
... | ... | |
633 |
1416 |
{
|
634 |
1417 |
if(strcmp($this->state,"Connected"))
|
635 |
1418 |
{
|
636 |
|
$this->error=gettext("connection is not in the initial state");
|
|
1419 |
$this->error="connection is not in the initial state";
|
637 |
1420 |
return(0);
|
638 |
1421 |
}
|
639 |
1422 |
}
|
... | ... | |
649 |
1432 |
$this->pending_recipients=0;
|
650 |
1433 |
return(1);
|
651 |
1434 |
}
|
|
1435 |
/*
|
|
1436 |
{metadocument}
|
|
1437 |
</do>
|
|
1438 |
</function>
|
|
1439 |
{/metadocument}
|
|
1440 |
*/
|
652 |
1441 |
|
|
1442 |
/*
|
|
1443 |
{metadocument}
|
|
1444 |
<function>
|
|
1445 |
<name>SetRecipient</name>
|
|
1446 |
<type>BOOLEAN</type>
|
|
1447 |
<documentation>
|
|
1448 |
<purpose>Set the address of a message recipient.</purpose>
|
|
1449 |
<usage>Call this function repeatedly for each recipient right after
|
|
1450 |
setting the message sender with the
|
|
1451 |
<functionlink>MailFrom</functionlink> function.</usage>
|
|
1452 |
<returnvalue>The function returns
|
|
1453 |
<tt><booleanvalue>1</booleanvalue></tt> if the recipient address is
|
|
1454 |
successfully set.</returnvalue>
|
|
1455 |
</documentation>
|
|
1456 |
<argument>
|
|
1457 |
<name>recipient</name>
|
|
1458 |
<type>STRING</type>
|
|
1459 |
<documentation>
|
|
1460 |
<purpose>E-mail address of a recipient.</purpose>
|
|
1461 |
</documentation>
|
|
1462 |
</argument>
|
|
1463 |
<do>
|
|
1464 |
{/metadocument}
|
|
1465 |
*/
|
653 |
1466 |
Function SetRecipient($recipient)
|
654 |
1467 |
{
|
655 |
1468 |
if($this->direct_delivery)
|
656 |
1469 |
{
|
657 |
1470 |
if(GetType($at=strrpos($recipient,"@"))!="integer")
|
658 |
|
return(gettext("it was not specified a valid direct recipient"));
|
|
1471 |
return("it was not specified a valid direct recipient");
|
659 |
1472 |
$domain=substr($recipient,$at+1);
|
660 |
1473 |
switch($this->state)
|
661 |
1474 |
{
|
... | ... | |
674 |
1487 |
case "RecipientSet":
|
675 |
1488 |
if(strcmp($this->connected_domain,$domain))
|
676 |
1489 |
{
|
677 |
|
$this->error=gettext("it is not possible to deliver directly to recipients of different domains");
|
|
1490 |
$this->error="it is not possible to deliver directly to recipients of different domains";
|
678 |
1491 |
return(0);
|
679 |
1492 |
}
|
680 |
1493 |
break;
|
681 |
1494 |
default:
|
682 |
|
$this->error=gettext("connection is already established and the recipient is already set");
|
|
1495 |
$this->error="connection is already established and the recipient is already set";
|
683 |
1496 |
return(0);
|
684 |
1497 |
}
|
685 |
1498 |
}
|
... | ... | |
691 |
1504 |
case "RecipientSet":
|
692 |
1505 |
break;
|
693 |
1506 |
default:
|
694 |
|
$this->error=gettext("connection is not in the recipient setting state");
|
|
1507 |
$this->error="connection is not in the recipient setting state";
|
695 |
1508 |
return(0);
|
696 |
1509 |
}
|
697 |
1510 |
}
|
... | ... | |
715 |
1528 |
$this->state="RecipientSet";
|
716 |
1529 |
return(1);
|
717 |
1530 |
}
|
|
1531 |
/*
|
|
1532 |
{metadocument}
|
|
1533 |
</do>
|
|
1534 |
</function>
|
|
1535 |
{/metadocument}
|
|
1536 |
*/
|
718 |
1537 |
|
|
1538 |
/*
|
|
1539 |
{metadocument}
|
|
1540 |
<function>
|
|
1541 |
<name>StartData</name>
|
|
1542 |
<type>BOOLEAN</type>
|
|
1543 |
<documentation>
|
|
1544 |
<purpose>Tell the SMTP server that the message data will start being
|
|
1545 |
sent.</purpose>
|
|
1546 |
<usage>Call this function right after you are done setting all the
|
|
1547 |
message recipients with the
|
|
1548 |
<functionlink>SetRecipient</functionlink> function.</usage>
|
|
1549 |
<returnvalue>The function returns
|
|
1550 |
<tt><booleanvalue>1</booleanvalue></tt> if the server is ready to
|
|
1551 |
start receiving the message data.</returnvalue>
|
|
1552 |
</documentation>
|
|
1553 |
<do>
|
|
1554 |
{/metadocument}
|
|
1555 |
*/
|
719 |
1556 |
Function StartData()
|
720 |
1557 |
{
|
721 |
1558 |
if(strcmp($this->state,"RecipientSet"))
|
722 |
1559 |
{
|
723 |
|
$this->error=gettext("connection is not in the start sending data state");
|
|
1560 |
$this->error="connection is not in the start sending data state";
|
724 |
1561 |
return(0);
|
725 |
1562 |
}
|
726 |
1563 |
$this->error="";
|
... | ... | |
736 |
1573 |
$this->state="SendingData";
|
737 |
1574 |
return(1);
|
738 |
1575 |
}
|
|
1576 |
/*
|
|
1577 |
{metadocument}
|
|
1578 |
</do>
|
|
1579 |
</function>
|
|
1580 |
{/metadocument}
|
|
1581 |
*/
|
739 |
1582 |
|
740 |
|
Function PrepareData(&$data,&$output,$preg=1)
|
|
1583 |
/*
|
|
1584 |
{metadocument}
|
|
1585 |
<function>
|
|
1586 |
<name>PrepareData</name>
|
|
1587 |
<type>STRING</type>
|
|
1588 |
<documentation>
|
|
1589 |
<purpose>Prepare message data to normalize line breaks and escaping
|
|
1590 |
lines that contain single dots.</purpose>
|
|
1591 |
<usage>Call this function if the message data you want to send may
|
|
1592 |
contain line breaks that are not the
|
|
1593 |
<stringvalue> </stringvalue> sequence or it may contain
|
|
1594 |
lines that just have a single dot.</usage>
|
|
1595 |
<returnvalue>Resulting normalized messages data.</returnvalue>
|
|
1596 |
</documentation>
|
|
1597 |
<argument>
|
|
1598 |
<name>data</name>
|
|
1599 |
<type>STRING</type>
|
|
1600 |
<documentation>
|
|
1601 |
<purpose>Message data to be prepared.</purpose>
|
|
1602 |
</documentation>
|
|
1603 |
</argument>
|
|
1604 |
<do>
|
|
1605 |
{/metadocument}
|
|
1606 |
*/
|
|
1607 |
Function PrepareData($data)
|
741 |
1608 |
{
|
742 |
|
if($preg
|
743 |
|
&& function_exists("preg_replace"))
|
744 |
|
$output=preg_replace(array("/\n\n|\r\r/","/(^|[^\r])\n/","/\r([^\n]|\$)/D","/(^|\n)\\./"),array("\r\n\r\n","\\1\r\n","\r\n\\1","\\1.."),$data);
|
745 |
|
else
|
746 |
|
$output=ereg_replace("(^|\n)\\.","\\1..",ereg_replace("\r([^\n]|\$)","\r\n\\1",ereg_replace("(^|[^\r])\n","\\1\r\n",ereg_replace("\n\n|\r\r","\r\n\r\n",$data))));
|
|
1609 |
return(preg_replace(array("/\n\n|\r\r/","/(^|[^\r])\n/","/\r([^\n]|\$)/D","/(^|\n)\\./"),array("\r\n\r\n","\\1\r\n","\r\n\\1","\\1.."),$data));
|
747 |
1610 |
}
|
|
1611 |
/*
|
|
1612 |
{metadocument}
|
|
1613 |
</do>
|
|
1614 |
</function>
|
|
1615 |
{/metadocument}
|
|
1616 |
*/
|
748 |
1617 |
|
|
1618 |
/*
|
|
1619 |
{metadocument}
|
|
1620 |
<function>
|
|
1621 |
<name>SendData</name>
|
|
1622 |
<type>BOOLEAN</type>
|
|
1623 |
<documentation>
|
|
1624 |
<purpose>Send message data.</purpose>
|
|
1625 |
<usage>Call this function repeatedly for all message data blocks
|
|
1626 |
to be sent right after start sending message data with the
|
|
1627 |
<functionlink>StartData</functionlink> function.</usage>
|
|
1628 |
<returnvalue>The function returns
|
|
1629 |
<tt><booleanvalue>1</booleanvalue></tt> if the message data was
|
|
1630 |
sent to the SMTP server successfully.</returnvalue>
|
|
1631 |
</documentation>
|
|
1632 |
<argument>
|
|
1633 |
<name>data</name>
|
|
1634 |
<type>STRING</type>
|
|
1635 |
<documentation>
|
|
1636 |
<purpose>Message data to be sent.</purpose>
|
|
1637 |
</documentation>
|
|
1638 |
</argument>
|
|
1639 |
<do>
|
|
1640 |
{/metadocument}
|
|
1641 |
*/
|
749 |
1642 |
Function SendData($data)
|
750 |
1643 |
{
|
751 |
1644 |
if(strcmp($this->state,"SendingData"))
|
752 |
1645 |
{
|
753 |
|
$this->error=gettext("connection is not in the sending data state");
|
|
1646 |
$this->error="connection is not in the sending data state";
|
754 |
1647 |
return(0);
|
755 |
1648 |
}
|
756 |
1649 |
$this->error="";
|
757 |
1650 |
return($this->PutData($data));
|
758 |
1651 |
}
|
|
1652 |
/*
|
|
1653 |
{metadocument}
|
|
1654 |
</do>
|
|
1655 |
</function>
|
|
1656 |
{/metadocument}
|
Update smtp class to latest version, fixes #5604
- SMTP class from
http://www.phpclasses.org/package/14-PHP-Sends-e-mail-messages-via-SMTP-protocol.html
- Adapt code to current version, only change was tls parameter became
start_tls