Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 8, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions library/Zend/Mail/Protocol/Smtp.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,15 @@ public function helo($host = '127.0.0.1')
$this->auth();
}

/**
* Returns the perceived session status
*
* @return boolean
*/
public function hasSession()
{
return $this->sess;
}

/**
* Send EHLO or HELO depending on capabilities of smtp host
Expand Down Expand Up @@ -367,6 +376,7 @@ public function auth()
*/
public function disconnect()
{
$this->quit();
$this->_disconnect();
}

Expand Down
20 changes: 16 additions & 4 deletions library/Zend/Mail/Transport/Smtp.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,8 @@ public function send(Message $message)
// If sending multiple messages per session use existing adapter
$connection = $this->getConnection();

if (!($connection instanceof Protocol\Smtp)) {
// First time connecting
$connection = $this->lazyLoadConnection();
if (!($connection instanceof Protocol\Smtp) || !$connection->hasSession()) {
$connection = $this->connect();
} else {
// Reset connection to ensure reliable transaction
$connection->rset();
Expand Down Expand Up @@ -322,8 +321,21 @@ protected function lazyLoadConnection()
$config['port'] = $options->getPort();
$connection = $this->plugin($options->getConnectionClass(), $config);
$this->connection = $connection;
return $this->connect();
}

/**
* Connect the connection, and pass it helo
*
* @return Protocol\Smtp
*/
protected function connect()
{
if (!$this->connection instanceof Protocol\Smtp) {
$this->lazyLoadConnection();
}
$this->connection->connect();
$this->connection->helo($options->getName());
$this->connection->helo($this->getOptions()->getName());
return $this->connection;
}
}
2 changes: 1 addition & 1 deletion tests/ZendTest/Mail/Protocol/SmtpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function testSendMinimalMail()
->setBody('testSendMailWithoutMinimalHeaders')
->addTo('[email protected]', 'ZF DevTeam')
;
$expectedMessage = "RSET\r\n"
$expectedMessage = "EHLO localhost\r\n"
. "MAIL FROM:<[email protected]>\r\n"
. "DATA\r\n"
. "Date: Sun, 10 Jun 2012 20:07:24 +0200\r\n"
Expand Down
15 changes: 7 additions & 8 deletions tests/ZendTest/Mail/TestAsset/SmtpProtocolSpy.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,27 @@ class SmtpProtocolSpy extends Smtp
protected $connect = false;
protected $mail;
protected $rcptTest = array();
protected $sess = true;

public function connect()
{
$this->connect = true;
return true;
}

public function helo($serverName = '127.0.0.1')
public function disconnect()
{
parent::helo($serverName);
$this->connect = false;
parent::disconnect();
}

public function quit()
public function helo($serverName = '127.0.0.1')
{
$this->rset();
parent::helo($serverName);
}

public function disconnect()
public function quit()
{
$this->connect = false;
$this->rset();
parent::quit();
}

public function rset()
Expand Down
14 changes: 13 additions & 1 deletion tests/ZendTest/Mail/Transport/SmtpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public function testAutoDisconnectTrue()
{
$this->connection->connect();
unset($this->transport);
$this->assertFalse($this->connection->isConnected());
$this->assertFalse($this->connection->hasSession());
}

public function testAutoDisconnectFalse()
Expand All @@ -175,4 +175,16 @@ public function testDisconnect()
$this->transport->disconnect();
$this->assertFalse($this->connection->isConnected());
}

public function testDisconnectSendReconnects()
{
$this->assertFalse($this->connection->hasSession());
$this->transport->send($this->getMessage());
$this->assertTrue($this->connection->hasSession());
$this->connection->disconnect();

$this->assertFalse($this->connection->hasSession());
$this->transport->send($this->getMessage());
$this->assertTrue($this->connection->hasSession());
}
}