Permalink
Browse files

Merge branch 'hotfix/mail-allow-di' of https://github.com/shevron/zf2

…into hotfix/mail-di
  • Loading branch information...
2 parents 0846d6b + 5115ec6 commit 9ef861f3ec5c8315e1392b9d3cac012b80fffaa5 @weierophinney weierophinney committed Oct 25, 2011
Showing with 68 additions and 14 deletions.
  1. +41 −6 library/Zend/Mail/Mail.php
  2. +20 −2 library/Zend/Mail/Transport/Smtp.php
  3. +7 −6 tests/Zend/Mail/MessageTest.php
View
@@ -157,12 +157,18 @@ 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();
@@ -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;
}
@@ -210,6 +220,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
*
* @return string
@@ -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) {
@@ -115,6 +115,21 @@ class Smtp extends AbstractTransport
*/
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'];
}
@@ -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
@@ -26,6 +26,7 @@
use Zend\Mail\Message;
use Zend\Mime;
use Zend\Mail\Storage;
+use Zend\Mail\Exception;
/**
* @category Zend
@@ -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
}
@@ -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
}
@@ -268,7 +269,7 @@ public function testNoContent()
try {
$message->getContent();
- } catch (\Zend\Mime\Exception $e) {
+ } catch (Exception\RuntimeException $e) {
return; // ok
}
@@ -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) {
@@ -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) {
@@ -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');

0 comments on commit 9ef861f

Please sign in to comment.