Commit 41b988f3 authored by Marius Burkard's avatar Marius Burkard

- improved mailer class (content type encoding and subject encoding)

parent c76e0cc2
Pipeline #418 passed with stage
in 2 minutes and 9 seconds
...@@ -430,6 +430,9 @@ class ispcmail { ...@@ -430,6 +430,9 @@ class ispcmail {
if($text == true && $html == false && $attach == false) { if($text == true && $html == false && $attach == false) {
// only text // only text
$content_type = 'text/plain; charset="' . strtolower($this->mail_charset) . '"'; $content_type = 'text/plain; charset="' . strtolower($this->mail_charset) . '"';
if($this->mail_charset == 'UTF-8') {
$this->headers['Content-Transfer-Encoding'] = '8bit';
}
$textonly = true; $textonly = true;
} elseif($text == true && $html == false && $attach == true) { } elseif($text == true && $html == false && $attach == true) {
// text and attachment // text and attachment
...@@ -440,6 +443,9 @@ class ispcmail { ...@@ -440,6 +443,9 @@ class ispcmail {
} elseif($html == true && $text == false && $attach == false) { } elseif($html == true && $text == false && $attach == false) {
// html only (or text too) // html only (or text too)
$content_type = 'text/html; charset="' . strtolower($this->mail_charset) . '"'; $content_type = 'text/html; charset="' . strtolower($this->mail_charset) . '"';
if($this->mail_charset == 'UTF-8') {
$this->headers['Content-Transfer-Encoding'] = '8bit';
}
$htmlonly = true; $htmlonly = true;
} elseif($html == true && $attach == true) { } elseif($html == true && $attach == true) {
// html and attachments // html and attachments
...@@ -564,17 +570,14 @@ class ispcmail { ...@@ -564,17 +570,14 @@ class ispcmail {
* @access private * @access private
*/ */
private function _encodeSubject($input, $charset = 'ISO-8859-1') { private function _encodeSubject($input, $charset = 'ISO-8859-1') {
/* if(preg_match('/(?:[\xC2-\xDF][\x80-\xBF]|\xE0[\xA0-\xBF][\x80-\xBF]|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}|\xED[\x80-\x9F][\x80-\xBF]|\xF0[\x90-\xBF][\x80-\xBF]{2}|[\xF1-\xF3][\x80-\xBF]{3}|\xF4[\x80-\x8F][\x80-\xBF]{2})/s', $input)) {
if($charset == 'UTF-8' && function_exists('imap_8bit')) { // needs encoding
$input = "=?utf-8?Q?" . imap_8bit($input) . "?="; if(function_exists('imap_8bit')) {
$input = "=?utf-8?Q?" . str_replace("?","=3F", imap_8bit($input)) . "?=";
} else { } else {
preg_match_all('/(\s?\w*[\x80-\xFF]+\w*\s?)/', $input, $matches); $input = '=?utf-8?B?' . base64_encode($input) . '?=';
foreach ($matches[1] as $value) { }
$replacement = preg_replace('/([\x20\x80-\xFF])/e', '"=" . strtoupper(dechex(ord("\1")))', $value);
$input = str_replace($value, '=?' . $charset . '?Q?' . $replacement . '?=', $input);
} }
}*/
$input='=?UTF-8?B?'.base64_encode($input).'?=';
return $input; return $input;
} }
......
...@@ -430,6 +430,9 @@ class ispcmail { ...@@ -430,6 +430,9 @@ class ispcmail {
if($text == true && $html == false && $attach == false) { if($text == true && $html == false && $attach == false) {
// only text // only text
$content_type = 'text/plain; charset="' . strtolower($this->mail_charset) . '"'; $content_type = 'text/plain; charset="' . strtolower($this->mail_charset) . '"';
if($this->mail_charset == 'UTF-8') {
$this->headers['Content-Transfer-Encoding'] = '8bit';
}
$textonly = true; $textonly = true;
} elseif($text == true && $html == false && $attach == true) { } elseif($text == true && $html == false && $attach == true) {
// text and attachment // text and attachment
...@@ -440,6 +443,9 @@ class ispcmail { ...@@ -440,6 +443,9 @@ class ispcmail {
} elseif($html == true && $text == false && $attach == false) { } elseif($html == true && $text == false && $attach == false) {
// html only (or text too) // html only (or text too)
$content_type = 'text/html; charset="' . strtolower($this->mail_charset) . '"'; $content_type = 'text/html; charset="' . strtolower($this->mail_charset) . '"';
if($this->mail_charset == 'UTF-8') {
$this->headers['Content-Transfer-Encoding'] = '8bit';
}
$htmlonly = true; $htmlonly = true;
} elseif($html == true && $attach == true) { } elseif($html == true && $attach == true) {
// html and attachments // html and attachments
...@@ -564,17 +570,14 @@ class ispcmail { ...@@ -564,17 +570,14 @@ class ispcmail {
* @access private * @access private
*/ */
private function _encodeSubject($input, $charset = 'ISO-8859-1') { private function _encodeSubject($input, $charset = 'ISO-8859-1') {
/* if(preg_match('/(?:[\xC2-\xDF][\x80-\xBF]|\xE0[\xA0-\xBF][\x80-\xBF]|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}|\xED[\x80-\x9F][\x80-\xBF]|\xF0[\x90-\xBF][\x80-\xBF]{2}|[\xF1-\xF3][\x80-\xBF]{3}|\xF4[\x80-\x8F][\x80-\xBF]{2})/s', $input)) {
if($charset == 'UTF-8' && function_exists('imap_8bit')) { // needs encoding
$input = "=?utf-8?Q?" . imap_8bit($input) . "?="; if(function_exists('imap_8bit')) {
$input = "=?utf-8?Q?" . str_replace("?","=3F", imap_8bit($input)) . "?=";
} else { } else {
preg_match_all('/(\s?\w*[\x80-\xFF]+\w*\s?)/', $input, $matches); $input = '=?utf-8?B?' . base64_encode($input) . '?=';
foreach ($matches[1] as $value) { }
$replacement = preg_replace('/([\x20\x80-\xFF])/e', '"=" . strtoupper(dechex(ord("\1")))', $value);
$input = str_replace($value, '=?' . $charset . '?Q?' . $replacement . '?=', $input);
} }
}*/
$input='=?UTF-8?B?'.base64_encode($input).'?=';
return $input; return $input;
} }
...@@ -598,6 +601,10 @@ class ispcmail { ...@@ -598,6 +601,10 @@ class ispcmail {
if($this->smtp_crypt == 'tls') { if($this->smtp_crypt == 'tls') {
fputs($this->_smtp_conn, 'STARTTLS' . $this->_crlf); fputs($this->_smtp_conn, 'STARTTLS' . $this->_crlf);
fgets($this->_smtp_conn, 515); fgets($this->_smtp_conn, 515);
stream_context_set_option($this->_smtp_conn, 'ssl', 'verify_host', false);
stream_context_set_option($this->_smtp_conn, 'ssl', 'verify_peer', false);
stream_context_set_option($this->_smtp_conn, 'ssl', 'allow_self_signed', true);
stream_socket_enable_crypto($this->_smtp_conn, true, STREAM_CRYPTO_METHOD_TLS_CLIENT); stream_socket_enable_crypto($this->_smtp_conn, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment