Example #1
0
/**
 * Runs the ACP email parsers
 *	 - returns cut email or original if the cut would result in a blank message
 *
 * @param string $text
 * @return string
 */
function pbe_run_parsers($text)
{
    // Run our parsers, as defined in the ACP,  to remove the original "replied to" message
    $text_save = $text;
    $result = pbe_parse_email_message($text);
    // If we have no message left after running the parser, then they may have replied
    // below and/or inside the original message. People like this should not be allowed
    // to use the net, or be forced to read their own messed up emails
    if (empty($result) || trim(strip_tags(pbe_filter_email_message($text))) === '') {
        $text = $text_save;
    }
    return $text;
}
Example #2
0
/**
 * Converts text / HTML to BBC
 *
 * What it does:
 * - protects certain tags from conversion
 * - strips original message from the reply if possible
 * - If the email is html based, this will convert basic html tags to bbc tags
 * - If the email is plain text it will convert it to html based on markdown text
 * conventions and then that will be converted to bbc.
 *
 * @uses Html2BBC.class.php for the html to bbc conversion
 * @uses markdown.php for text to html conversions
 * @package Maillist
 * @param string $text
 * @param boolean $html
 */
function pbe_email_to_bbc($text, $html)
{
    // Define some things that need to be converted/modified, outside normal html or markup
    $tags = array('~\\*\\*(.*)\\*\\*~isUe' => '\'**\'.ltrim(\'$1\').\'**\'', '~<\\*>~i' => '&lt;*&gt;', '~-{20,}~' => '<hr>', '~#([0-9a-fA-F]{4,6}\\b)~' => '&#35;$1');
    // We are starting with HTML, our goal is to convert the best parts of it to BBC,
    if ($html) {
        // Convert the email-HTML to BBC
        $text = preg_replace(array_keys($tags), array_values($tags), $text);
        require_once SUBSDIR . '/Html2BBC.class.php';
        $bbc_converter = new Html_2_BBC($text);
        $text = $bbc_converter->get_bbc();
        // Run our parsers, as defined in the ACP,  to remove the original "replied to" message
        // before we do any more work.
        $text_save = $text;
        $result = pbe_parse_email_message($text);
        // If we have no message left after running the parser, then they may have replied
        // below and/or inside the original message. People like this should not be allowed
        // to use the net, or be forced to read their own messed up emails
        if (empty($result) || trim(strip_tags(pbe_filter_email_message($text))) === '') {
            $text = $text_save;
        }
    } else {
        // Run the parser to try and remove common mail clients "reply to" stuff
        $text_save = $text;
        $result = pbe_parse_email_message($text);
        // Bottom feeder?  If we have no message they could have replied below the original message
        if (empty($result) || trim(strip_tags(pbe_filter_email_message($text))) === '') {
            $text = $text_save;
        }
        // Set a gmail flag for special quote processing since its quotes are strange
        $gmail = (bool) preg_match('~<div class="gmail_quote">~i', $text);
        // Attempt to fix textual ('>') quotes so we also fix wrapping issues first!
        $text = pbe_fix_email_quotes($text, $html && !$gmail);
        // Convert this (markup) text to html
        $text = preg_replace(array_keys($tags), array_values($tags), $text);
        require_once EXTDIR . '/markdown/markdown.php';
        $text = Markdown($text);
        // Convert any resulting HTML created by markup style text in the email to BBC
        require_once SUBSDIR . '/Html2BBC.class.php';
        $bbc_converter = new Html_2_BBC($text, false);
        $text = $bbc_converter->get_bbc();
    }
    // Some tags often end up as just empty tags - remove those.
    $emptytags = array('~\\[[bisu]\\]\\s*\\[/[bisu]\\]~' => '', '~\\[[bisu]\\]\\s*\\[/[bisu]\\]~' => '', '~(\\n){3,}~si' => "\n\n");
    $text = preg_replace(array_keys($emptytags), array_values($emptytags), $text);
    return $text;
}