tbrehm
2013-06-11 0e7cfad31e708f9b82d1dae3ee80defa5b19e406
Fixed charset issue in mail library.
1 files modified
38 ■■■■ changed files
interface/lib/classes/ispcmail.inc.php 38 ●●●● patch | view | raw | blame | history
interface/lib/classes/ispcmail.inc.php
@@ -414,15 +414,21 @@
            $this->body = "This is a multi-part message in MIME format.\n\n";
            
            if($text) {
                $this->body .= "--{$this->mime_boundary}\n" .
                /*$this->body .= "--{$this->mime_boundary}\n" .
                              "Content-Type:text/plain; charset=\"" . strtolower($this->mail_charset) . "\"\n" .
                              "Content-Transfer-Encoding: 7bit\n\n" . $this->text_part . "\n\n";
                              "Content-Transfer-Encoding: 7bit\n\n" . $this->text_part . "\n\n";*/
                $this->body .= "--{$this->mime_boundary}\n" .
                              "Content-Type:text/plain; charset=\"UTF-8\"\n" .
                              "Content-Transfer-Encoding: 8bit\n\n" . $this->text_part . "\n\n";
            }
            
            if($html) {
                $this->body .= "--{$this->mime_boundary}\n" .
                /*$this->body .= "--{$this->mime_boundary}\n" .
                               "Content-Type:text/html; charset=\"" . strtolower($this->mail_charset) . "\"\n" . 
                               "Content-Transfer-Encoding: 7bit\n\n" . $this->html_part . "\n\n";
                               "Content-Transfer-Encoding: 7bit\n\n" . $this->html_part . "\n\n";*/
                $this->body .= "--{$this->mime_boundary}\n" .
                              "Content-Type:text/html; charset=\"UTF-8\"\n" .
                              "Content-Transfer-Encoding: 8bit\n\n" . $this->html_part . "\n\n";
            }
            
            if($attach) {
@@ -506,6 +512,27 @@
    }
    
    /**
    * Function to encode the subject if necessary
    * according to RFC2047
    * @access private
    */
    private function _encodeSubject($input, $charset = 'ISO-8859-1') {
        /*
        if($charset == 'UTF-8' && function_exists('imap_8bit')) {
            $input = "=?utf-8?Q?" . imap_8bit($input) . "?=";
        } else {
            preg_match_all('/(\s?\w*[\x80-\xFF]+\w*\s?)/', $input, $matches);
            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;
    }
    /**
     * @access private
     */
    private function _smtp_login() {
@@ -578,7 +605,8 @@
            //$subject = $this->_encodeHeader($this->headers['Subject'], $this->mail_charset);
            $subject = $this->headers['Subject'];
            
            $enc_subject = $this->_encodeHeader($subject, $this->mail_charset);
            //$enc_subject = $this->_encodeHeader($subject, $this->mail_charset);
            $enc_subject = $this->_encodeSubject($subject, $this->mail_charset);
            unset($this->headers['Subject']);
        }