Exemplo n.º 1
0
/**
 * Calls the necessary functions to extract and format the message so its ready for posting
 *
 * What it does:
 * - Converts an email response (text or html) to a BBC equivalant via pbe_Email_to_bbc
 * - Formats the email response so it looks structured and not chopped up (via pbe_fix_email_body)
 *
 * @package Maillist
 * @param boolean $html
 * @param Email_Parse $email_message
 * @param mixed[] $pbe
 */
function pbe_load_text(&$html, $email_message, $pbe)
{
    if (!$html || $html && preg_match_all('~<table.*?>~i', $email_message->body, $match) >= 2) {
        // Some mobile responses wrap everything in a table structure so use plain text
        $text = $email_message->plain_body;
        $html = false;
    } else {
        $text = un_htmlspecialchars($email_message->body);
    }
    // Run filters now, before the data is manipulated
    $text = pbe_filter_email_message($text);
    // Convert to BBC and format it so it looks like a post
    $text = pbe_email_to_bbc($text, $html);
    $pbe['profile']['real_name'] = isset($pbe['profile']['real_name']) ? $pbe['profile']['real_name'] : '';
    $text = pbe_fix_email_body($text, $html, $pbe['profile']['real_name'], empty($email_message->_converted_utf8) ? $email_message->headers['x-parameters']['content-type']['charset'] : 'UTF-8');
    // Do we even have a message left to post?
    $text = Util::htmltrim($text);
    if (empty($text)) {
        return;
    }
    if ($email_message->message_type !== 'p') {
        // Prepare it for the database
        require_once SUBSDIR . '/Post.subs.php';
        preparsecode($text);
    }
    return $text;
}
Exemplo n.º 2
0
/**
 * Prepares the email body so that it looks like a forum post
 *
 * What it does:
 * - Removes extra content as defined in the ACP filters
 * - Fixes quotes and quote levels
 * - Re-flows (unfolds) an email using the EmailFormat.class
 * - Attempts to remove any exposed email address
 *
 * @uses EmailFormat.class.php
 * @package Maillist
 * @param string $body
 * @param boolean $html
 * @param string $real_name
 * @param string $charset character set of the text
 */
function pbe_fix_email_body($body, $html = false, $real_name = '', $charset = 'UTF-8')
{
    global $txt;
    // Remove the \r's now so its done
    $body = trim(str_replace("\r", '', $body));
    // Remove the riff-raff as defined by the ACP filters
    $body = pbe_filter_email_message($body);
    // Any old school email john smith wrote: etc style quotes that we need to update
    $body = pbe_fix_client_quotes($body);
    // Attempt to remove any exposed email addresses that are in the reply
    $body = preg_replace('~>' . $txt['to'] . '(.*)@(.*?)(?:\\n|\\[br\\])~i', '', $body);
    $body = preg_replace('~\\b\\s?[a-z0-9._%+-]+@[a-zZ0-9.-]+\\.[a-z]{2,4}\\b.?' . $txt['email_wrote'] . ':\\s?~i', '', $body);
    $body = preg_replace('~<(.*?)>(.*@.*?)(?:\\n|\\[br\\])~', '$1' . "\n", $body);
    $body = preg_replace('~' . $txt['email_quoting'] . ' (.*) (?:<|&lt;|\\[email\\]).*?@.*?(?:>|&gt;|\\[/email\\]):~i', '', $body);
    // Remove multiple sequential blank lines, again
    $body = preg_replace('~(\\n\\s?){3,}~si', "\n\n", $body);
    // Check for blank quotes
    $body = preg_replace('~(\\[quote\\s?([a-zA-Z0-9"=]*)?\\]\\s*(\\[br\\]\\s*)?\\[/quote\\])~s', '', $body);
    // Reflow and Cleanup this message to something that looks normal-er
    require_once SUBSDIR . '/EmailFormat.class.php';
    $formatter = new Email_Format();
    $body = $formatter->reflow($body, $html, $real_name, $charset);
    return $body;
}