]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-mail.php
Wordpress 2.5.1
[autoinstalls/wordpress.git] / wp-mail.php
index ab9ae84585a263a4f20638461289259cbee1d510..9e767fb3b053812d9ead98a6b52e224f95446918 100644 (file)
@@ -14,9 +14,14 @@ $pop3 = new POP3();
 if (!$pop3->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 "<p>There doesn't seem to be any new mail.</p>\n"; // will fall-through to end of for loop
 
 for ($i=1; $i <= $count; $i++) :
 
@@ -27,6 +32,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 +77,18 @@ for ($i=1; $i <= $count; $i++) :
                                $author = sanitize_email($author);
                                if ( is_email($author) ) {
                                        echo "Author = {$author} <p>";
-                                       $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 +122,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 +164,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) {