Skip to content

Commit

Permalink
Initial changes in headers, just draft.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrbasso committed Apr 13, 2011
1 parent a920922 commit 8f5049e
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 46 deletions.
100 changes: 56 additions & 44 deletions lib/Cake/Network/CakeEmail.php
Expand Up @@ -27,33 +27,40 @@
* @package cake.libs
*/
class CakeEmail {
/**
* What mailer should EmailComponent identify itself as
*
* @constant EMAIL_CLIENT
*/
const EMAIL_CLIENT = 'CakePHP Email Component';

/**
* Recipient of the email
*
* @var string
*/
public $to = null;
protected $_to = array();

/**
* The mail which the email is sent from
*
* @var string
*/
public $from = null;
protected $_from = array();

/**
* The email the recipient will reply to
*
* @var string
*/
public $replyTo = null;
protected $_replyTo = null;

/**
* The read receipt email
*
* @var string
*/
public $readReceipt = null;
protected $_readReceipt = null;

/**
* The mail that will be used in case of any errors like
Expand All @@ -63,7 +70,7 @@ class CakeEmail {
*
* @var string
*/
public $return = null;
protected $_return = null;

/**
* Carbon Copy
Expand All @@ -73,7 +80,7 @@ class CakeEmail {
*
* @var array
*/
public $cc = array();
protected $_cc = array();

/**
* Blind Carbon Copy
Expand All @@ -83,40 +90,22 @@ class CakeEmail {
*
* @var array
*/
public $bcc = array();

/**
* The date to put in the Date: header. This should be a date
* conformant with the RFC2822 standard. Leave null, to have
* today's date generated.
*
* @var string
*/
var $date = null;
protected $_bcc = array();

/**
* The subject of the email
*
* @var string
*/
public $subject = null;
protected $_subject = null;

/**
* Associative array of a user defined headers
* Keys will be prefixed 'X-' as per RFC2822 Section 4.7.5
*
* @var array
*/
public $headers = array();

/**
* List of additional headers
*
* These will NOT be used if you are using safemode and mail()
*
* @var string
*/
public $additionalParams = null;
protected $_headers = array();

/**
* Layout for the View
Expand Down Expand Up @@ -185,27 +174,13 @@ class CakeEmail {
*/
public $attachments = array();

/**
* What mailer should EmailComponent identify itself as
*
* @var string
*/
public $xMailer = 'CakePHP Email Component';

/**
* The list of paths to search if an attachment isnt absolute
*
* @var array
*/
public $filePaths = array();

/**
* Temporary store of message header lines
*
* @var array
*/
protected $_header = array();

/**
* If set, boundary to use for multipart mime messages
*
Expand All @@ -229,14 +204,51 @@ public function __construct() {
*
* @param array Associative array containing headers to be set.
* @return void
* @thrown SocketException
*/
public function header($headers) {
public function setHeaders($headers) {
if (!is_array($headers)) {
throw new SocketException(__('$headers should be an array.'));
}
foreach ($headers as $header => $value) {
$this->_header[] = sprintf('%s: %s', trim($header), trim($value));
$this->_headers = $headers;
}

/**
* Add header for the message
*
* @param array $headers
* @return void
* @thrown SocketException
*/
public function addHeaders($headers) {
if (!is_array($headers)) {
throw new SocketException(__('$headers should be an array.'));
}
$this->_headers = array_merge($this->_headers, $headers);
}

/**
* Get list of headers
*
* @param boolean $includeToAndCc
* @param boolean $includeBcc
* @param boolean $includeSubject
* @return array
*/
public function getHeaders($includeToAndCc = false, $includeBcc = false, $includeSubject = false) {
if (!isset($this->_headers['X-Mailer'])) {
$this->_headers['X-Mailer'] = Configure::read('Email.XMailer');
if (empty($this->_headers['X-Mailer'])) {
$this->_headers['X-Mailer'] = self::EMAIL_CLIENT;
}
}
if (!isset($this->_headers['Date'])) {
$this->_headers['Date'] = date(DATE_RFC2822);
}
if ($includeSubject) {
$this->_headers['Subject'] = $this->_subject;
}
return $this->_headers;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/tests/Case/Network/CakeEmailTest.php
Expand Up @@ -26,11 +26,11 @@
class CakeEmailTest extends CakeTestCase {

/**
* testHeader method
* testHeaders method
*
* @return void
*/
public function testHeader() {
public function testHeaders() {
}

/**
Expand Down

0 comments on commit 8f5049e

Please sign in to comment.