Fix the way that SMTP host lists are parsed, see #112

This commit is contained in:
Synchro 2013-09-24 14:35:34 +02:00
parent accd948dad
commit 70ba3fbc0f
3 changed files with 27 additions and 8 deletions

View File

@ -6,6 +6,7 @@
* Chinese language update (Thanks to @binaryoung)
* Allow custom Mailer types (thanks to @michield)
* Cope with spaces around SMTP host specs
* Fix processing of multiple hosts in connect string
## Version 5.2.7 (September 12th 2013)
* Add Ukranian translation from @Krezalis

View File

@ -1242,18 +1242,36 @@ class PHPMailer
$this->smtp->setDebugLevel($this->SMTPDebug);
$this->smtp->setDebugOutput($this->Debugoutput);
$this->smtp->setVerp($this->do_verp);
$tls = ($this->SMTPSecure == 'tls');
$ssl = ($this->SMTPSecure == 'ssl');
$hosts = explode(';', $this->Host);
$lastexception = null;
foreach ($hosts as $hostentry) {
$host = trim($hostentry);
$port = $this->Port;
if (strpos($host, ':') !== false) {
list($host, $port) = explode(':', $host);
$hostinfo = array();
if (!preg_match('/^((ssl|tls):\/\/)*([a-zA-Z0-9\.-]*):?([0-9]*)$/', trim($hostentry), $hostinfo)) {
//Not a valid host entry
continue;
}
if ($this->smtp->connect(($ssl ? 'ssl://' : '') . $host, $port, $this->Timeout, $options)) {
//$hostinfo[2]: optional ssl or tls prefix
//$hostinfo[3]: the hostname
//$hostinfo[4]: optional port number
//The host string prefix can temporarily override the current setting for SMTPSecure
//If it's not specified, the default value is used
$prefix = '';
$tls = ($this->SMTPSecure == 'tls');
if ($hostinfo[2] == 'ssl') {
$prefix = 'ssl://';
$tls = false; //Can't have SSL and TLS at once
} elseif ($hostinfo[2] == 'tls') {
$tls = true;
//tls doesn't use a prefix
}
$host = $hostinfo[3];
$port = $this->Port;
$tport = (integer)$hostinfo[4];
if ($tport > 0 and $tport < 65536) {
$port = $tport;
}
if ($this->smtp->connect($prefix . $host, $port, $this->Timeout, $options)) {
try {
if ($this->Helo) {
$hello = $this->Helo;

View File

@ -1033,7 +1033,7 @@ EOT;
{
$this->assertTrue($this->Mail->smtpConnect(), 'SMTP single connect failed');
$this->Mail->smtpClose();
$this->Mail->Host = "localhost:12345;10.10.10.10:54321";
$this->Mail->Host = "ssl://localhost:12345;tls://localhost:587;10.10.10.10:54321;localhost:12345;10.10.10.10";
$this->assertFalse($this->Mail->smtpConnect(), 'SMTP bad multi-connect succeeded');
$this->Mail->smtpClose();
$this->Mail->Host = "localhost:12345;10.10.10.10:54321;" . $_REQUEST['mail_host'];