mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Refactoring EmailComponent class
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@3537 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
f01e1a28f4
commit
e459a7c4e2
1 changed files with 15 additions and 11 deletions
|
@ -55,7 +55,7 @@ class EmailComponent extends Object{
|
|||
|
||||
var $_debug = false;
|
||||
var $_error = false;
|
||||
var $_newLine = '\n';
|
||||
var $_newLine = "\r\n";
|
||||
var $_lineLength = 75;
|
||||
|
||||
var $__header = null;
|
||||
|
@ -81,7 +81,7 @@ class EmailComponent extends Object{
|
|||
$this->__createHeader();
|
||||
$this->__formatMessage($message);
|
||||
|
||||
if(!empty($this->$attachments)) {
|
||||
if(!empty($this->attachments)) {
|
||||
$this->__attachFiles();
|
||||
}
|
||||
$__method = '__'.$this->delivery;
|
||||
|
@ -94,13 +94,13 @@ class EmailComponent extends Object{
|
|||
|
||||
|
||||
function __createHeader(){
|
||||
$this->__header .= 'To: ' . $this->to . $this->_newLine;
|
||||
$this->__header .= 'From: ' . $this->from . $this->_newLine;
|
||||
$this->__header .= 'Reply-To: ' . $this->replyTo . $this->_newLine;
|
||||
$this->__header .= 'Return-Path: ' . $this->return . $this->_newLine;
|
||||
|
||||
$addresses = null;
|
||||
if(!empty($this->cc)) {
|
||||
die(debug($this->cc));
|
||||
foreach ($this->cc as $cc) {
|
||||
$addresses .= $cc . ', ';
|
||||
}
|
||||
|
@ -108,6 +108,7 @@ class EmailComponent extends Object{
|
|||
$this->to .= ', ' . $addresses;
|
||||
}
|
||||
if(!empty($this->bcc)) {
|
||||
die(debug($this->bcc));
|
||||
foreach ($this->bcc as $bcc) {
|
||||
$addresses .= $bcc . ', ';
|
||||
}
|
||||
|
@ -117,10 +118,10 @@ class EmailComponent extends Object{
|
|||
|
||||
$this->__header .= 'X-Mailer: ' . $this->xMailer . $this->_newLine;
|
||||
|
||||
if(!empty($this->$attachments) && $this->sendAs === 'text') {
|
||||
if(!empty($this->attachments) && $this->sendAs === 'text') {
|
||||
$this->__header .= 'MIME-Version: 1.0' . $this->_newLine;
|
||||
$this->__header .= 'Content-Type: multipart/mixed; boundary=' . $this->__boundary . $this->_newLine;
|
||||
} elseif(!empty($this->$attachments) && $this->sendAs === 'html') {
|
||||
} elseif(!empty($this->attachments) && $this->sendAs === 'html') {
|
||||
$this->__header .= 'MIME-Version: 1.0' . $this->_newLine;
|
||||
$this->__header .= 'Content-Type: multipart/related; boundary=' . $this->__boundary . $this->_newLine;
|
||||
} elseif($this->sendAs === 'html') {
|
||||
|
@ -131,13 +132,15 @@ class EmailComponent extends Object{
|
|||
|
||||
function __formatMessage($message){
|
||||
$message = $this->__wrap($message);
|
||||
|
||||
if($this->sendAs === 'html'){
|
||||
$this->__message = '--' . $this->__boundary . $this->_newLine;
|
||||
$this->__message .= 'Content-Type: text/plain; charset=' . $this->charset . $this->_newLine;
|
||||
$this->__message .= 'Content-Transfer-Encoding: 8bit' . $this->_newLine;
|
||||
$this->__message .= 'If you are seeing this is because you may need to change your'.$this->_newLine;
|
||||
$this->__message .= 'preferred message format from HTML to plain text.'.$this->_newLine.$this->_newLine;
|
||||
$this->__message .= strip_tags($message) . $this->_newLine;
|
||||
|
||||
if($this->sendAs === 'html'){
|
||||
$this->__message .= strip_tags($message) . $this->_newLine;
|
||||
$this->__message = '--' . $this->__boundary . $this->_newLine;
|
||||
$this->__message .= 'Content-Type: text/html; charset=' . $this->charset . $this->_newLine;
|
||||
$this->__message .= 'Content-Transfer-Encoding: 8bit' . $this->_newLine;
|
||||
|
@ -177,10 +180,11 @@ class EmailComponent extends Object{
|
|||
}
|
||||
|
||||
function __wrap($message) {
|
||||
$message = str_replace("\r\n", "\n ", $message);
|
||||
$message = str_replace(array('\r','\n'), '\n ', $message);
|
||||
$words = explode(" ", $message);
|
||||
$formated = null;
|
||||
foreach ($words as $word) {
|
||||
$formated .= chunk_split($word, $this->_lineLength, " ") . " ";
|
||||
$formated .= chunk_split($word, $this->_lineLength, ' ') . ' ' ;
|
||||
}
|
||||
return $formated;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue