X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/7688c6ba71852cd89123b62b2d57683535e4702a..refs/tags/wordpress-2.6.2-scripts:/wp-mail.php diff --git a/wp-mail.php b/wp-mail.php index ab9ae845..52d05cb8 100644 --- a/wp-mail.php +++ b/wp-mail.php @@ -1,8 +1,18 @@ connect(get_option('mailserver_url'), get_option('mailserver_port'))) wp_die(wp_specialchars($pop3->ERROR)); -$count = $pop3->login(get_option('mailserver_login'), get_option('mailserver_pass')); -if (0 == $count) wp_die(__('There doesn’t seem to be any new mail.')); +if (!$pop3->user(get_option('mailserver_login'))) + wp_die(wp_specialchars($pop3->ERROR)); +$count = $pop3->pass(get_option('mailserver_pass')); +if (false === $count) + wp_die(wp_specialchars($pop3->ERROR)); +if (0 == $count) + echo "

There doesn't seem to be any new mail.

\n"; // will fall-through to end of for loop for ($i=1; $i <= $count; $i++) : @@ -27,6 +42,8 @@ for ($i=1; $i <= $count; $i++) : $content_transfer_encoding = ''; $boundary = ''; $bodysignal = 0; + $post_author = 1; + $author_found = false; $dmonths = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'); foreach ($message as $line) : if (strlen($line) < 3) $bodysignal = 1; @@ -70,14 +87,18 @@ for ($i=1; $i <= $count; $i++) : $author = sanitize_email($author); if ( is_email($author) ) { echo "Author = {$author}

"; - $author = $wpdb->escape($author); - $result = $wpdb->get_row("SELECT ID FROM $wpdb->users WHERE user_email='$author' LIMIT 1"); - if (!$result) + $userdata = get_user_by_email($author); + if (!$userdata) { $post_author = 1; - else - $post_author = $result->ID; - } else + $author_found = false; + } else { + $post_author = $userdata->ID; + $author_found = true; + } + } else { $post_author = 1; + $author_found = false; + } } if (preg_match('/Date: /i', $line)) { // of the form '20 Mar 2002 20:32:37' @@ -111,6 +132,18 @@ for ($i=1; $i <= $count; $i++) : } endforeach; + // Set $post_status based on $author_found and on author's publish_posts capability + if ($author_found) { + $user = new WP_User($post_author); + if ($user->has_cap('publish_posts')) + $post_status = 'publish'; + else + $post_status = 'pending'; + } else { + // Author not found in DB, set status to pending. Author already set to admin. + $post_status = 'pending'; + } + $subject = trim($subject); if ($content_type == 'multipart/alternative') { @@ -141,14 +174,11 @@ for ($i=1; $i <= $count; $i++) : $post_category = $post_categories; - // or maybe we should leave the choice to email drafts? propose a way - $post_status = 'publish'; - $post_data = compact('post_content','post_title','post_date','post_date_gmt','post_author','post_category', 'post_status'); $post_data = add_magic_quotes($post_data); $post_ID = wp_insert_post($post_data); - if ( is_wp_error( $post_ID ) ) + if ( is_wp_error( $post_ID ) ) echo "\n" . $post_ID->get_error_message(); if (!$post_ID) { @@ -173,4 +203,4 @@ endfor; $pop3->quit(); -?> +?> \ No newline at end of file