Skip to content

Commit 41b988f

Browse files
author
Marius Burkard
committed
- improved mailer class (content type encoding and subject encoding)
1 parent c76e0cc commit 41b988f

File tree

2 files changed

+30
-20
lines changed

2 files changed

+30
-20
lines changed

interface/lib/classes/ispcmail.inc.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,9 @@ private function create() {
430430
if($text == true && $html == false && $attach == false) {
431431
// only text
432432
$content_type = 'text/plain; charset="' . strtolower($this->mail_charset) . '"';
433+
if($this->mail_charset == 'UTF-8') {
434+
$this->headers['Content-Transfer-Encoding'] = '8bit';
435+
}
433436
$textonly = true;
434437
} elseif($text == true && $html == false && $attach == true) {
435438
// text and attachment
@@ -440,6 +443,9 @@ private function create() {
440443
} elseif($html == true && $text == false && $attach == false) {
441444
// html only (or text too)
442445
$content_type = 'text/html; charset="' . strtolower($this->mail_charset) . '"';
446+
if($this->mail_charset == 'UTF-8') {
447+
$this->headers['Content-Transfer-Encoding'] = '8bit';
448+
}
443449
$htmlonly = true;
444450
} elseif($html == true && $attach == true) {
445451
// html and attachments
@@ -564,17 +570,14 @@ private function _encodeHeader($input, $charset = 'ISO-8859-1') {
564570
* @access private
565571
*/
566572
private function _encodeSubject($input, $charset = 'ISO-8859-1') {
567-
/*
568-
if($charset == 'UTF-8' && function_exists('imap_8bit')) {
569-
$input = "=?utf-8?Q?" . imap_8bit($input) . "?=";
570-
} else {
571-
preg_match_all('/(\s?\w*[\x80-\xFF]+\w*\s?)/', $input, $matches);
572-
foreach ($matches[1] as $value) {
573-
$replacement = preg_replace('/([\x20\x80-\xFF])/e', '"=" . strtoupper(dechex(ord("\1")))', $value);
574-
$input = str_replace($value, '=?' . $charset . '?Q?' . $replacement . '?=', $input);
573+
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)) {
574+
// needs encoding
575+
if(function_exists('imap_8bit')) {
576+
$input = "=?utf-8?Q?" . str_replace("?","=3F", imap_8bit($input)) . "?=";
577+
} else {
578+
$input = '=?utf-8?B?' . base64_encode($input) . '?=';
575579
}
576-
}*/
577-
$input='=?UTF-8?B?'.base64_encode($input).'?=';
580+
}
578581

579582
return $input;
580583
}

server/lib/classes/ispcmail.inc.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,9 @@ private function create() {
430430
if($text == true && $html == false && $attach == false) {
431431
// only text
432432
$content_type = 'text/plain; charset="' . strtolower($this->mail_charset) . '"';
433+
if($this->mail_charset == 'UTF-8') {
434+
$this->headers['Content-Transfer-Encoding'] = '8bit';
435+
}
433436
$textonly = true;
434437
} elseif($text == true && $html == false && $attach == true) {
435438
// text and attachment
@@ -440,6 +443,9 @@ private function create() {
440443
} elseif($html == true && $text == false && $attach == false) {
441444
// html only (or text too)
442445
$content_type = 'text/html; charset="' . strtolower($this->mail_charset) . '"';
446+
if($this->mail_charset == 'UTF-8') {
447+
$this->headers['Content-Transfer-Encoding'] = '8bit';
448+
}
443449
$htmlonly = true;
444450
} elseif($html == true && $attach == true) {
445451
// html and attachments
@@ -564,17 +570,14 @@ private function _encodeHeader($input, $charset = 'ISO-8859-1') {
564570
* @access private
565571
*/
566572
private function _encodeSubject($input, $charset = 'ISO-8859-1') {
567-
/*
568-
if($charset == 'UTF-8' && function_exists('imap_8bit')) {
569-
$input = "=?utf-8?Q?" . imap_8bit($input) . "?=";
570-
} else {
571-
preg_match_all('/(\s?\w*[\x80-\xFF]+\w*\s?)/', $input, $matches);
572-
foreach ($matches[1] as $value) {
573-
$replacement = preg_replace('/([\x20\x80-\xFF])/e', '"=" . strtoupper(dechex(ord("\1")))', $value);
574-
$input = str_replace($value, '=?' . $charset . '?Q?' . $replacement . '?=', $input);
573+
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)) {
574+
// needs encoding
575+
if(function_exists('imap_8bit')) {
576+
$input = "=?utf-8?Q?" . str_replace("?","=3F", imap_8bit($input)) . "?=";
577+
} else {
578+
$input = '=?utf-8?B?' . base64_encode($input) . '?=';
575579
}
576-
}*/
577-
$input='=?UTF-8?B?'.base64_encode($input).'?=';
580+
}
578581

579582
return $input;
580583
}
@@ -598,6 +601,10 @@ private function _smtp_login() {
598601
if($this->smtp_crypt == 'tls') {
599602
fputs($this->_smtp_conn, 'STARTTLS' . $this->_crlf);
600603
fgets($this->_smtp_conn, 515);
604+
605+
stream_context_set_option($this->_smtp_conn, 'ssl', 'verify_host', false);
606+
stream_context_set_option($this->_smtp_conn, 'ssl', 'verify_peer', false);
607+
stream_context_set_option($this->_smtp_conn, 'ssl', 'allow_self_signed', true);
601608
stream_socket_enable_crypto($this->_smtp_conn, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
602609
}
603610

0 commit comments

Comments
 (0)