Пример #1
0
/**
 *This function handles finding and setting the correct subject
 * @return array - (subject,content)
 */
function GetSubject(&$mimeDecodedEmail, &$content, $config)
{
    global $charset;
    //assign the default title/subject
    if ($mimeDecodedEmail->headers['subject'] == NULL) {
        if ($config["ALLOW_SUBJECT_IN_MAIL"]) {
            list($subject, $content) = ParseInMessageSubject($content, $config['DEFAULT_TITLE']);
        } else {
            $subject = $config["DEFAULT_TITLE"];
        }
        $mimeDecodedEmail->headers['subject'] = $subject;
    } else {
        $subject = $mimeDecodedEmail->headers['subject'];
        if ($mimeDecodedEmail->headers["content-transfer-encoding"] != '') {
            $encoding = $mimeDecodedEmail->headers["content-transfer-encoding"];
        } else {
            if ($mimeDecodedEmail->ctype_parameters["content-transfer-encoding"] != '') {
                $encoding = $mimeDecodedEmail->ctype_parameters["content-transfer-encoding"];
            } else {
                $encoding = '7bit';
            }
        }
        if (function_exists(imap_mime_header_decode)) {
            $subject = '';
            //$elements=imap_mime_header_decode($mimeDecodedEmail->headers['subject']);
            //$text = "=?utf-8?b?w6XDpMO2?= unicode";
            $text = $mimeDecodedEmail->headers['subject'];
            //$text="test emails with ISO 8859-2 cahracters ąęśćółńżźĄĘŚÓŁŃŻŹ";
            //echo "text='$text'\n";
            $elements = imap_mime_header_decode($text);
            for ($i = 0; $i < count($elements); $i++) {
                $thischarset = $elements[$i]->charset;
                if ($thischarset == 'default') {
                    $thischarset = $charset;
                }
                //echo "Charset: {$thischarset}\n";
                //echo "Text: ". utf8_encode($elements[$i]->text). "\n\n";
                $subject .= HandleMessageEncoding($encoding, $thischarset, $elements[$i]->text, $config['MESSAGE_ENCODING'], $config['MESSAGE_DEQUOTE']);
                //echo "subject=$subject\n";
            }
            //echo "now subject= $subject\n";
            //if ($element->charset!='') {
            //$charset = $element[0]->charset;
            //echo "charset='$charset'\n";
            // }
        }
        if (!$config["ALLOW_HTML_IN_SUBJECT"]) {
            $subject = htmlentities($subject);
        }
    }
    //This is for ISO-2022-JP - Can anyone confirm that this is still neeeded?
    // escape sequence is 'ESC $ B' == 1b 24 42 hex.
    if (strpos($subject, "\$B") !== false) {
        // found iso-2022-jp escape sequence in subject... convert!
        $subject = iconv("ISO-2022-JP//TRANSLIT", "UTF-8", $subject);
    }
    return $subject;
}
Пример #2
0
/**
 *This function handles finding and setting the correct subject
 * @return array - (subject,content)
 */
function GetSubject(&$mimeDecodedEmail, &$content)
{
    $config = GetConfig();
    //assign the default title/subject
    if ($mimeDecodedEmail->headers['subject'] == NULL) {
        if ($config["ALLOW_SUBJECT_IN_MAIL"]) {
            list($subject, $content) = ParseInMessageSubject($content);
        } else {
            $subject = $config["DEFAULT_TITLE"];
        }
        $mimeDecodedEmail->headers['subject'] = $subject;
    } else {
        $subject = $mimeDecodedEmail->headers['subject'];
        HandleMessageEncoding($mimeDecodedEmail->headers["content-transfer-encoding"], $mimeDecodedEmail->ctype_parameters["charset"], $subject);
        if (!$config["ALLOW_HTML_IN_SUBJECT"]) {
            $subject = htmlentities($subject);
        }
    }
    //This is for ISO-2022-JP - Can anyone confirm that this is still neeeded?
    // escape sequence is 'ESC $ B' == 1b 24 42 hex.
    if (strpos($subject, "\$B") !== false) {
        // found iso-2022-jp escape sequence in subject... convert!
        $subject = iconv("ISO-2022-JP//TRANSLIT", "UTF-8", $subject);
    }
    return $subject;
}