Пример #1
1
/**
 * This is the main handler for all of the processing
 */
function PostEmail($poster, $mimeDecodedEmail, $config)
{
    postie_disable_revisions();
    extract($config);
    /* in order to do attachments correctly, we need to associate the
       attachments with a post. So we add the post here, then update it */
    $tmpPost = array('post_title' => 'tmptitle', 'post_content' => 'tmpPost');
    $post_id = wp_insert_post($tmpPost);
    DebugEcho("new post id is {$post_id}");
    $is_reply = false;
    $postmodifiers = new PostiePostModifiers();
    $details = CreatePost($poster, $mimeDecodedEmail, $post_id, $is_reply, $config, $postmodifiers);
    $details = apply_filters('postie_post', $details);
    $details = apply_filters('postie_post_before', $details);
    DebugEcho("Post postie_post filter");
    DebugDump($details);
    DebugEcho("Post modifiers");
    DebugDump($postmodifiers);
    if (empty($details)) {
        // It is possible that the filter has removed the post, in which case, it should not be posted.
        // And if we created a placeholder post (because this was not a reply to an existing post),
        // then it should be removed
        if (!$is_reply) {
            wp_delete_post($post_id);
            EchoInfo("postie_post filter cleared the post, not saving.");
        }
    } else {
        DisplayEmailPost($details);
        PostToDB($details, $is_reply, $custom_image_field, $postmodifiers);
        if ($confirmation_email != '') {
            if ($confirmation_email == 'sender') {
                $recipients = array($details['email_author']);
            } elseif ($confirmation_email == 'admin') {
                $recipients = array(get_option("admin_email"));
            } elseif ($confirmation_email == 'both') {
                $recipients = array($details['email_author'], get_option("admin_email"));
            }
            MailToRecipients($mimeDecodedEmail, false, $recipients, false, false);
        }
    }
    postie_disable_revisions(true);
    DebugEcho("Done");
}
Пример #2
0
/**
 * This is the main handler for all of the processing
 */
function PostEmail($poster, $mimeDecodedEmail)
{
    $config = GetConfig();
    $GLOBALS["POSTIE_IMAGE_ROTATION"] = 0;
    $attachments = array("html" => array(), "cids" => array(), "image_files" => array());
    print "<p>Message Id is :" . $mimeDecodedEmail->headers["message-id"] . "</p><br/>\n";
    print "<p>Email has following attachments:</p>";
    foreach ($mimeDecodedEmail->parts as $parts) {
        print "<p>" . $parts->ctype_primary . " " . $parts->ctype_secondary . "</p><br />\n";
    }
    FilterTextParts($mimeDecodedEmail);
    #print("<p>Email has following attachments after filtering:");
    #    foreach($mimeDecodedEmail->parts as $parts) {
    #        print("<p>".$parts->ctype_primary ." ".$parts->ctype_secondary) ."<br />\n";
    #    }
    $content = GetContent($mimeDecodedEmail, $attachments);
    $subject = GetSubject($mimeDecodedEmail, $content);
    $rotation = GetRotation($mimeDecodedEmail, $content);
    if ($rotation != "0" && count($attachments["image_files"])) {
        RotateImages($rotation, $attachments["image_files"]);
    }
    SpecialMessageParsing($content, $attachments);
    $message_date = NULL;
    if (array_key_exists("date", $mimeDecodedEmail->headers) && !empty($mimeDecodedEmail->headers["date"])) {
        $message_date = HandleMessageEncoding($mimeDecodedEmail->headers["content-transfer-encoding"], $mimeDecodedEmail->ctype_parameters["charset"], $mimeDecodedEmail->headers["date"]);
    }
    list($post_date, $post_date_gmt) = DeterminePostDate($content, $message_date);
    ubb2HTML($content);
    $content = FilterNewLines($content);
    $post_categories = GetPostCategories($subject);
    $comment_status = AllowCommentsOnPost($content);
    $details = array('post_author' => $poster, 'post_date' => $post_date, 'post_date_gmt' => $post_date_gmt, 'post_content' => preg_replace("/'/", "\\'", $content), 'post_title' => preg_replace("/'/", "\\'", $subject), 'post_modified' => $post_date, 'post_modified_gmt' => $post_date_gmt, 'ping_status' => get_option('default_ping_status'), 'post_category' => $post_categories, 'comment_status' => $comment_status, 'post_name' => sanitize_title($subject), 'post_status' => 'publish');
    DisplayEmailPost($details);
    PostToDB($details);
}
Пример #3
0
/**
 * This is the main handler for all of the processing
 */
function PostEmail($poster, $mimeDecodedEmail)
{
    $config = GetConfig();
    $GLOBALS["POSTIE_IMAGE_ROTATION"] = 0;
    $attachments = array("html" => array(), "cids" => array(), "image_files" => array());
    print "<p>Message Id is :" . $mimeDecodedEmail->headers["message-id"] . "</p><br/>\n";
    print "<p>Email has following attachments:</p>";
    foreach ($mimeDecodedEmail->parts as $parts) {
        print "<p>" . $parts->ctype_primary . " " . $parts->ctype_secondary . "</p><br />\n";
    }
    FilterTextParts($mimeDecodedEmail);
    #print("<p>Email has following attachments after filtering:");
    #    foreach($mimeDecodedEmail->parts as $parts) {
    #        print("<p>".$parts->ctype_primary ." ".$parts->ctype_secondary) ."<br />\n";
    #    }
    $content = GetContent($mimeDecodedEmail, $attachments);
    $subject = GetSubject($mimeDecodedEmail, $content);
    echo "the subject is {$subject}, right after calling GetSubject\n";
    $rotation = GetRotation($mimeDecodedEmail, $content);
    if ($rotation != "0" && count($attachments["image_files"])) {
        RotateImages($rotation, $attachments["image_files"]);
    }
    SpecialMessageParsing($content, $attachments);
    $postAuthorDetails = getPostAuthorDetails($subject, $content, $mimeDecodedEmail);
    $message_date = NULL;
    if (array_key_exists("date", $mimeDecodedEmail->headers) && !empty($mimeDecodedEmail->headers["date"])) {
        HandleMessageEncoding($mimeDecodedEmail->headers["content-transfer-encoding"], $mimeDecodedEmail->ctype_parameters["charset"], $mimeDecodedEmail->headers["date"]);
        $message_date = $mimeDecodedEmail->headers['date'];
    }
    list($post_date, $post_date_gmt) = DeterminePostDate($content, $message_date);
    ubb2HTML($content);
    //$content = FilterNewLines($content);
    //$content = FixEmailQuotes($content);
    $id = checkReply($subject);
    $post_categories = GetPostCategories($subject);
    echo "the subject is {$subject}, right after calling GetPostCategories\n";
    $comment_status = AllowCommentsOnPost($content);
    if ((empty($id) || is_null($id)) && $config['ADD_META'] == 'yes') {
        if ($config['WRAP_PRE'] == 'yes') {
            $content = $postAuthorDetails['content'] . "<pre>\n" . $content . "</pre>\n";
        } else {
            $content = $postAuthorDetails['content'] . $content;
        }
        echo "id is empty\n";
    } else {
        if ($config['WRAP_PRE'] == 'yes') {
            $content = "<pre>\n" . $content . "</pre>\n";
        }
    }
    $details = array('post_author' => $poster, 'comment_author' => $postAuthorDetails['author'], 'email_author' => $postAuthorDetails['email'], 'post_date' => $post_date, 'post_date_gmt' => $post_date_gmt, 'post_content' => addslashes($content), 'post_title' => preg_replace("/'/", "\\'", $subject), 'post_modified' => $post_date, 'post_modified_gmt' => $post_date_gmt, 'ping_status' => get_option('default_ping_status'), 'post_category' => $post_categories, 'comment_status' => $comment_status, 'post_name' => sanitize_title($subject), 'ID' => $id, 'post_status' => 'publish');
    DisplayEmailPost($details);
    PostToDB($details);
}
Пример #4
0
/**
 * This is the main handler for all of the processing
 */
function PostEmail($poster, $mimeDecodedEmail, $config)
{
    $debug = true;
    $attachments = array("html" => array(), "cids" => array(), "image_files" => array());
    print "<p>Message Id is :" . htmlentities($mimeDecodedEmail->headers["message-id"]) . "</p><br/>\n";
    print "<p>Email has following attachments:</p>";
    //foreach($mimeDecodedEmail->parts as $parts) {
    // print("<p>".$parts->ctype_primary ." ".$parts->ctype_secondary) ."</p>\n";
    //}
    FilterTextParts($mimeDecodedEmail, $config['PREFER_TEXT_TYPE']);
    $tmpPost = array('post_title' => 'tmptitle', 'post_content' => 'tmpPost');
    /* in order to do attachments correctly, we need to associate the
      attachments with a post. So we add the post here, then update it 
      */
    $post_id = wp_insert_post($tmpPost);
    if ($debug) {
        echo "the id is {$post_id}\n";
    }
    $content = GetContent($mimeDecodedEmail, $attachments, $post_id, $config);
    if ($debug) {
        echo "the content is {$content}\n";
    }
    $subject = GetSubject($mimeDecodedEmail, $content, $config);
    if ($debug) {
        echo "the subject is {$subject}, right after calling GetSubject\n";
    }
    $customImages = SpecialMessageParsing($content, $attachments, $config);
    $post_excerpt = GetPostExcerpt($content, $config['FILTERNEWLINES'], $config['CONVERTNEWLINE']);
    $postAuthorDetails = getPostAuthorDetails($subject, $content, $mimeDecodedEmail);
    $message_date = NULL;
    if (array_key_exists("date", $mimeDecodedEmail->headers) && !empty($mimeDecodedEmail->headers["date"])) {
        $message_date = HandleMessageEncoding($mimeDecodedEmail->headers["content-transfer-encoding"], $mimeDecodedEmail->ctype_parameters["charset"], $mimeDecodedEmail->headers["date"], $config['MESSAGE_ENCODING'], $config['MESSAGE_DEQUOTE']);
        //$message_date = $mimeDecodedEmail->headers['date'];
    }
    list($post_date, $post_date_gmt, $delay) = DeterminePostDate($content, $message_date, $config['TIME_OFFSET']);
    ubb2HTML($content);
    if ($config['CONVERTURLS']) {
        $content = clickableLink($content, $config['SHORTCODE']);
    }
    //$content = FixEmailQuotes($content);
    $id = checkReply($subject);
    $post_categories = GetPostCategories($subject, $config['DEFAULT_POST_CATEGORY']);
    $post_tags = postie_get_tags($content, $config['DEFAULT_POST_TAGS']);
    $comment_status = AllowCommentsOnPost($content);
    if (empty($id) || is_null($id)) {
        $id = $post_id;
        $isReply = false;
        if ($config['ADD_META'] == 'yes') {
            if ($config['WRAP_PRE'] == 'yes') {
                $content = $postAuthorDetails['content'] . "<pre>\n" . $content . "</pre>\n";
                $content = "<pre>\n" . $content . "</pre>\n";
            } else {
                $content = $postAuthorDetails['content'] . $content;
                $content = $content;
            }
        } else {
            if ($config['WRAP_PRE'] == 'yes') {
                $content = "<pre>\n" . $content . "</pre>\n";
            }
        }
    } else {
        $isReply = true;
        // strip out quoted content
        $lines = explode("\n", $content);
        //$lines=preg_split('/([\r\n]|<br \/>)/',$content);
        $newContents = '';
        foreach ($lines as $line) {
            //$match=preg_match("/^>.*/i",$line);
            //echo "line=$line,  match=$match";
            if (preg_match("/^>.*/i", $line) == 0 && preg_match("/^(from|subject|to|date):.*?/i", $line) == 0 && preg_match("/^-+.*?(from|subject|to|date).*?/i", $line) == 0 && preg_match("/^on.*?wrote:\$/i", $line) == 0 && preg_match("/^-+\\s*forwarded\\s*message\\s*-+/i", $line) == 0) {
                $newContents .= "{$line}\n";
            }
        }
        $content = $newContents;
        wp_delete_post($post_id);
    }
    if ($config['FILTERNEWLINES']) {
        $content = FilterNewLines($content, $config['CONVERTNEWLINE']);
    }
    if ($delay != 0 && $config['POST_STATUS'] == 'publish') {
        $post_status = 'future';
    } else {
        $post_status = $config['POST_STATUS'];
    }
    $details = array('post_author' => $poster, 'comment_author' => $postAuthorDetails['author'], 'comment_author_url' => $postAuthorDetails['comment_author_url'], 'user_ID' => $postAuthorDetails['user_ID'], 'email_author' => $postAuthorDetails['email'], 'post_date' => $post_date, 'post_content' => apply_filters('content_save_pre', $content), 'post_title' => $subject, 'ping_status' => get_option('default_ping_status'), 'post_category' => $post_categories, 'tags_input' => $post_tags, 'comment_status' => $comment_status, 'post_name' => sanitize_title($subject), 'post_excerpt' => $post_excerpt, 'ID' => $id, 'customImages' => $customImages, 'post_status' => $post_status);
    $details = apply_filters('postie_post', $details);
    DisplayEmailPost($details);
    PostToDB($details, $isReply, $config['POST_TO_DB'], $config['CUSTOM_IMAGE_FIELD']);
    if ($config['CONFIRMATION_EMAIL']) {
        MailToRecipients($mimeDecodedEmail, false, array($postAuthorDetails['email']), false, false);
    }
}
Пример #5
0
/**
 * This is the main handler for all of the processing
 */
function PostEmail($poster, $mimeDecodedEmail, $config)
{
    extract($config);
    $post_to_db = true;
    $attachments = array("html" => array(), "cids" => array(), "image_files" => array());
    print "<p>Message Id is :" . htmlentities($mimeDecodedEmail->headers["message-id"]) . "</p><br/>\n";
    if (defined('POSTIE_DEBUG')) {
        foreach ($mimeDecodedEmail->parts as $parts) {
            print "<p>" . $parts->ctype_primary . " " . $parts->ctype_secondary . "</p>\n";
        }
        echo "<p>Email is:</p>";
        var_dump($mimeDecodedEmail);
    }
    FilterTextParts($mimeDecodedEmail, $prefer_text_type);
    $tmpPost = array('post_title' => 'tmptitle', 'post_content' => 'tmpPost');
    /* in order to do attachments correctly, we need to associate the
      attachments with a post. So we add the post here, then update it 
      */
    $post_id = wp_insert_post($tmpPost);
    if (defined('POSTIE_DEBUG')) {
        echo "the id is {$post_id}\n";
    }
    $content = GetContent($mimeDecodedEmail, $attachments, $post_id, $poster, $config);
    if (defined('POSTIE_DEBUG')) {
        echo "the content is {$content}\n";
    }
    $subject = GetSubject($mimeDecodedEmail, $content, $config);
    if (defined('POSTIE_DEBUG')) {
        echo "the subject is {$subject}, right after calling GetSubject\n";
    }
    $customImages = SpecialMessageParsing($content, $attachments, $config);
    $post_excerpt = GetPostExcerpt($content, $filternewlines, $convertnewline);
    $postAuthorDetails = getPostAuthorDetails($subject, $content, $mimeDecodedEmail);
    $message_date = NULL;
    if (array_key_exists("date", $mimeDecodedEmail->headers) && !empty($mimeDecodedEmail->headers["date"])) {
        $message_date = HandleMessageEncoding($mimeDecodedEmail->headers["content-transfer-encoding"], $mimeDecodedEmail->ctype_parameters["charset"], $mimeDecodedEmail->headers["date"], $message_encoding, $message_dequote);
        //$message_date = $mimeDecodedEmail->headers['date'];
    }
    list($post_date, $post_date_gmt, $delay) = DeterminePostDate($content, $message_date, $time_offset);
    ubb2HTML($content);
    if ($converturls) {
        $content = clickableLink($content, $shortcode);
    }
    //$content = FixEmailQuotes($content);
    $id = checkReply($subject);
    $post_categories = GetPostCategories($subject, $default_post_category);
    $post_tags = postie_get_tags($content, $default_post_tags);
    $comment_status = AllowCommentsOnPost($content);
    if (empty($id) || is_null($id)) {
        $id = $post_id;
        $isReply = false;
        if ($add_meta == 'yes') {
            if ($wrap_pre == 'yes') {
                $content = $postAuthorDetails['content'] . "<pre>\n" . $content . "</pre>\n";
                $content = "<pre>\n" . $content . "</pre>\n";
            } else {
                $content = $postAuthorDetails['content'] . $content;
                $content = $content;
            }
        } else {
            if ($wrap_pre == 'yes') {
                $content = "<pre>\n" . $content . "</pre>\n";
            }
        }
    } else {
        $isReply = true;
        // strip out quoted content
        $lines = explode("\n", $content);
        //$lines=preg_split('/([\r\n]|<br \/>)/',$content);
        $newContents = '';
        foreach ($lines as $line) {
            //$match=preg_match("/^>.*/i",$line);
            //echo "line=$line,  match=$match";
            if (preg_match("/^>.*/i", $line) == 0 && preg_match("/^(from|subject|to|date):.*?/i", $line) == 0 && preg_match("/^-+.*?(from|subject|to|date).*?/i", $line) == 0 && preg_match("/^on.*?wrote:\$/i", $line) == 0 && preg_match("/^-+\\s*forwarded\\s*message\\s*-+/i", $line) == 0) {
                $newContents .= "{$line}\n";
            }
        }
        $content = $newContents;
        wp_delete_post($post_id);
    }
    if ($filternewlines) {
        $content = FilterNewLines($content, $convertnewline);
    }
    if ($delay != 0 && $post_status == 'publish') {
        $post_status = 'future';
    } else {
        $post_status = $post_status;
    }
    /* 
     * Added by Raam Dev <*****@*****.**>
     * Adds support for handling Custom Post Types by adding the
     * Custom Post Type name to the email subject separated by
     * $custom_post_type_delim, e.g. "Movies // My Favorite Movie"
     */
    $custom_post_type_delim = "//";
    if (strpos($subject, $custom_post_type_delim) !== FALSE) {
        // Captures the custom post type in the subject before $custom_post_type_delim
        $separated_subject = explode($custom_post_type_delim, $subject);
        $custom_post_type = $separated_subject[0];
        $subject = $separated_subject[1];
        $custom_post_type = trim(strtolower($custom_post_type));
        // Check if custom post type exists, if not, set default post type of 'post'
        $known_post_types = get_post_types();
        if (in_array($custom_post_type, $known_post_types)) {
            $post_type = $custom_post_type;
        } else {
            $post_type = 'post';
        }
    } else {
        $post_type = 'post';
    }
    /* --------- end by Raam Dev <*****@*****.**> */
    // DEBUG
    $details = array('post_author' => $poster, 'comment_author' => $postAuthorDetails['author'], 'comment_author_url' => $postAuthorDetails['comment_author_url'], 'user_ID' => $postAuthorDetails['user_ID'], 'email_author' => $postAuthorDetails['email'], 'post_date' => $post_date, 'post_content' => $content, 'post_title' => $subject, 'post_type' => $post_type, 'ping_status' => get_option('default_ping_status'), 'post_category' => $post_categories, 'tags_input' => $post_tags, 'comment_status' => $comment_status, 'post_name' => sanitize_title($subject), 'post_excerpt' => $post_excerpt, 'ID' => $id, 'customImages' => $customImages, 'post_status' => $post_status);
    $details = apply_filters('postie_post', $details);
    if (empty($details)) {
        // It is possible that the filter has removed the post, in which case, it should not be posted.
        // And if we created a placeholder post (because this was not a reply to an existing post),
        // then it should be removed
        if (!$is_reply) {
            wp_delete_post($post_id);
        }
    } else {
        DisplayEmailPost($details);
        PostToDB($details, $isReply, $post_to_db, $custom_image_field);
        if ($confirmation_email != '') {
            if ($confirmation_email == 'sender') {
                $recipients = array($postAuthorDetails['email']);
            } elseif ($confirmation_email == 'admin') {
                $recipients = array(get_option("admin_email"));
            } elseif ($confirmation_email == 'both') {
                $recipients = array($postAuthorDetails['email'], get_option("admin_email"));
            }
            MailToRecipients($mimeDecodedEmail, false, $recipients, false, false);
        }
    }
}
function PostEmail($poster, $mimeDecodedEmail)
{
    $config = GetConfig();
    $GLOBALS["POSTIE_IMAGE_ROTATION"] = 0;
    $attachments = array("html" => array(), "cids" => array(), "image_files" => array());
    print "<p>Message Id is :" . $mimeDecodedEmail->headers["message-id"] . "</p><br/>\n";
    print "<p>Email has following attachments:</p>";
    foreach ($mimeDecodedEmail->parts as $parts) {
        print "<p>" . $parts->ctype_primary . " " . $parts->ctype_secondary . "</p><br />\n";
    }
    FilterTextParts($mimeDecodedEmail);
    #print("<p>Email has following attachments after filtering:");
    #    foreach($mimeDecodedEmail->parts as $parts) {
    #        print("<p>".$parts->ctype_primary ." ".$parts->ctype_secondary) ."<br />\n";
    #    }
    $content = GetContent($mimeDecodedEmail, $attachments);
    //$content = $content;
    // replace emails and links that are identifiable BF-CHANGED
    $patterns[] = '/<a\\b[^>]*>.*?(ubscribe|eave|rofile|pdate|[Pp]references).*?<\\/a>/';
    //remove unsubscribe stuff
    $patterns[] = '/<a\\b([^>]+)(ubscribe|eave|rofile|pdate|[Pp]references)([^>]+)>.*?<\\/a>/si';
    //remove unsubscribe stuff
    $patterns[] = '/(http).*?(evite).*?(email)/';
    //remove evite
    $patterns[] = '/(href=)?["\']?(http:\\S+www\\.evite\\.com)\\S+["\'\\b]/';
    //evite
    $patterns[] = '/inviteId\\S+\\b/';
    //evite
    $patterns[] = '/iid=\\S+\\b/';
    //evite
    $patterns[] = '/No virus found in this outgoing message\\./';
    //remove avg stuff
    $patterns[] = '/Checked by AVG\\./';
    //remove avg stuff
    $patterns[] = '/Version.+?Virus.+?Release.+?AM/';
    //remove avg stuff
    $patterns[] = '/No virus found in this incoming message\\./';
    //remove avg stuff
    $patterns[] = '/<span\\b[^>]*>.*(_,_).*(_,_).*<\\/span>/si';
    //remove yahoo stuff
    $content = preg_replace($patterns, '', $content);
    // end BF-CHANGED
    //
    $subject = GetSubject($mimeDecodedEmail, $content);
    $subject = $subject;
    //BF-CHANGED
    $rotation = GetRotation($mimeDecodedEmail, $content);
    if ($rotation != "0" && count($attachments["image_files"])) {
        RotateImages($rotation, $attachments["image_files"]);
    }
    SpecialMessageParsing($content, $attachments);
    $message_date = NULL;
    if (array_key_exists("date", $mimeDecodedEmail->headers) && !empty($mimeDecodedEmail->headers["date"])) {
        $message_date = HandleMessageEncoding($mimeDecodedEmail->headers["content-transfer-encoding"], $mimeDecodedEmail->ctype_parameters["charset"], $mimeDecodedEmail->headers["date"]);
    }
    list($post_date, $post_date_gmt) = DeterminePostDate($content, $message_date);
    ubb2HTML($content);
    $content = FilterNewLines($content);
    $post_categories = GetPostCategories($subject);
    $comment_status = AllowCommentsOnPost($content);
    if (PURIFIER == "on") {
        $purifier_ref =& $purifier;
        $content = addslashes(getpurified()->purify($content));
    } else {
        $content = addslashes($content);
    }
    $details = array('post_author' => $poster, 'post_date' => $post_date, 'post_date_gmt' => $post_date_gmt, 'post_content' => $content, 'post_title' => addslashes($subject), 'post_modified' => $post_date, 'post_modified_gmt' => $post_date_gmt, 'ping_status' => get_option('default_ping_status'), 'post_category' => $post_categories, 'comment_status' => $comment_status, 'post_name' => sanitize_title($subject), 'post_status' => $config["POST_TYPE"], 'tags_input' => $config["DEFAULT_TAG"]);
    DisplayEmailPost($details, $config["AJAX_SELECT"]);
    if ($config["AJAX_SELECT"] == "0") {
        PostToDB($details);
        //print 'AJAX0'.$config["AJAX_SELECT"];
    }
}