Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'feature/router' of github.com:DASPRiD/zf2 into feature/…
Browse files Browse the repository at this point in the history
…router
  • Loading branch information
DASPRiD committed Oct 29, 2011
15 parents 84a7972 + f6501d5 + 74b0454 + ea99bf1 + e2703e7 + 90db7ae + b2f5380 + d6ee2dd + 2dae9df + 15a2e1f + 00d7ef1 + 88e29ab + 04f5596 + a566cb1 + d4b9187 commit 83cb40e
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 14 deletions.
47 changes: 41 additions & 6 deletions src/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,19 @@ class Mail extends Mime\Message

/**#@-*/

/**
* Mail transport object
*
* @var \Zend\Mail\AbstractTransport
*/
protected $transport = null;

/**
* Flag: whether or not email has attachments
* @var boolean
*/
public $hasAttachments = false;


/**
* Sets the default mail transport for all following uses of
* Zend_Mail::send();
Expand All @@ -185,6 +191,10 @@ public static function setDefaultTransport(AbstractTransport $transport)
*/
public static function getDefaultTransport()
{
if (! self::$_defaultTransport instanceof AbstractTransport) {
$transport = new Transport\Sendmail();
}

return self::$_defaultTransport;
}

Expand All @@ -209,6 +219,35 @@ public function __construct($charset = null)
}
}

/**
* Set the transport object
*
* @param AbstractTransport $transport
* @return \Zend\Mail\Mail
*/
public function setTransport(AbstractTransport $transport)
{
$this->transport = $transport;
return $this;
}

/**
* Get transport object
*
* If no transport object is set, will set and return the global default
* transport object
*
* @return \Zend\Mail\AbstractTransport
*/
public function getTransport()
{
if (! $this->transport) {
$this->transport = self::getDefaultTransport();
}

return $this->transport;
}

/**
* Return charset string
*
Expand Down Expand Up @@ -1086,11 +1125,7 @@ public function getHeaders()
public function send($transport = null)
{
if ($transport === null) {
if (! self::$_defaultTransport instanceof AbstractTransport) {
$transport = new Transport\Sendmail();
} else {
$transport = self::$_defaultTransport;
}
$transport = $this->getTransport();
}

if ($this->_date === null) {
Expand Down
22 changes: 20 additions & 2 deletions src/Transport/Smtp.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,21 @@ class Smtp extends AbstractTransport
* with the SendMail transport class.
*/
public function __construct($host = '127.0.0.1', Array $config = array())
{
if ($host) {
$config['host'] = $host;
}

$this->setConfig($config);
}

/**
* Set configuration
*
* @param array $config
* @return \Zend\Mail\Transport\Smtp
*/
public function setConfig(array $config)
{
if (isset($config['name'])) {
$this->_name = $config['name'];
Expand All @@ -124,11 +139,14 @@ public function __construct($host = '127.0.0.1', Array $config = array())
if (isset($config['auth'])) {
$this->_auth = $config['auth'];
}
if (isset($config['host'])) {
$this->_host = $config['host'];
}

$this->_host = $host;
$this->_config = $config;
}

return $this;
}

/**
* Class destructor to ensure all open connections are closed
Expand Down
13 changes: 7 additions & 6 deletions test/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Zend\Mail\Message;
use Zend\Mime;
use Zend\Mail\Storage;
use Zend\Mail\Exception;

/**
* @category Zend
Expand Down Expand Up @@ -173,7 +174,7 @@ public function testInvalidMailHandler()
{
try {
$message = new Message(array('handler' => 1));
} catch (\Zend\Mime\Exception $e) {
} catch (Exception\InvalidArgumentException $e) {
return; // ok
}

Expand All @@ -187,7 +188,7 @@ public function testMissingId()

try {
$message = new Message(array('handler' => $mail));
} catch (\Zend\Mime\Exception $e) {
} catch (Exception\InvalidArgumentException $e) {
return; // ok
}

Expand Down Expand Up @@ -268,7 +269,7 @@ public function testNoContent()

try {
$message->getContent();
} catch (\Zend\Mime\Exception $e) {
} catch (Exception\RuntimeException $e) {
return; // ok
}

Expand All @@ -284,7 +285,7 @@ public function testEmptyHeader()
$subject = null;
try {
$subject = $message->subject;
} catch (\Zend\Mime\Exception $e) {
} catch (Exception\InvalidArgumentException $e) {
// ok
}
if ($subject) {
Expand All @@ -298,7 +299,7 @@ public function testEmptyBody()
$part = null;
try {
$part = $message->getPart(1);
} catch (\Zend\Mime\Exception $e) {
} catch (Exception\RuntimeException $e) {
// ok
}
if ($part) {
Expand Down Expand Up @@ -329,7 +330,7 @@ public function testWrongMultipart()

try {
$message->getPart(1);
} catch (\Zend\Mime\Exception $e) {
} catch (Exception\RuntimeException $e) {
return; // ok
}
$this->fail('no exception raised while getting part from message without boundary');
Expand Down

0 comments on commit 83cb40e

Please sign in to comment.