Revision 1cddd59c
Added by Warren Baker almost 12 years ago
etc/inc/smtp.inc | ||
---|---|---|
20 | 20 |
var $host_name=""; |
21 | 21 |
var $host_port=25; |
22 | 22 |
var $ssl=0; |
23 |
var $tls=0; |
|
23 | 24 |
var $localhost=""; |
24 | 25 |
var $timeout=0; |
25 | 26 |
var $data_timeout=0; |
... | ... | |
213 | 214 |
|
214 | 215 |
Function ConnectToHost($domain, $port, $resolve_message) |
215 | 216 |
{ |
216 |
if($this->ssl) |
|
217 |
if($this->ssl || $this->tls)
|
|
217 | 218 |
{ |
218 | 219 |
$version=explode(".",function_exists("phpversion") ? phpversion() : "3.0.7"); |
219 | 220 |
$php_version=intval($version[0])*1000000+intval($version[1])*1000+intval($version[2]); |
... | ... | |
461 | 462 |
socket_set_timeout($this->connection,$timeout,0); |
462 | 463 |
if($this->debug) |
463 | 464 |
$this->OutputDebug(sprintf(gettext("Connected to SMTP server \"%s\"."), $domain)); |
464 |
if(!strcmp($localhost=$this->localhost,"") |
|
465 |
&& !strcmp($localhost=getenv("SERVER_NAME"),"") |
|
466 |
&& !strcmp($localhost=getenv("HOST"),"") |
|
467 |
&& !strcmp($localhost=getenv("HOSTNAME"),"") |
|
468 |
&& !strcmp($localhost=exec("/bin/hostname"),"")) |
|
469 |
$localhost="localhost"; |
|
470 |
$success=0; |
|
471 | 465 |
if($this->VerifyResultLines("220",$responses)>0) |
472 | 466 |
{ |
473 |
$fallback=1; |
|
474 |
if($this->esmtp |
|
475 |
|| strlen($this->user)) |
|
476 |
{ |
|
477 |
if($this->PutLine("EHLO $localhost")) |
|
478 |
{ |
|
479 |
if(($success_code=$this->VerifyResultLines("250",$responses))>0) |
|
480 |
{ |
|
481 |
$this->esmtp_host=$this->Tokenize($responses[0]," "); |
|
482 |
for($response=1;$response<count($responses);$response++) |
|
483 |
{ |
|
484 |
$extension=strtoupper($this->Tokenize($responses[$response]," ")); |
|
485 |
$this->esmtp_extensions[$extension]=$this->Tokenize(""); |
|
486 |
} |
|
487 |
$success=1; |
|
488 |
$fallback=0; |
|
489 |
} |
|
490 |
else |
|
491 |
{ |
|
492 |
if($success_code==0) |
|
493 |
{ |
|
494 |
$code=$this->Tokenize($this->error," -"); |
|
495 |
switch($code) |
|
496 |
{ |
|
497 |
case "421": |
|
498 |
$fallback=0; |
|
499 |
break; |
|
500 |
} |
|
501 |
} |
|
502 |
} |
|
503 |
} |
|
504 |
else |
|
505 |
$fallback=0; |
|
506 |
} |
|
507 |
if($fallback) |
|
508 |
{ |
|
509 |
if($this->PutLine("HELO $localhost") |
|
510 |
&& $this->VerifyResultLines("250",$responses)>0) |
|
511 |
$success=1; |
|
512 |
} |
|
467 |
// Send our HELLO |
|
468 |
$success = $this->hello($this->hostname()); |
|
469 |
if ($this->tls) |
|
470 |
$success = $this->startTLS(); |
|
471 |
|
|
513 | 472 |
if($success |
514 | 473 |
&& strlen($this->user) |
515 | 474 |
&& strlen($this->pop3_auth_host)==0) |
516 | 475 |
{ |
517 | 476 |
if(!IsSet($this->esmtp_extensions["AUTH"])) |
518 | 477 |
{ |
519 |
$this->error=gettext("server does not require authentication");
|
|
478 |
$this->error = gettext("server does not require authentication");
|
|
520 | 479 |
$success=0; |
521 | 480 |
} |
522 | 481 |
else |
... | ... | |
599 | 558 |
return($success); |
600 | 559 |
} |
601 | 560 |
|
561 |
Function hostname() { |
|
562 |
if(!strcmp($localhost=$this->localhost,"") |
|
563 |
&& !strcmp($localhost=getenv("SERVER_NAME"),"") |
|
564 |
&& !strcmp($localhost=getenv("HOST"),"") |
|
565 |
&& !strcmp($localhost=getenv("HOSTNAME"),"") |
|
566 |
&& !strcmp($localhost=exec("/bin/hostname"),"")) |
|
567 |
$localhost="localhost"; |
|
568 |
|
|
569 |
return $localhost; |
|
570 |
} |
|
571 |
|
|
572 |
Function hello() |
|
573 |
{ |
|
574 |
$success = 0; |
|
575 |
$fallback = 1; |
|
576 |
if ($this->esmtp || strlen($this->user)) { |
|
577 |
if ($this->PutLine("EHLO ".$this->hostname())) { |
|
578 |
if (($success_code = $this->VerifyResultLines("250",$responses)) > 0) { |
|
579 |
$this->esmtp_host = $this->Tokenize($responses[0]," "); |
|
580 |
for($response=1;$response<count($responses);$response++) { |
|
581 |
$extension = strtoupper($this->Tokenize($responses[$response]," ")); |
|
582 |
$this->esmtp_extensions[$extension]=$this->Tokenize(""); |
|
583 |
} |
|
584 |
$success = 1; |
|
585 |
$fallback = 0; |
|
586 |
} else { |
|
587 |
if ($success_code == 0) { |
|
588 |
$code = $this->Tokenize($this->error," -"); |
|
589 |
switch($code) { |
|
590 |
case "421": |
|
591 |
$fallback=0; |
|
592 |
break; |
|
593 |
} |
|
594 |
} |
|
595 |
} |
|
596 |
} else |
|
597 |
$fallback=0; |
|
598 |
} |
|
599 |
|
|
600 |
if ($fallback) { |
|
601 |
if ($this->PutLine("HELO $localhost") && $this->VerifyResultLines("250",$responses)>0) |
|
602 |
$success=1; |
|
603 |
} |
|
604 |
return $success; |
|
605 |
} |
|
606 |
|
|
607 |
Function startTLS() { |
|
608 |
if ($this->PutLine("STARTTLS") && $this->VerifyResultLines("220",$responses)>0) { |
|
609 |
if (!stream_socket_enable_crypto($this->connection,true,STREAM_CRYPTO_METHOD_TLS_CLIENT)) { |
|
610 |
return false; |
|
611 |
} else { |
|
612 |
// Resend HELO since session has been reset |
|
613 |
return $this->hello($this->hostname); |
|
614 |
} |
|
615 |
} else |
|
616 |
return false; |
|
617 |
} |
|
618 |
|
|
602 | 619 |
Function MailFrom($sender) |
603 | 620 |
{ |
604 | 621 |
if($this->direct_delivery) |
Also available in: Unified diff
Split SSL/TLS into separate checkboxes so that plaintext connections can be made secured by using STARTTLS. Support for SMTPS connections should probably be done away with in future. Fixes #3180