From 92d8eb2acf7204d01f595081551a4b08c4660cf3 Mon Sep 17 00:00:00 2001 From: Robert Angyal Date: Sun, 17 Apr 2016 06:48:22 +0200 Subject: Fixes #4583 by separating attachments to related and mixed multiparts Signed-off-by: Robert Angyal --- system/libraries/Email.php | 135 +++++++++++++++++++++++++++++++++------------ 1 file changed, 101 insertions(+), 34 deletions(-) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index ed6f737a1..ef9b58b61 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -149,13 +149,6 @@ class CI_Email { */ public $charset = 'utf-8'; - /** - * Multipart message - * - * @var string 'mixed' (in the body) or 'related' (separate) - */ - public $multipart = 'mixed'; // "mixed" (in the body) or "related" (separate) - /** * Alternative message (for HTML messages only) * @@ -274,6 +267,13 @@ class CI_Email { */ protected $_atc_boundary = ''; + /** + * Related Attachment boundary + * + * @var string + */ + protected $_rel_boundary = ''; + /** * Final headers to send * @@ -766,7 +766,8 @@ class CI_Email { 'name' => array($file, $newname), 'disposition' => empty($disposition) ? 'attachment' : $disposition, // Can also be 'inline' Not sure if it matters 'type' => $mime, - 'content' => chunk_split(base64_encode($file_content)) + 'content' => chunk_split(base64_encode($file_content)), + 'multipart' => 'mixed' ); return $this; @@ -784,15 +785,11 @@ class CI_Email { */ public function attachment_cid($filename) { - if ($this->multipart !== 'related') - { - $this->multipart = 'related'; // Thunderbird need this for inline images - } - for ($i = 0, $c = count($this->_attachments); $i < $c; $i++) { if ($this->_attachments[$i]['name'][0] === $filename) { + $this->_attachments[$i]['multipart'] = 'related'; $this->_attachments[$i]['cid'] = uniqid(basename($this->_attachments[$i]['name'][0]).'@'); return $this->_attachments[$i]['cid']; } @@ -945,6 +942,7 @@ class CI_Email { { $this->_alt_boundary = 'B_ALT_'.uniqid(''); // multipart/alternative $this->_atc_boundary = 'B_ATC_'.uniqid(''); // attachment boundary + $this->_rel_boundary = 'B_REL_'.uniqid(''); // related attachment boundary } // -------------------------------------------------------------------- @@ -1391,7 +1389,7 @@ class CI_Email { case 'plain-attach' : - $hdr .= 'Content-Type: multipart/'.$this->multipart.'; boundary="'.$this->_atc_boundary.'"'; + $hdr .= 'Content-Type: multipart/mixed; boundary="'.$this->_atc_boundary.'"'; if ($this->_get_protocol() === 'mail') { @@ -1406,18 +1404,45 @@ class CI_Email { .$this->newline .$this->_body.$this->newline.$this->newline; + $attachment_prepared = $this->_prep_attachments($this->_attachments, $this->_atc_boundary); + break; case 'html-attach' : - $hdr .= 'Content-Type: multipart/'.$this->multipart.'; boundary="'.$this->_atc_boundary.'"'; + $attachments_indexed_by_multipart = $this->_attachments_indexed_by_multipart(); + $attachments_related = $attachments_indexed_by_multipart['related']; + $attachments_mixed = $attachments_indexed_by_multipart['mixed']; + $prepared_attachment_parts = array(); + + if (isset($attachments_mixed) && count($attachments_mixed) > 0) + { + $hdr .= 'Content-Type: multipart/mixed; boundary="'.$this->_atc_boundary.'"'; + + array_push($prepared_attachment_parts, $this->_prep_attachments($attachments_mixed, $this->_atc_boundary)); + $last_boundary = $this->_atc_boundary; + } + + if (isset($attachments_related) && count($attachments_related) > 0) + { + $target_container =& $hdr; + if (isset($last_boundary)) { + $target_container =& $body; + $target_container .= '--' . $last_boundary . $this->newline; + } + $target_container .= 'Content-Type: multipart/related; boundary="'.$this->_rel_boundary.'"'; + + array_unshift($prepared_attachment_parts, $this->_prep_attachments($attachments_related, $this->_rel_boundary)); + $last_boundary = $this->_rel_boundary; + } if ($this->_get_protocol() === 'mail') { $this->_header_str .= $hdr; } + if (strlen(body) > 0) $body .= $this->newline.$this->newline; $body .= $this->_get_mime_message().$this->newline.$this->newline - .'--'.$this->_atc_boundary.$this->newline + .'--'.$last_boundary.$this->newline .'Content-Type: multipart/alternative; boundary="'.$this->_alt_boundary.'"'.$this->newline.$this->newline .'--'.$this->_alt_boundary.$this->newline @@ -1432,27 +1457,12 @@ class CI_Email { .$this->_prep_quoted_printable($this->_body).$this->newline.$this->newline .'--'.$this->_alt_boundary.'--'.$this->newline.$this->newline; - break; - } - - $attachment = array(); - for ($i = 0, $c = count($this->_attachments), $z = 0; $i < $c; $i++) - { - $filename = $this->_attachments[$i]['name'][0]; - $basename = ($this->_attachments[$i]['name'][1] === NULL) - ? basename($filename) : $this->_attachments[$i]['name'][1]; - - $attachment[$z++] = '--'.$this->_atc_boundary.$this->newline - .'Content-type: '.$this->_attachments[$i]['type'].'; ' - .'name="'.$basename.'"'.$this->newline - .'Content-Disposition: '.$this->_attachments[$i]['disposition'].';'.$this->newline - .'Content-Transfer-Encoding: base64'.$this->newline - .(empty($this->_attachments[$i]['cid']) ? '' : 'Content-ID: <'.$this->_attachments[$i]['cid'].'>'.$this->newline); + $attachment_prepared = implode($this->newline.$this->newline, $prepared_attachment_parts); - $attachment[$z++] = $this->_attachments[$i]['content']; + break; } - $body .= implode($this->newline, $attachment).$this->newline.'--'.$this->_atc_boundary.'--'; + $body .= $attachment_prepared; $this->_finalbody = ($this->_get_protocol() === 'mail') ? $body : $hdr.$this->newline.$this->newline.$body; @@ -1462,6 +1472,63 @@ class CI_Email { // -------------------------------------------------------------------- + /** + * Returns attachments mapped by multipart type + * + * @return array + */ + protected function _attachments_indexed_by_multipart() + { + foreach ($this->_attachments as $attachment) + { + $multipart = $attachment['multipart']; + if (!isset($attachments_indexed[$multipart])) + { + $attachments_indexed[$multipart] = array(); + } + array_push($attachments_indexed[$multipart], $attachment); + } + + return $attachments_indexed; + } + + // -------------------------------------------------------------------- + + /** + * Prepares attachment string + * + * @param array $attachments + * @param string $boundary Multipart boundary string + * @return string + */ + protected function _prep_attachments($attachments, $boundary) + { + if (!isset($attachments) || count($attachments) === 0) return ''; + + $attachment_parts = array(); + foreach ($attachments as $attachment) + { + $filename = $attachment['name'][0]; + $basename = ($attachment['name'][1] === NULL) + ? basename($filename) : $attachment['name'][1]; + + array_push( + $attachment_parts, + '--'.$boundary.$this->newline + .'Content-type: '.$attachment['type'].'; ' + .'name="'.$basename.'"'.$this->newline + .'Content-Disposition: '.$attachment['disposition'].';'.$this->newline + .'Content-Transfer-Encoding: base64'.$this->newline + .(empty($attachment['cid']) ? '' : 'Content-ID: <'.$attachment['cid'].'>'.$this->newline), + $attachment['content'] + ); + } + + return implode($this->newline, $attachment_parts).$this->newline.'--'.$boundary.'--'; + } + + // -------------------------------------------------------------------- + /** * Prep Quoted Printable * -- cgit v1.2.3-24-g4f1b From 832fd00b10f2fb236e0bf5b770d3298e6fedee64 Mon Sep 17 00:00:00 2001 From: Robert Angyal Date: Wed, 20 Apr 2016 05:20:15 +0200 Subject: #4583 Fix code style issues Signed-off-by: Robert Angyal --- system/libraries/Email.php | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index ef9b58b61..cbb48f525 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -767,7 +767,7 @@ class CI_Email { 'disposition' => empty($disposition) ? 'attachment' : $disposition, // Can also be 'inline' Not sure if it matters 'type' => $mime, 'content' => chunk_split(base64_encode($file_content)), - 'multipart' => 'mixed' + 'multipart' => 'mixed' ); return $this; @@ -1413,6 +1413,7 @@ class CI_Email { $attachments_related = $attachments_indexed_by_multipart['related']; $attachments_mixed = $attachments_indexed_by_multipart['mixed']; $prepared_attachment_parts = array(); + $last_boundary = NULL; if (isset($attachments_mixed) && count($attachments_mixed) > 0) { @@ -1425,7 +1426,8 @@ class CI_Email { if (isset($attachments_related) && count($attachments_related) > 0) { $target_container =& $hdr; - if (isset($last_boundary)) { + if (isset($last_boundary)) + { $target_container =& $body; $target_container .= '--' . $last_boundary . $this->newline; } @@ -1440,7 +1442,10 @@ class CI_Email { $this->_header_str .= $hdr; } - if (strlen(body) > 0) $body .= $this->newline.$this->newline; + if (strlen(body) > 0) + { + $body .= $this->newline.$this->newline; + } $body .= $this->_get_mime_message().$this->newline.$this->newline .'--'.$last_boundary.$this->newline @@ -1475,7 +1480,7 @@ class CI_Email { /** * Returns attachments mapped by multipart type * - * @return array + * @return array */ protected function _attachments_indexed_by_multipart() { @@ -1497,13 +1502,16 @@ class CI_Email { /** * Prepares attachment string * - * @param array $attachments - * @param string $boundary Multipart boundary string - * @return string + * @param array $attachments + * @param string $boundary Multipart boundary string + * @return string */ protected function _prep_attachments($attachments, $boundary) { - if (!isset($attachments) || count($attachments) === 0) return ''; + if (!isset($attachments) OR count($attachments) === 0) + { + return ''; + } $attachment_parts = array(); foreach ($attachments as $attachment) -- cgit v1.2.3-24-g4f1b From ed458fbdb36f8d8d7bd7d818dbb2983485e86b3c Mon Sep 17 00:00:00 2001 From: Robert Angyal Date: Thu, 28 Apr 2016 10:26:56 +0200 Subject: #4583 Refactor according to the suggestions commented on Pull Request Signed-off-by: Robert Angyal --- system/libraries/Email.php | 68 ++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 38 deletions(-) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index cbb48f525..e35c48ec4 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1406,34 +1406,34 @@ class CI_Email { $attachment_prepared = $this->_prep_attachments($this->_attachments, $this->_atc_boundary); - break; + break; case 'html-attach' : $attachments_indexed_by_multipart = $this->_attachments_indexed_by_multipart(); - $attachments_related = $attachments_indexed_by_multipart['related']; - $attachments_mixed = $attachments_indexed_by_multipart['mixed']; $prepared_attachment_parts = array(); $last_boundary = NULL; - if (isset($attachments_mixed) && count($attachments_mixed) > 0) + if ( ! empty($attachments_indexed_by_multipart['mixed'])) { $hdr .= 'Content-Type: multipart/mixed; boundary="'.$this->_atc_boundary.'"'; - array_push($prepared_attachment_parts, $this->_prep_attachments($attachments_mixed, $this->_atc_boundary)); + $prepared_attachment_parts[] = $this->_prep_attachments($attachments_indexed_by_multipart['mixed'], $this->_atc_boundary); $last_boundary = $this->_atc_boundary; } - if (isset($attachments_related) && count($attachments_related) > 0) + if ( ! empty($attachments_indexed_by_multipart['related'])) { - $target_container =& $hdr; + $rel_boundary_header = 'Content-Type: multipart/related; boundary="'.$this->_rel_boundary.'"'; if (isset($last_boundary)) { - $target_container =& $body; - $target_container .= '--' . $last_boundary . $this->newline; + $body .= '--' . $last_boundary . $this->newline . $rel_boundary_header; + } + else + { + $hdr .= $rel_boundary_header; } - $target_container .= 'Content-Type: multipart/related; boundary="'.$this->_rel_boundary.'"'; - array_unshift($prepared_attachment_parts, $this->_prep_attachments($attachments_related, $this->_rel_boundary)); + array_unshift($prepared_attachment_parts, $this->_prep_attachments($attachments_indexed_by_multipart['related'], $this->_rel_boundary)); $last_boundary = $this->_rel_boundary; } @@ -1442,10 +1442,7 @@ class CI_Email { $this->_header_str .= $hdr; } - if (strlen(body) > 0) - { - $body .= $this->newline.$this->newline; - } + strlen($body) && $body .= $this->newline.$this->newline; $body .= $this->_get_mime_message().$this->newline.$this->newline .'--'.$last_boundary.$this->newline @@ -1464,7 +1461,7 @@ class CI_Email { $attachment_prepared = implode($this->newline.$this->newline, $prepared_attachment_parts); - break; + break; } $body .= $attachment_prepared; @@ -1487,11 +1484,8 @@ class CI_Email { foreach ($this->_attachments as $attachment) { $multipart = $attachment['multipart']; - if (!isset($attachments_indexed[$multipart])) - { - $attachments_indexed[$multipart] = array(); - } - array_push($attachments_indexed[$multipart], $attachment); + isset($attachments_indexed[$multipart]) OR $attachments_indexed[$multipart] = array(); + $attachments_indexed[$multipart][] = $attachment; } return $attachments_indexed; @@ -1508,31 +1502,29 @@ class CI_Email { */ protected function _prep_attachments($attachments, $boundary) { - if (!isset($attachments) OR count($attachments) === 0) + if (empty($attachments)) { return ''; } - $attachment_parts = array(); - foreach ($attachments as $attachment) + $attachment = array(); + for ($i = 0, $c = count($attachments), $z = 0; $i < $c; $i++) { - $filename = $attachment['name'][0]; - $basename = ($attachment['name'][1] === NULL) - ? basename($filename) : $attachment['name'][1]; + $filename = $attachments[$i]['name'][0]; + $basename = ($attachments[$i]['name'][1] === NULL) + ? basename($filename) : $attachments[$i]['name'][1]; + + $attachment[$z++] = '--'.$boundary.$this->newline + .'Content-type: '.$attachments[$i]['type'].'; ' + .'name="'.$basename.'"'.$this->newline + .'Content-Disposition: '.$attachments[$i]['disposition'].';'.$this->newline + .'Content-Transfer-Encoding: base64'.$this->newline + .(empty($attachments[$i]['cid']) ? '' : 'Content-ID: <'.$attachments[$i]['cid'].'>'.$this->newline); - array_push( - $attachment_parts, - '--'.$boundary.$this->newline - .'Content-type: '.$attachment['type'].'; ' - .'name="'.$basename.'"'.$this->newline - .'Content-Disposition: '.$attachment['disposition'].';'.$this->newline - .'Content-Transfer-Encoding: base64'.$this->newline - .(empty($attachment['cid']) ? '' : 'Content-ID: <'.$attachment['cid'].'>'.$this->newline), - $attachment['content'] - ); + $attachment[$z++] = $attachments[$i]['content']; } - return implode($this->newline, $attachment_parts).$this->newline.'--'.$boundary.'--'; + return implode($this->newline, $attachment).$this->newline.'--'.$boundary.'--'; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 5277583e7336675d02665ff77359b41e782853ce Mon Sep 17 00:00:00 2001 From: Robert Angyal Date: Wed, 4 May 2016 16:33:25 +0200 Subject: #4583 Refactor according to the suggestions commented on Pull Request Signed-off-by: Robert Angyal --- system/libraries/Email.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index e35c48ec4..4fd1107c5 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1404,20 +1404,17 @@ class CI_Email { .$this->newline .$this->_body.$this->newline.$this->newline; - $attachment_prepared = $this->_prep_attachments($this->_attachments, $this->_atc_boundary); + $body .= $this->_prep_attachments($this->_attachments, $this->_atc_boundary); break; case 'html-attach' : $attachments_indexed_by_multipart = $this->_attachments_indexed_by_multipart(); - $prepared_attachment_parts = array(); $last_boundary = NULL; if ( ! empty($attachments_indexed_by_multipart['mixed'])) { $hdr .= 'Content-Type: multipart/mixed; boundary="'.$this->_atc_boundary.'"'; - - $prepared_attachment_parts[] = $this->_prep_attachments($attachments_indexed_by_multipart['mixed'], $this->_atc_boundary); $last_boundary = $this->_atc_boundary; } @@ -1426,14 +1423,12 @@ class CI_Email { $rel_boundary_header = 'Content-Type: multipart/related; boundary="'.$this->_rel_boundary.'"'; if (isset($last_boundary)) { - $body .= '--' . $last_boundary . $this->newline . $rel_boundary_header; + $body .= '--'.$last_boundary.$this->newline.$rel_boundary_header; } else { $hdr .= $rel_boundary_header; } - - array_unshift($prepared_attachment_parts, $this->_prep_attachments($attachments_indexed_by_multipart['related'], $this->_rel_boundary)); $last_boundary = $this->_rel_boundary; } @@ -1459,12 +1454,15 @@ class CI_Email { .$this->_prep_quoted_printable($this->_body).$this->newline.$this->newline .'--'.$this->_alt_boundary.'--'.$this->newline.$this->newline; - $attachment_prepared = implode($this->newline.$this->newline, $prepared_attachment_parts); + ( ! empty($attachments_indexed_by_multipart['related'])) && $body .= $this->newline.$this->newline + .$this->_prep_attachments($attachments_indexed_by_multipart['related'], $this->_rel_boundary); + + ( ! empty($attachments_indexed_by_multipart['mixed'])) && $body .= $this->newline.$this->newline + .$this->_prep_attachments($attachments_indexed_by_multipart['mixed'], $this->_atc_boundary); break; } - $body .= $attachment_prepared; $this->_finalbody = ($this->_get_protocol() === 'mail') ? $body : $hdr.$this->newline.$this->newline.$body; -- cgit v1.2.3-24-g4f1b From 21a41ba37b9248291939cf4c801ac0f27982668e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 25 May 2016 15:27:39 +0300 Subject: [ci skip] Refactor changes from PR #4585 Related: #4583 --- system/libraries/Email.php | 165 +++++++++++++++++++-------------------------- 1 file changed, 70 insertions(+), 95 deletions(-) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 4fd1107c5..21b62fea0 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -253,27 +253,6 @@ class CI_Email { */ protected $_finalbody = ''; - /** - * multipart/alternative boundary - * - * @var string - */ - protected $_alt_boundary = ''; - - /** - * Attachment boundary - * - * @var string - */ - protected $_atc_boundary = ''; - - /** - * Related Attachment boundary - * - * @var string - */ - protected $_rel_boundary = ''; - /** * Final headers to send * @@ -933,20 +912,6 @@ class CI_Email { // -------------------------------------------------------------------- - /** - * Set Message Boundary - * - * @return void - */ - protected function _set_boundaries() - { - $this->_alt_boundary = 'B_ALT_'.uniqid(''); // multipart/alternative - $this->_atc_boundary = 'B_ATC_'.uniqid(''); // attachment boundary - $this->_rel_boundary = 'B_REL_'.uniqid(''); // related attachment boundary - } - - // -------------------------------------------------------------------- - /** * Get the Message ID * @@ -1014,9 +979,9 @@ class CI_Email { { if ($this->mailtype === 'html') { - return (count($this->_attachments) === 0) ? 'html' : 'html-attach'; + return empty($this->_attachments) ? 'html' : 'html-attach'; } - elseif ($this->mailtype === 'text' && count($this->_attachments) > 0) + elseif ($this->mailtype === 'text' && ! empty($this->_attachments)) { return 'plain-attach'; } @@ -1322,7 +1287,6 @@ class CI_Email { $this->_body = $this->word_wrap($this->_body); } - $this->_set_boundaries(); $this->_write_headers(); $hdr = ($this->_get_protocol() === 'mail') ? $this->newline : ''; @@ -1330,7 +1294,7 @@ class CI_Email { switch ($this->_get_content_type()) { - case 'plain' : + case 'plain': $hdr .= 'Content-Type: text/plain; charset='.$this->charset.$this->newline .'Content-Transfer-Encoding: '.$this->_get_encoding(); @@ -1347,7 +1311,7 @@ class CI_Email { return; - case 'html' : + case 'html': if ($this->send_multipart === FALSE) { @@ -1356,14 +1320,16 @@ class CI_Email { } else { - $hdr .= 'Content-Type: multipart/alternative; boundary="'.$this->_alt_boundary.'"'; + $boundary = uniqid('B_ALT_'); + $hdr .= 'Content-Type: multipart/alternative; boundary="'.$boundary.'"'; $body .= $this->_get_mime_message().$this->newline.$this->newline - .'--'.$this->_alt_boundary.$this->newline + .'--'.$boundary.$this->newline .'Content-Type: text/plain; charset='.$this->charset.$this->newline .'Content-Transfer-Encoding: '.$this->_get_encoding().$this->newline.$this->newline - .$this->_get_alt_message().$this->newline.$this->newline.'--'.$this->_alt_boundary.$this->newline + .$this->_get_alt_message().$this->newline.$this->newline + .'--'.$boundary.$this->newline .'Content-Type: text/html; charset='.$this->charset.$this->newline .'Content-Transfer-Encoding: quoted-printable'.$this->newline.$this->newline; @@ -1382,14 +1348,15 @@ class CI_Email { if ($this->send_multipart !== FALSE) { - $this->_finalbody .= '--'.$this->_alt_boundary.'--'; + $this->_finalbody .= '--'.$boundary.'--'; } return; - case 'plain-attach' : + case 'plain-attach': - $hdr .= 'Content-Type: multipart/mixed; boundary="'.$this->_atc_boundary.'"'; + $boundary = uniqid('B_ATC_'); + $hdr .= 'Content-Type: multipart/mixed; boundary="'.$boundary.'"'; if ($this->_get_protocol() === 'mail') { @@ -1398,29 +1365,32 @@ class CI_Email { $body .= $this->_get_mime_message().$this->newline .$this->newline - .'--'.$this->_atc_boundary.$this->newline + .'--'.$boundary.$this->newline .'Content-Type: text/plain; charset='.$this->charset.$this->newline .'Content-Transfer-Encoding: '.$this->_get_encoding().$this->newline .$this->newline .$this->_body.$this->newline.$this->newline; - $body .= $this->_prep_attachments($this->_attachments, $this->_atc_boundary); + $this->_append_attachments($body, $boundary); break; - case 'html-attach' : + case 'html-attach': - $attachments_indexed_by_multipart = $this->_attachments_indexed_by_multipart(); + $alt_boundary = uniqid('B_ALT_'); $last_boundary = NULL; - if ( ! empty($attachments_indexed_by_multipart['mixed'])) + if ($this->_attachments_have_multipart('mixed')) { - $hdr .= 'Content-Type: multipart/mixed; boundary="'.$this->_atc_boundary.'"'; - $last_boundary = $this->_atc_boundary; + $atc_boundary = uniqid('B_ATC_'); + $hdr .= 'Content-Type: multipart/mixed; boundary="'.$atc_boundary.'"'; + $last_boundary = $atc_boundary; } - if ( ! empty($attachments_indexed_by_multipart['related'])) + if ($this->_attachments_have_multipart('related')) { - $rel_boundary_header = 'Content-Type: multipart/related; boundary="'.$this->_rel_boundary.'"'; + $rel_boundary = uniqid('B_REL_'); + $rel_boundary_header = 'Content-Type: multipart/related; boundary="'.$rel_boundary.'"'; + if (isset($last_boundary)) { $body .= '--'.$last_boundary.$this->newline.$rel_boundary_header; @@ -1429,7 +1399,8 @@ class CI_Email { { $hdr .= $rel_boundary_header; } - $last_boundary = $this->_rel_boundary; + + $last_boundary = $rel_boundary; } if ($this->_get_protocol() === 'mail') @@ -1441,24 +1412,32 @@ class CI_Email { $body .= $this->_get_mime_message().$this->newline.$this->newline .'--'.$last_boundary.$this->newline - .'Content-Type: multipart/alternative; boundary="'.$this->_alt_boundary.'"'.$this->newline.$this->newline - .'--'.$this->_alt_boundary.$this->newline + .'Content-Type: multipart/alternative; boundary="'.$alt_boundary.'"'.$this->newline.$this->newline + .'--'.$alt_boundary.$this->newline .'Content-Type: text/plain; charset='.$this->charset.$this->newline .'Content-Transfer-Encoding: '.$this->_get_encoding().$this->newline.$this->newline - .$this->_get_alt_message().$this->newline.$this->newline.'--'.$this->_alt_boundary.$this->newline + .$this->_get_alt_message().$this->newline.$this->newline + .'--'.$alt_boundary.$this->newline .'Content-Type: text/html; charset='.$this->charset.$this->newline .'Content-Transfer-Encoding: quoted-printable'.$this->newline.$this->newline .$this->_prep_quoted_printable($this->_body).$this->newline.$this->newline - .'--'.$this->_alt_boundary.'--'.$this->newline.$this->newline; + .'--'.$alt_boundary.'--'.$this->newline.$this->newline; - ( ! empty($attachments_indexed_by_multipart['related'])) && $body .= $this->newline.$this->newline - .$this->_prep_attachments($attachments_indexed_by_multipart['related'], $this->_rel_boundary); + // multipart/mixed attachments + if ( ! empty($atc_boundary)) + { + $body .= $this->newline.$this->newline; + $this->_append_attachments($body, $atc_boundary, 'mixed'); + } - ( ! empty($attachments_indexed_by_multipart['mixed'])) && $body .= $this->newline.$this->newline - .$this->_prep_attachments($attachments_indexed_by_multipart['mixed'], $this->_atc_boundary); + if ( ! empty($rel_boundary)) + { + $body .= $this->newline.$this->newline; + $this->_append_attachments($body, $rel_boundary, 'related'); + } break; } @@ -1472,21 +1451,17 @@ class CI_Email { // -------------------------------------------------------------------- - /** - * Returns attachments mapped by multipart type - * - * @return array - */ - protected function _attachments_indexed_by_multipart() + protected function _attachments_have_multipart($type) { - foreach ($this->_attachments as $attachment) + foreach ($this->_attachments as &$attachment) { - $multipart = $attachment['multipart']; - isset($attachments_indexed[$multipart]) OR $attachments_indexed[$multipart] = array(); - $attachments_indexed[$multipart][] = $attachment; + if ($attachment[$i]['multipart'] === $type) + { + return TRUE; + } } - return $attachments_indexed; + return FALSE; } // -------------------------------------------------------------------- @@ -1494,35 +1469,35 @@ class CI_Email { /** * Prepares attachment string * - * @param array $attachments - * @param string $boundary Multipart boundary string + * @param string $body Message body to append to + * @param string $boundary Multipart boundary + * @param string $multipart When provided, only attachments of this type will be processed * @return string */ - protected function _prep_attachments($attachments, $boundary) + protected function _append_attachments(&$body, $boundary, $multipart = null) { - if (empty($attachments)) + for ($i = 0, $c = count($this->_attachments); $i < $c; $i++) { - return ''; - } + if (isset($multipart) && $this->_attachments[$i]['multipart'] !== $multipart) + { + continue; + } - $attachment = array(); - for ($i = 0, $c = count($attachments), $z = 0; $i < $c; $i++) - { - $filename = $attachments[$i]['name'][0]; - $basename = ($attachments[$i]['name'][1] === NULL) - ? basename($filename) : $attachments[$i]['name'][1]; + $name = isset($this->_attachments[$i]['name'][1]) + ? $this->_attachments[$i]['name'][1] + : basename($this->_attachments[$i]['name'][0]); - $attachment[$z++] = '--'.$boundary.$this->newline - .'Content-type: '.$attachments[$i]['type'].'; ' - .'name="'.$basename.'"'.$this->newline - .'Content-Disposition: '.$attachments[$i]['disposition'].';'.$this->newline + $body .= '--'.$boundary.$this->newline + .'Content-Type: '.$this->_attachments[$i]['type'].'; name="'.$name.'"'.$this->newline + .'Content-Disposition: '.$this->_attachments[$i]['disposition'].';'.$this->newline .'Content-Transfer-Encoding: base64'.$this->newline - .(empty($attachments[$i]['cid']) ? '' : 'Content-ID: <'.$attachments[$i]['cid'].'>'.$this->newline); - - $attachment[$z++] = $attachments[$i]['content']; + .(empty($this->_attachments[$i]['cid']) ? '' : 'Content-ID: <'.$this->_attachments[$i]['cid'].'>'.$this->newline.$this->newline) + .$this->_attachments[$i]['content'].$this->newline; } - return implode($this->newline, $attachment).$this->newline.'--'.$boundary.'--'; + // $name won't be set if no attachments were appended, + // and therefore a boundary wouldn't be necessary + empty($name) OR $body .= '--'.$boundary.'--'; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From e341601efed83a2c9cdca72de30de43a7ae12e1d Mon Sep 17 00:00:00 2001 From: Robert Angyal Date: Sat, 4 Jun 2016 12:12:28 +0200 Subject: Update Email.php --- system/libraries/Email.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 21b62fea0..0a55e1841 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1426,17 +1426,17 @@ class CI_Email { .$this->_prep_quoted_printable($this->_body).$this->newline.$this->newline .'--'.$alt_boundary.'--'.$this->newline.$this->newline; - // multipart/mixed attachments - if ( ! empty($atc_boundary)) + if ( ! empty($rel_boundary)) { $body .= $this->newline.$this->newline; - $this->_append_attachments($body, $atc_boundary, 'mixed'); + $this->_append_attachments($body, $rel_boundary, 'related'); } - if ( ! empty($rel_boundary)) + // multipart/mixed attachments + if ( ! empty($atc_boundary)) { $body .= $this->newline.$this->newline; - $this->_append_attachments($body, $rel_boundary, 'related'); + $this->_append_attachments($body, $atc_boundary, 'mixed'); } break; @@ -1455,7 +1455,7 @@ class CI_Email { { foreach ($this->_attachments as &$attachment) { - if ($attachment[$i]['multipart'] === $type) + if ($attachment['multipart'] === $type) { return TRUE; } -- cgit v1.2.3-24-g4f1b From a309badf3a73f427af030e790e5080347da67372 Mon Sep 17 00:00:00 2001 From: Kristaps V Date: Fri, 12 Aug 2016 17:55:36 +0300 Subject: Fix custom user agent not working Signed-off-by: Kristaps V --- system/libraries/Email.php | 1 + 1 file changed, 1 insertion(+) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 50d0cd04e..426731135 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1206,6 +1206,7 @@ class CI_Email { */ protected function _build_headers() { + $this->set_header('User-Agent', $this->useragent); $this->set_header('X-Sender', $this->clean_email($this->_headers['From'])); $this->set_header('X-Mailer', $this->useragent); $this->set_header('X-Priority', $this->_priorities[$this->priority]); -- cgit v1.2.3-24-g4f1b From 50e87ec848f27bb5e40093ade2b67dc104679fb9 Mon Sep 17 00:00:00 2001 From: Igor Ostapchuk Date: Sun, 21 Aug 2016 16:28:28 +0300 Subject: return fix --- system/libraries/Email.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 50d0cd04e..6a7e2b3a7 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1202,7 +1202,7 @@ class CI_Email { /** * Build final headers * - * @return string + * @return void */ protected function _build_headers() { @@ -2046,7 +2046,7 @@ class CI_Email { * * @param string * @param string - * @return string + * @return bool */ protected function _send_command($cmd, $data = '') { -- cgit v1.2.3-24-g4f1b From d76431db46e04d650c1c538493021cdf336d1301 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 1 Dec 2016 14:23:40 +0200 Subject: Switch CI_Email::$validate to On by default Relevant: #4844 --- system/libraries/Email.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 162cc7777..90a68f129 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -161,7 +161,7 @@ class CI_Email { * * @var bool */ - public $validate = FALSE; + public $validate = TRUE; /** * X-Priority header value. -- cgit v1.2.3-24-g4f1b From 24c866628d0ce5463d7e8b4eba512fa9e7752dfd Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 14 Dec 2016 16:14:13 +0200 Subject: Drop all PHP 5.3-related code --- system/libraries/Email.php | 36 +++--------------------------------- 1 file changed, 3 insertions(+), 33 deletions(-) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 90a68f129..1191e2350 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -225,13 +225,6 @@ class CI_Email { // -------------------------------------------------------------------- - /** - * Whether PHP is running in safe mode. Initialized by the class constructor. - * - * @var bool - */ - protected $_safe_mode = FALSE; - /** * Subject header * @@ -395,7 +388,6 @@ class CI_Email { { $this->charset = config_item('charset'); $this->initialize($config); - $this->_safe_mode = ( ! is_php('5.4') && ini_get('safe_mode')); isset(self::$func_override) OR self::$func_override = (extension_loaded('mbstring') && ini_get('mbstring.func_override')); @@ -676,18 +668,6 @@ class CI_Email { public function message($body) { $this->_body = rtrim(str_replace("\r", '', $body)); - - /* strip slashes only if magic quotes is ON - if we do it with magic quotes OFF, it strips real, user-inputted chars. - - NOTE: In PHP 5.4 get_magic_quotes_gpc() will always return 0 and - it will probably not exist in future versions at all. - */ - if ( ! is_php('5.4') && get_magic_quotes_gpc()) - { - $this->_body = stripslashes($this->_body); - } - return $this; } @@ -1854,16 +1834,9 @@ class CI_Email { $this->_recipients = implode(', ', $this->_recipients); } - if ($this->_safe_mode === TRUE) - { - return mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str); - } - else - { - // most documentation of sendmail using the "-f" flag lacks a space after it, however - // we've encountered servers that seem to require it to be in place. - return mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str, '-f '.$this->clean_email($this->_headers['Return-Path'])); - } + // most documentation of sendmail using the "-f" flag lacks a space after it, however + // we've encountered servers that seem to require it to be in place. + return mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str, '-f '.$this->clean_email($this->_headers['Return-Path'])); } // -------------------------------------------------------------------- @@ -2421,9 +2394,6 @@ class CI_Email { { if (self::$func_override) { - // mb_substr($str, $start, null, '8bit') returns an empty - // string on PHP 5.3 - isset($length) OR $length = ($start >= 0 ? self::strlen($str) - $start : -$start); return mb_substr($str, $start, $length, '8bit'); } -- cgit v1.2.3-24-g4f1b From fced25f5728ce81fe810216fcaa4ccec7523f6c9 Mon Sep 17 00:00:00 2001 From: Master Yoda Date: Sat, 31 Dec 2016 08:46:18 -0800 Subject: Update copyright data to 2017 --- system/libraries/Email.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 1191e2350..fbf0cb7dc 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -6,7 +6,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014 - 2016, British Columbia Institute of Technology + * Copyright (c) 2014 - 2017, British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * @package CodeIgniter * @author EllisLab Dev Team * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) - * @copyright Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/) + * @copyright Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/) * @license http://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com * @since Version 1.0.0 -- cgit v1.2.3-24-g4f1b From 8acd0fa915f61d4e152ce7505646865815b4f458 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 22 Jun 2017 13:40:21 +0300 Subject: [ci skip] Close #3711 --- system/libraries/Email.php | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index fa5820dcd..73bf7ffdd 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1235,7 +1235,7 @@ class CI_Email { /** * Build Final Body and attachments * - * @return bool + * @return void */ protected function _build_message() { @@ -1402,8 +1402,6 @@ class CI_Email { $this->_finalbody = ($this->_get_protocol() === 'mail') ? $body : $hdr.$this->newline.$this->newline.$body; - - return TRUE; } // -------------------------------------------------------------------- @@ -1677,21 +1675,17 @@ class CI_Email { if ($this->bcc_batch_mode && count($this->_bcc_array) > $this->bcc_batch_size) { - $result = $this->batch_bcc_send(); + $this->batch_bcc_send(); - if ($result && $auto_clear) + if ($auto_clear) { $this->clear(); } - return $result; - } - - if ($this->_build_message() === FALSE) - { - return FALSE; + return TRUE; } + $this->_build_message(); $result = $this->_spool_email(); if ($result && $auto_clear) @@ -1750,11 +1744,7 @@ class CI_Email { $this->_bcc_array = $bcc; } - if ($this->_build_message() === FALSE) - { - return FALSE; - } - + $this->_build_message(); $this->_spool_email(); } } -- cgit v1.2.3-24-g4f1b From a2a49fcc322acd5ded3c0664d64bbebe982815f5 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 22 Jun 2017 13:51:11 +0300 Subject: [ci skip] Misc cleanup of CI_Email code --- system/libraries/Email.php | 165 ++++++++++++++++++--------------------------- 1 file changed, 64 insertions(+), 101 deletions(-) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 73bf7ffdd..1dcafeddd 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1663,8 +1663,8 @@ class CI_Email { $this->reply_to($this->_headers['From']); } - if ( ! isset($this->_recipients) && ! isset($this->_headers['To']) - && ! isset($this->_bcc_array) && ! isset($this->_headers['Bcc']) + if (empty($this->_recipients) && ! isset($this->_headers['To']) + && empty($this->_bcc_array) && ! isset($this->_headers['Bcc']) && ! isset($this->_headers['Cc'])) { $this->_set_error_message('lang:email_no_recipients'); @@ -1935,27 +1935,21 @@ class CI_Email { } } - if (count($this->_cc_array) > 0) + foreach ($this->_cc_array as $val) { - foreach ($this->_cc_array as $val) + if ($val !== '' && ! $this->_send_command('to', $val)) { - if ($val !== '' && ! $this->_send_command('to', $val)) - { - $this->_smtp_end(); - return FALSE; - } + $this->_smtp_end(); + return FALSE; } } - if (count($this->_bcc_array) > 0) + foreach ($this->_bcc_array as $val) { - foreach ($this->_bcc_array as $val) + if ($val !== '' && ! $this->_send_command('to', $val)) { - if ($val !== '' && ! $this->_send_command('to', $val)) - { - $this->_smtp_end(); - return FALSE; - } + $this->_smtp_end(); + return FALSE; } } @@ -1969,7 +1963,6 @@ class CI_Email { $this->_send_data($this->_header_str.preg_replace('/^\./m', '..$1', $this->_finalbody)); $this->_send_data('.'); - $reply = $this->_get_smtp_data(); $this->_set_error_message($reply); @@ -1995,9 +1988,7 @@ class CI_Email { */ protected function _smtp_end() { - ($this->smtp_keepalive) - ? $this->_send_command('reset') - : $this->_send_command('quit'); + $this->_send_command($this->smtp_keepalive ? 'reset' : 'quit'); } // -------------------------------------------------------------------- @@ -2016,11 +2007,13 @@ class CI_Email { $ssl = ($this->smtp_crypto === 'ssl') ? 'ssl://' : ''; - $this->_smtp_connect = fsockopen($ssl.$this->smtp_host, - $this->smtp_port, - $errno, - $errstr, - $this->smtp_timeout); + $this->_smtp_connect = fsockopen( + $ssl.$this->smtp_host, + $this->smtp_port, + $errno, + $errstr, + $this->smtp_timeout + ); if ( ! is_resource($this->_smtp_connect)) { @@ -2061,57 +2054,49 @@ class CI_Email { { switch ($cmd) { - case 'hello' : - - if ($this->_smtp_auth OR $this->_get_encoding() === '8bit') - { - $this->_send_data('EHLO '.$this->_get_hostname()); - } - else - { - $this->_send_data('HELO '.$this->_get_hostname()); - } - - $resp = 250; - break; - case 'starttls' : - - $this->_send_data('STARTTLS'); - $resp = 220; - break; - case 'from' : - - $this->_send_data('MAIL FROM:<'.$data.'>'); - $resp = 250; - break; - case 'to' : - - if ($this->dsn) - { - $this->_send_data('RCPT TO:<'.$data.'> NOTIFY=SUCCESS,DELAY,FAILURE ORCPT=rfc822;'.$data); - } - else - { - $this->_send_data('RCPT TO:<'.$data.'>'); - } - - $resp = 250; - break; - case 'data' : - - $this->_send_data('DATA'); - $resp = 354; - break; - case 'reset': - - $this->_send_data('RSET'); - $resp = 250; - break; - case 'quit' : + case 'hello': + if ($this->_smtp_auth OR $this->_get_encoding() === '8bit') + { + $this->_send_data('EHLO '.$this->_get_hostname()); + } + else + { + $this->_send_data('HELO '.$this->_get_hostname()); + } - $this->_send_data('QUIT'); - $resp = 221; - break; + $resp = 250; + break; + case 'starttls': + $this->_send_data('STARTTLS'); + $resp = 220; + break; + case 'from': + $this->_send_data('MAIL FROM:<'.$data.'>'); + $resp = 250; + break; + case 'to': + if ($this->dsn) + { + $this->_send_data('RCPT TO:<'.$data.'> NOTIFY=SUCCESS,DELAY,FAILURE ORCPT=rfc822;'.$data); + } + else + { + $this->_send_data('RCPT TO:<'.$data.'>'); + } + $resp = 250; + break; + case 'data': + $this->_send_data('DATA'); + $resp = 354; + break; + case 'reset': + $this->_send_data('RSET'); + $resp = 250; + break; + case 'quit': + $this->_send_data('QUIT'); + $resp = 221; + break; } $reply = $this->_get_smtp_data(); @@ -2153,7 +2138,6 @@ class CI_Email { } $this->_send_data('AUTH LOGIN'); - $reply = $this->_get_smtp_data(); if (strpos($reply, '503') === 0) // Already authenticated @@ -2167,7 +2151,6 @@ class CI_Email { } $this->_send_data(base64_encode($this->smtp_user)); - $reply = $this->_get_smtp_data(); if (strpos($reply, '334') !== 0) @@ -2177,7 +2160,6 @@ class CI_Email { } $this->_send_data(base64_encode($this->smtp_pass)); - $reply = $this->_get_smtp_data(); if (strpos($reply, '235') !== 0) @@ -2300,34 +2282,15 @@ class CI_Email { */ public function print_debugger($include = array('headers', 'subject', 'body')) { - $msg = ''; - - if (count($this->_debug_msg) > 0) - { - foreach ($this->_debug_msg as $val) - { - $msg .= $val; - } - } + $msg = implode('', $this->_debug_msg); // Determine which parts of our raw data needs to be printed $raw_data = ''; is_array($include) OR $include = array($include); - if (in_array('headers', $include, TRUE)) - { - $raw_data = htmlspecialchars($this->_header_str)."\n"; - } - - if (in_array('subject', $include, TRUE)) - { - $raw_data .= htmlspecialchars($this->_subject)."\n"; - } - - if (in_array('body', $include, TRUE)) - { - $raw_data .= htmlspecialchars($this->_finalbody); - } + in_array('headers', $include, TRUE) && $raw_data = htmlspecialchars($this->_header_str)."\n"; + in_array('subject', $include, TRUE) && $raw_data .= htmlspecialchars($this->_subject)."\n"; + in_array('body', $include, TRUE) && $raw_data .= htmlspecialchars($this->_finalbody); return $msg.($raw_data === '' ? '' : '
'.$raw_data.'
'); } -- cgit v1.2.3-24-g4f1b From 3ecfcaa94bbae55fec8c2c9bbf8524c49816342f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 4 Dec 2017 12:18:20 +0200 Subject: [ci skip] Fix #5348 --- system/libraries/Email.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 6e28989cb..f115d9f40 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1014,7 +1014,7 @@ class CI_Email { */ public function valid_email($email) { - if (function_exists('idn_to_ascii') && strpos($email, '@')) + if (function_exists('idn_to_ascii') && $atpos = strpos($email, '@')) { $email = self::substr($email, 0, ++$atpos).idn_to_ascii(self::substr($email, $atpos), 0, INTL_IDNA_VARIANT_UTS46); } @@ -1821,7 +1821,7 @@ class CI_Email { */ protected function _validate_email_for_shell(&$email) { - if (function_exists('idn_to_ascii') && strpos($email, '@')) + if (function_exists('idn_to_ascii') && $atpos = strpos($email, '@')) { $email = self::substr($email, 0, ++$atpos).idn_to_ascii(self::substr($email, $atpos), 0, INTL_IDNA_VARIANT_UTS46); } -- cgit v1.2.3-24-g4f1b From 058a127a6a5e15f39def341e67a7cd6418882c34 Mon Sep 17 00:00:00 2001 From: Gabriel Caruso Date: Wed, 20 Dec 2017 14:50:39 -0200 Subject: Clean elses --- system/libraries/Email.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index f115d9f40..6d192a6e2 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -941,10 +941,8 @@ class CI_Email { { return 'plain-attach'; } - else - { - return 'plain'; - } + + return 'plain'; } // -------------------------------------------------------------------- @@ -2209,10 +2207,8 @@ class CI_Email { usleep(250000); continue; } - else - { - $timestamp = 0; - } + + $timestamp = 0; } if ($result === FALSE) -- cgit v1.2.3-24-g4f1b From 208381009ed12768478b2e8110bfb6e506acc3e1 Mon Sep 17 00:00:00 2001 From: Master Yoda Date: Tue, 9 Jan 2018 00:53:27 -0800 Subject: Annual copyright update --- system/libraries/Email.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 6d192a6e2..f9a4ae733 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -6,7 +6,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014 - 2017, British Columbia Institute of Technology + * Copyright (c) 2014 - 2018, British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * @package CodeIgniter * @author EllisLab Dev Team * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) - * @copyright Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/) + * @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/) * @license http://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com * @since Version 1.0.0 -- cgit v1.2.3-24-g4f1b From 52a87e506d4fc70bd5922b07a532852d28f28ab6 Mon Sep 17 00:00:00 2001 From: Mehdi Bounya Date: Thu, 17 May 2018 23:41:30 +0000 Subject: http:// to https:// --- system/libraries/Email.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index beb2ffa17..55f81f4bd 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -29,8 +29,8 @@ * @package CodeIgniter * @author EllisLab Dev Team * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) - * @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/) - * @license http://opensource.org/licenses/MIT MIT License + * @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (https://bcit.ca/) + * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com * @since Version 1.0.0 * @filesource @@ -174,7 +174,7 @@ class CI_Email { * Newline character sequence. * Use "\r\n" to comply with RFC 822. * - * @link http://www.ietf.org/rfc/rfc822.txt + * @link https://www.ietf.org/rfc/rfc822.txt * @var string "\r\n" or "\n" */ public $newline = "\n"; // Default newline. "\r\n" or "\n" (Use "\r\n" to comply with RFC 822) @@ -188,7 +188,7 @@ class CI_Email { * switching to "\n", while improper, is the only solution * that seems to work for all environments. * - * @link http://www.ietf.org/rfc/rfc822.txt + * @link https://www.ietf.org/rfc/rfc822.txt * @var string */ public $crlf = "\n"; @@ -1463,7 +1463,7 @@ class CI_Email { * Prep Quoted Printable * * Prepares string for Quoted-Printable Content-Transfer-Encoding - * Refer to RFC 2045 http://www.ietf.org/rfc/rfc2045.txt + * Refer to RFC 2045 https://www.ietf.org/rfc/rfc2045.txt * * @param string * @return string @@ -1472,7 +1472,7 @@ class CI_Email { { // ASCII code numbers for "safe" characters that can always be // used literally, without encoding, as described in RFC 2049. - // http://www.ietf.org/rfc/rfc2049.txt + // https://www.ietf.org/rfc/rfc2049.txt static $ascii_safe_chars = array( // ' ( ) + , - . / : = ? 39, 40, 41, 43, 44, 45, 46, 47, 58, 61, 63, @@ -2210,7 +2210,7 @@ class CI_Email { { break; } - // See https://bugs.php.net/bug.php?id=39598 and http://php.net/manual/en/function.fwrite.php#96951 + // See https://bugs.php.net/bug.php?id=39598 and https://secure.php.net/manual/en/function.fwrite.php#96951 elseif ($result === 0) { if ($timestamp === 0) @@ -2273,7 +2273,7 @@ class CI_Email { * (eg: "[1.2.3.4]"). * * @link https://tools.ietf.org/html/rfc5321#section-2.3.5 - * @link http://cbl.abuseat.org/namingproblems.html + * @link https://cbl.abuseat.org/namingproblems.html * @return string */ protected function _get_hostname() -- cgit v1.2.3-24-g4f1b From 2674bb4eb3ef26ff3408d0eb23b74373d2db0fb3 Mon Sep 17 00:00:00 2001 From: John de Kroon Date: Fri, 25 May 2018 11:46:27 +0200 Subject: Only use the output of idn_to_ascii() if it worked properly --- system/libraries/Email.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index beb2ffa17..cbfd670e7 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1017,7 +1017,11 @@ class CI_Email { $domain = defined('INTL_IDNA_VARIANT_UTS46') ? idn_to_ascii($matches[2], 0, INTL_IDNA_VARIANT_UTS46) : idn_to_ascii($matches[2]); - $email = $matches[1].'@'.$domain; + //If idn_to_ascii() fails, treat it like it doesn't exists + if ($domain !== FALSE) + { + $email = $account.'@'.$domain; + } } return (bool) filter_var($email, FILTER_VALIDATE_EMAIL); @@ -1828,7 +1832,11 @@ class CI_Email { $domain = defined('INTL_IDNA_VARIANT_UTS46') ? idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46) : idn_to_ascii($domain); - $email = $account.'@'.$domain; + //If idn_to_ascii() fails, treat it like it doesn't exists + if ($domain !== FALSE) + { + $email = $account.'@'.$domain; + } } return (filter_var($email, FILTER_VALIDATE_EMAIL) === $email && preg_match('#\A[a-z0-9._+-]+@[a-z0-9.-]{1,253}\z#i', $email)); -- cgit v1.2.3-24-g4f1b From 9bf6753a1bcd54d6ca69fc194efc9f982661aa66 Mon Sep 17 00:00:00 2001 From: John de Kroon Date: Mon, 11 Jun 2018 15:17:06 +0200 Subject: Fixing codestyle --- system/libraries/Email.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index cbfd670e7..943500e7e 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1017,7 +1017,7 @@ class CI_Email { $domain = defined('INTL_IDNA_VARIANT_UTS46') ? idn_to_ascii($matches[2], 0, INTL_IDNA_VARIANT_UTS46) : idn_to_ascii($matches[2]); - //If idn_to_ascii() fails, treat it like it doesn't exists + if ($domain !== FALSE) { $email = $account.'@'.$domain; @@ -1832,7 +1832,7 @@ class CI_Email { $domain = defined('INTL_IDNA_VARIANT_UTS46') ? idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46) : idn_to_ascii($domain); - //If idn_to_ascii() fails, treat it like it doesn't exists + if ($domain !== FALSE) { $email = $account.'@'.$domain; -- cgit v1.2.3-24-g4f1b From 1fd1494c709ced0b20252976c65145e21be046ee Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 12 Jun 2018 16:32:15 +0300 Subject: [ci skip] Correct an erroneous variable name from PR #5510 --- system/libraries/Email.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index d9da06057..e5d9706ac 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1020,7 +1020,7 @@ class CI_Email { if ($domain !== FALSE) { - $email = $account.'@'.$domain; + $email = $matches[1].'@'.$domain; } } -- cgit v1.2.3-24-g4f1b From 8bb638e392f5991c05ec9a1e57b882213844dc6f Mon Sep 17 00:00:00 2001 From: Jim Parry Date: Wed, 26 Dec 2018 21:03:09 -0800 Subject: Update copyright date to 2019 --- system/libraries/Email.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index e5d9706ac..1912e0442 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -6,7 +6,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014 - 2018, British Columbia Institute of Technology + * Copyright (c) 2014 - 2019, British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * @package CodeIgniter * @author EllisLab Dev Team * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) - * @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (https://bcit.ca/) + * @copyright Copyright (c) 2014 - 2019, British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com * @since Version 1.0.0 -- cgit v1.2.3-24-g4f1b From 6ba0207160f8f2b99c79dd285bccf45f574ec660 Mon Sep 17 00:00:00 2001 From: sapics Date: Wed, 24 Jun 2020 11:51:36 +0900 Subject: Fix user guide url Replace from https://codeigniter.com/user_guide/* to https://codeigniter.com/userguide3/* --- system/libraries/Email.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 1912e0442..01f513b26 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -46,7 +46,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); * @subpackage Libraries * @category Libraries * @author EllisLab Dev Team - * @link https://codeigniter.com/user_guide/libraries/email.html + * @link https://codeigniter.com/userguide3/libraries/email.html */ class CI_Email { -- cgit v1.2.3-24-g4f1b