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

Commit

Permalink
Merge branch 'master' of git://git.zendframework.com/zf
Browse files Browse the repository at this point in the history
  • Loading branch information
Shahar Evron committed Jul 25, 2010
5 parents bbf0ef3 + 3ecbc20 + 7524f9b + 67b64ab + 7abc3aa commit a09c912
Show file tree
Hide file tree
Showing 40 changed files with 382 additions and 328 deletions.
52 changes: 38 additions & 14 deletions src/Protocol/AbstractProtocol.php → src/AbstractProtocol.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
/**
* @namespace
*/
namespace Zend\Mail\Protocol;
use Zend\Validator\Hostname as HostnameValidator;
use Zend\Validator;
namespace Zend\Mail;

use Zend\Validator\Hostname as HostnameValidator,
Zend\Validator;

/**
* Zend_Mail_Protocol_Abstract
Expand Down Expand Up @@ -59,8 +60,9 @@ abstract class AbstractProtocol

/**
* Maximum of the transaction log
* @var integer
*/
const MAXIMUM_LOG = 64;
protected $_maximumLog = 64;


/**
Expand Down Expand Up @@ -134,7 +136,7 @@ public function __construct($host = '127.0.0.1', $port = null)
$this->_validHost->addValidator(new HostnameValidator\Hostname(HostnameValidator\Hostname::ALLOW_ALL));

if (!$this->_validHost->isValid($host)) {
throw new Exception(join(', ', $this->_validHost->getMessages()));
throw new Protocol\Exception(join(', ', $this->_validHost->getMessages()));
}

$this->_host = $host;
Expand All @@ -152,6 +154,28 @@ public function __destruct()
$this->_disconnect();
}

/**
* Set the maximum log size
*
* @param integer $maximumLog Maximum log size
* @return void
*/
public function setMaximumLog($maximumLog)
{
$this->_maximumLog = (int) $maximumLog;
}


/**
* Get the maximum log size
*
* @return int the maximum log size
*/
public function getMaximumLog()
{
return $this->_maximumLog;
}


/**
* Create a connection to the remote host
Expand Down Expand Up @@ -212,7 +236,7 @@ public function resetLog()
*/
protected function _addLog($value)
{
if (count($this->_log) >= self::MAXIMUM_LOG) {
if ($this->_maximumLog >= 0 && count($this->_log) >= $this->_maximumLog) {
array_shift($this->_log);
}

Expand Down Expand Up @@ -240,11 +264,11 @@ protected function _connect($remote)
if ($errorNum == 0) {
$errorStr = 'Could not open socket';
}
throw new Exception($errorStr);
throw new Protocol\Exception($errorStr);
}

if (($result = stream_set_timeout($this->_socket, self::TIMEOUT_CONNECTION)) === false) {
throw new Exception('Could not set stream timeout');
throw new Protocol\Exception('Could not set stream timeout');
}

return $result;
Expand Down Expand Up @@ -274,7 +298,7 @@ protected function _disconnect()
protected function _send($request)
{
if (!is_resource($this->_socket)) {
throw new Exception('No connection has been established to ' . $this->_host);
throw new Protocol\Exception('No connection has been established to ' . $this->_host);
}

$this->_request = $request;
Expand All @@ -285,7 +309,7 @@ protected function _send($request)
$this->_addLog($request . self::EOL);

if ($result === false) {
throw new Exception('Could not send request to ' . $this->_host);
throw new Protocol\Exception('Could not send request to ' . $this->_host);
}

return $result;
Expand All @@ -302,7 +326,7 @@ protected function _send($request)
protected function _receive($timeout = null)
{
if (!is_resource($this->_socket)) {
throw new Exception('No connection has been established to ' . $this->_host);
throw new Protocol\Exception('No connection has been established to ' . $this->_host);
}

// Adapters may wish to supply per-commend timeouts according to appropriate RFC
Expand All @@ -320,11 +344,11 @@ protected function _receive($timeout = null)
$info = stream_get_meta_data($this->_socket);

if (!empty($info['timed_out'])) {
throw new Exception($this->_host . ' has timed out');
throw new Protocol\Exception($this->_host . ' has timed out');
}

if ($reponse === false) {
throw new Exception('Could not read from ' . $this->_host);
throw new Protocol\Exception('Could not read from ' . $this->_host);
}

return $reponse;
Expand Down Expand Up @@ -366,7 +390,7 @@ protected function _expect($code, $timeout = null)
} while (strpos($more, '-') === 0); // The '-' message prefix indicates an information string instead of a response string.

if ($errMsg !== '') {
throw new Exception($errMsg);
throw new Protocol\Exception($errMsg);
}

return $msg;
Expand Down
6 changes: 3 additions & 3 deletions src/Storage/AbstractStorage.php → src/AbstractStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
* @namespace
*/
namespace Zend\Mail\Storage;
namespace Zend\Mail;

/**
* @uses ArrayAccess
Expand Down Expand Up @@ -88,7 +88,7 @@ public function __get($var)
return isset($this->_has[$var]) ? $this->_has[$var] : null;
}

throw new Exception($var . ' not found');
throw new Storage\Exception($var . ' not found');
}


Expand Down Expand Up @@ -266,7 +266,7 @@ public function offsetGet($id)
*/
public function offsetSet($id, $value)
{
throw new Exception('cannot write mail messages via array access');
throw new Storage\Exception('cannot write mail messages via array access');
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
/**
* @namespace
*/
namespace Zend\Mail\Transport;
namespace Zend\Mail;

use Zend\Mime;
use Zend\Mail;

/**
* Abstract for sending eMails through different
Expand Down Expand Up @@ -208,7 +208,7 @@ protected function _prepareHeaders($headers)
}
}
if (!$sane) {
throw new Mail\Exception('At least one mail header line is too long');
throw new Exception('At least one mail header line is too long');
}
}

Expand Down Expand Up @@ -292,7 +292,7 @@ protected function _buildBody()
* @return void
* @throws \Zend\Mail\Transport\Exception if mail is empty
*/
public function send(\Zend\Mail\Mail $mail)
public function send(Mail $mail)
{
$this->_isMultipart = false;
$this->_mail = $mail;
Expand Down
24 changes: 14 additions & 10 deletions src/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@
* @namespace
*/
namespace Zend\Mail;
use Zend\Mime;
use Zend\Date;

use Zend\Mime,
Zend\Date;

/**
* Class for sending an email.
*
* @uses \Zend\Mail\Exception
* @uses \Zend\Mail\Transport\AbstractTransport
* @uses \Zend\Mail\AbstractTransport
* @uses \Zend\Mail\Transport\Sendmail
* @uses \Zend\Mime\Mime
* @uses \Zend\Mime\Message
Expand All @@ -47,7 +48,7 @@ class Mail extends Mime\Message
*/

/**
* @var \Zend\Mail\Transport\AbstractTransport
* @var \Zend\Mail\AbstractTransport
* @static
*/
protected static $_defaultTransport = null;
Expand Down Expand Up @@ -169,9 +170,9 @@ class Mail extends Mime\Message
*
* @todo Allow passing a string to indicate the transport to load
* @todo Allow passing in optional options for the transport to load
* @param \Zend\Mail\Transport\AbstractTransport $transport
* @param \Zend\Mail\AbstractTransport $transport
*/
public static function setDefaultTransport(Transport\AbstractTransport $transport)
public static function setDefaultTransport(AbstractTransport $transport)
{
self::$_defaultTransport = $transport;
}
Expand Down Expand Up @@ -200,10 +201,13 @@ public static function clearDefaultTransport()
* Public constructor
*
* @param string $charset
* @return void
*/
public function __construct($charset = 'iso-8859-1')
public function __construct($charset = null)
{
$this->_charset = $charset;
if ($charset != null) {
$this->_charset = $charset;
}
}

/**
Expand Down Expand Up @@ -1077,13 +1081,13 @@ public function getHeaders()
* set DefaultTransport or the internal mail function if no
* default transport had been set.
*
* @param \Zend\Mail\Transport\AbstractTransport $transport
* @param \Zend\Mail\AbstractTransport $transport
* @return \Zend\Mail\Mail Provides fluent interface
*/
public function send($transport = null)
{
if ($transport === null) {
if (! self::$_defaultTransport instanceof Transport\AbstractTransport) {
if (! self::$_defaultTransport instanceof AbstractTransport) {
$transport = new Transport\Sendmail();
} else {
$transport = self::$_defaultTransport;
Expand Down
7 changes: 3 additions & 4 deletions src/Message/MessageInterface.php → src/MailMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
* @namespace
*/
namespace Zend\Mail\Message;
namespace Zend\Mail;

/**
* @category Zend
Expand All @@ -32,8 +32,7 @@
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

interface MessageInterface
interface MailMessage
{
/**
* return toplines as found after headers
Expand All @@ -45,7 +44,7 @@ public function getTopLines();
/**
* check if flag is set
*
* @param mixed $flag a flag name, use constants defined in \Zend\Mail\Storage\Storage
* @param mixed $flag a flag name, use constants defined in \Zend\Mail\Storage
* @return bool true if set, otherwise false
*/
public function hasFlag($flag);
Expand Down
4 changes: 2 additions & 2 deletions src/Part/PartInterface.php → src/MailPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
* @namespace
*/
namespace Zend\Mail\Part;
namespace Zend\Mail;

/**
* @uses RecursiveIterator
Expand All @@ -33,7 +33,7 @@
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface PartInterface extends \RecursiveIterator
interface MailPart extends \RecursiveIterator
{
/**
* Check if part is a multipart message
Expand Down
10 changes: 4 additions & 6 deletions src/Message/Message.php → src/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,18 @@
/**
* @namespace
*/
namespace Zend\Mail\Message;
use Zend\Mail;
use Zend\Mail\Part as MailPart;
namespace Zend\Mail;

/**
* @uses \Zend\Mail\Exception
* @uses \Zend\Mail\Message\MessageInterface
* @uses \Zend\Mail\Part\Part
* @uses \Zend\Mail\Part
* @category Zend
* @package Zend_Mail
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Message extends MailPart\Part implements MessageInterface
class Message extends Part implements MailMessage
{
/**
* flags for this message
Expand All @@ -59,7 +57,7 @@ public function __construct(array $params)
if (!is_resource($params['file'])) {
$params['raw'] = @file_get_contents($params['file']);
if ($params['raw'] === false) {
throw new Mail\Exception('could not open file');
throw new Exception('could not open file');
}
} else {
$params['raw'] = stream_get_contents($params['file']);
Expand Down
10 changes: 6 additions & 4 deletions src/Message/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,19 @@
* @namespace
*/
namespace Zend\Mail\Message;
use Zend\Mail\Part as MailPart;

use Zend\Mail\MailMessage,
Zend\Mail\Part\File as FilePart;

/**
* @uses \Zend\Mail\Message\MessageInterface
* @uses \Zend\Mail\MailMessage
* @uses \Zend\Mail\Part\File
* @category Zend
* @package Zend_Mail
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class File extends MailPart\File implements MessageInterface
class File extends FilePart implements MailMessage
{
/**
* flags for this message
Expand Down Expand Up @@ -73,7 +75,7 @@ public function getTopLines()
/**
* check if flag is set
*
* @param mixed $flag a flag name, use constants defined in \Zend\Mail\Storage\Storage
* @param mixed $flag a flag name, use constants defined in \Zend\Mail\Storage
* @return bool true if set, otherwise false
*/
public function hasFlag($flag)
Expand Down
Loading

0 comments on commit a09c912

Please sign in to comment.