diff --git a/includes/qcodo/_core/framework/QEmailServer.class.php b/includes/qcodo/_core/framework/QEmailServer.class.php index 67b00d88..531bb34e 100644 --- a/includes/qcodo/_core/framework/QEmailServer.class.php +++ b/includes/qcodo/_core/framework/QEmailServer.class.php @@ -512,7 +512,7 @@ protected function CalculateMessageBody($strEncodingType, $strBoundary, $strAltB $strBody .= sprintf("--%s\r\n", $strAltBoundary); $strBody .= sprintf("Content-Type: text/plain; charset=\"%s\"\r\n", $strEncodingType); $strBody .= sprintf("Content-Transfer-Encoding: quoted-printable\r\n\r\n"); - $strBody .= self::QuotedPrintableEncode($this->Body); + $strBody .= QString::QuotedPrintableEncode($this->Body); $strBody .= "\r\n\r\n"; // Provide Html Version of Email (if applicable) @@ -520,7 +520,7 @@ protected function CalculateMessageBody($strEncodingType, $strBoundary, $strAltB $strBody .= sprintf("--%s\r\n", $strAltBoundary); $strBody .= sprintf("Content-Type: text/html; charset=\"%s\"\r\n", $strEncodingType); $strBody .= sprintf("Content-Transfer-Encoding: quoted-printable\r\n\r\n"); - $strBody .= self::QuotedPrintableEncode($this->HtmlBody); + $strBody .= QString::QuotedPrintableEncode($this->HtmlBody); $strBody .= "\r\n\r\n"; } @@ -545,7 +545,7 @@ protected function CalculateMessageBody($strEncodingType, $strBoundary, $strAltB // Plain-Text Version of the Body for Plain-Text Message Only } else { - $strBody = self::QuotedPrintableEncode($this->Body); + $strBody = QString::QuotedPrintableEncode($this->Body); } return $strBody; @@ -577,10 +577,15 @@ public function CalculateMessageHeaderAndBody($strEncodingType = null, QDateTime // Additional "Optional" Headers if ($this->Subject) { - $strSubject = self::QuotedPrintableEncode($this->Subject); - $strSubject = str_replace("=\r\n", "", $strSubject); - $strSubject = str_replace('?', '=3F', $strSubject); - $this->SetHeader('Subject', sprintf("=?%s?Q?%s?=", $strEncodingType, $strSubject)); + // Encode to UTF8 Subject if Applicable + if (QString::IsContainsUtf8($this->Subject)) { + $strSubject = QString::QuotedPrintableEncode($this->Subject); + $strSubject = str_replace("=\r\n", "", $strSubject); + $strSubject = str_replace('?', '=3F', $strSubject); + $this->SetHeader('Subject', sprintf("=?%s?Q?%s?=", $strEncodingType, $strSubject)); + } else { + $this->SetHeader('Subject', $this->Subject); + } } if ($this->Cc) $this->SetHeader('Cc', $this->Cc); @@ -653,22 +658,5 @@ public function __set($strName, $mixValue) { throw $objExc; } } - - /** - * Encodes a given 8-bit string into a quoted-printable string, - * @param string $strString the string to encode - * @return string the encoded string - */ - public static function QuotedPrintableEncode($strString) { - if (function_exists('quoted_printable_encode')) { - $strText = quoted_printable_encode($strString); - } else { - $strText = preg_replace( '/[^\x21-\x3C\x3E-\x7E\x09\x20]/e', 'sprintf( "=%02X", ord ( "$0" ) ) ;', $strString ); - preg_match_all( '/.{1,73}([^=]{0,2})?/', $strText, $arrMatch ); - $strText = implode( '=' . "\r\n", $arrMatch[0] ); - } - - return $strText; - } } ?> \ No newline at end of file diff --git a/includes/qcodo/_core/framework/QString.class.php b/includes/qcodo/_core/framework/QString.class.php index ea3fca2e..0e76f29b 100644 --- a/includes/qcodo/_core/framework/QString.class.php +++ b/includes/qcodo/_core/framework/QString.class.php @@ -225,5 +225,41 @@ public static function IsLengthBeetween($strString, $intMinimumLength, $intMaxim public static function ConvertToCamelCase($strString) { return str_replace(' ', '', ucwords(str_replace('_', ' ', strtolower($strString)))); } + + /** + * Encodes a given 8-bit string into a quoted-printable string, + * @param string $strString the string to encode + * @return string the encoded string + */ + public static function QuotedPrintableEncode($strString) { + if (function_exists('quoted_printable_encode')) { + $strText = quoted_printable_encode($strString); + } else { + $strText = preg_replace( '/[^\x21-\x3C\x3E-\x7E\x09\x20]/e', 'sprintf( "=%02X", ord ( "$0" ) ) ;', $strString ); + preg_match_all( '/.{1,73}([^=]{0,2})?/', $strText, $arrMatch ); + $strText = implode( '=' . "\r\n", $arrMatch[0] ); + } + + return $strText; + } + + /** + * Returns whether or not the given string contains any UTF-8 encoded characters. + * Uses regexp pattern as originally defined from http://w3.org/International/questions/qa-forms-utf-8.html + * and modified by chris@w3style.co.uk for efficiency. + * @param string $strString + * @return boolean whether or not the string contains any UTF-8 characters + */ + public static function IsContainsUtf8($strString) { + return preg_match('%(?: + [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte + |\xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs + |[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte + |\xED[\x80-\x9F][\x80-\xBF] # excluding surrogates + |\xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3 + |[\xF1-\xF3][\x80-\xBF]{3} # planes 4-15 + |\xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 + )+%xs', $strString); + } } ?> \ No newline at end of file