Make WordPress Core

Ticket #4642: 4642.diff

File 4642.diff, 2.4 KB (added by Bobcat, 17 years ago)

wp-mail.php patch, including email addr regexp fix

  • wp-mail.php

     
    2727        $content_transfer_encoding = '';
    2828        $boundary = '';
    2929        $bodysignal = 0;
     30        $post_author = 1;
     31        $author_found = false;
    3032        $dmonths = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
    3133        foreach ($message as $line) :
    3234                if (strlen($line) < 3) $bodysignal = 1;
     
    6062                                $subject = $subject[0];
    6163                        }
    6264
    63                         // Set the author using the email address (To or Reply-To, the last used)
     65                        // Set the author using the email address (From or Reply-To, the last used)
    6466                        // otherwise use the site admin
    6567                        if (preg_match('/From: /', $line) | preg_match('/Reply-To: /', $line))  {
    6668                                $author=trim($line);
    67                                 if ( ereg("([a-zA-Z0-9\_\-\.]+@[\a-zA-z0-9\_\-\.]+)", $author , $regs) ) {
     69                                if ( ereg("([a-zA-Z0-9_.-]+@[a-zA-Z0-9_.-]+)", $author , $regs) ) {
    6870                                        $author = $regs[1];
    6971                                        echo "Author = {$author} <p>";
    7072                                        $author = $wpdb->escape($author);
    7173                                        $result = $wpdb->get_row("SELECT ID FROM $wpdb->users WHERE user_email='$author' LIMIT 1");
    72                                         if (!$result)
     74                                        if (!$result) {
    7375                                                $post_author = 1;
    74                                         else
     76                                                $author_found = false;
     77                                        } else {
    7578                                                $post_author = $result->ID;
    76                                 } else
     79                                                $author_found = true;
     80                                        }
     81                                } else {
    7782                                        $post_author = 1;
     83                                        $author_found = false;
     84                                }
    7885                        }
    7986
    8087                        if (preg_match('/Date: /i', $line)) { // of the form '20 Mar 2002 20:32:37'
     
    108115                }
    109116        endforeach;
    110117
     118        // Set $post_status based on $author_found and on author's publish_posts capability
     119        if ($author_found) {
     120                $user = new WP_User($post_author);
     121                if ($user->has_cap('publish_posts'))
     122                        $post_status = 'publish';
     123                else
     124                        $post_status = 'pending';
     125        } else {
     126                // Author not found in DB, set status to pending.  Author already set to admin.
     127                $post_status = 'pending';
     128        }
     129
    111130        $subject = trim($subject);
    112131
    113132        if ($content_type == 'multipart/alternative') {
     
    141160
    142161        $post_category = $post_categories;
    143162
    144         // or maybe we should leave the choice to email drafts? propose a way
    145         $post_status = 'publish';
    146 
    147163        $post_data = compact('post_content','post_title','post_date','post_date_gmt','post_author','post_category', 'post_status');
    148164        $post_data = add_magic_quotes($post_data);
    149165