-
+ 2915BB3A275F2961BC736FB095F7A5F6E289DE2EA82F2E3F89483D7D34802AEDCD971D4BAC56BFB3F324D6E68A3ADF48A50AC19A927117CD542577C54A75F557
mp-wp/wp-mail.php
(0 . 0)(1 . 209)
160254 <?php
160255 /**
160256 * Gets the email message from the user's mailbox to add as
160257 * a WordPress post. Mailbox connection information must be
160258 * configured under Settings > Writing
160259 *
160260 * @package WordPress
160261 */
160262
160263 /** Make sure that the WordPress bootstrap has run before continuing. */
160264 require(dirname(__FILE__) . '/wp-load.php');
160265
160266 /** Get the POP3 class with which to access the mailbox. */
160267 require_once( ABSPATH . WPINC . '/class-pop3.php' );
160268
160269 $time_difference = absint(get_option('gmt_offset')) * 3600;
160270
160271 $phone_delim = '::';
160272
160273 $pop3 = new POP3();
160274
160275 if ( ! $pop3->connect(get_option('mailserver_url'), get_option('mailserver_port') ) ||
160276 ! $pop3->user(get_option('mailserver_login')) ||
160277 ( ! $count = $pop3->pass(get_option('mailserver_pass')) ) ) {
160278 $pop3->quit();
160279 wp_die( ( 0 === $count ) ? __("There doesn't seem to be any new mail.") : wp_specialchars($pop3->ERROR) );
160280 }
160281
160282 for ( $i = 1; $i <= $count; $i++ ) {
160283
160284 $message = $pop3->get($i);
160285
160286 $bodysignal = false;
160287 $boundary = '';
160288 $charset = '';
160289 $content = '';
160290 $content_type = '';
160291 $content_transfer_encoding = '';
160292 $post_author = 1;
160293 $author_found = false;
160294 $dmonths = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
160295 foreach ($message as $line) {
160296 // body signal
160297 if ( strlen($line) < 3 )
160298 $bodysignal = true;
160299 if ( $bodysignal ) {
160300 $content .= $line;
160301 } else {
160302 if ( preg_match('/Content-Type: /i', $line) ) {
160303 $content_type = trim($line);
160304 $content_type = substr($content_type, 14, strlen($content_type) - 14);
160305 $content_type = explode(';', $content_type);
160306 if ( ! empty( $content_type[1] ) ) {
160307 $charset = explode('=', $content_type[1]);
160308 $charset = ( ! empty( $charset[1] ) ) ? trim($charset[1]) : '';
160309 }
160310 $content_type = $content_type[0];
160311 }
160312 if ( preg_match('/Content-Transfer-Encoding: /i', $line) ) {
160313 $content_transfer_encoding = trim($line);
160314 $content_transfer_encoding = substr($content_transfer_encoding, 27, strlen($content_transfer_encoding) - 27);
160315 $content_transfer_encoding = explode(';', $content_transfer_encoding);
160316 $content_transfer_encoding = $content_transfer_encoding[0];
160317 }
160318 if ( ( $content_type == 'multipart/alternative' ) && ( false !== strpos($line, 'boundary="') ) && ( '' == $boundary ) ) {
160319 $boundary = trim($line);
160320 $boundary = explode('"', $boundary);
160321 $boundary = $boundary[1];
160322 }
160323 if (preg_match('/Subject: /i', $line)) {
160324 $subject = trim($line);
160325 $subject = substr($subject, 9, strlen($subject) - 9);
160326 // Captures any text in the subject before $phone_delim as the subject
160327 if ( function_exists('iconv_mime_decode') ) {
160328 $subject = iconv_mime_decode($subject, 2, get_option('blog_charset'));
160329 } else {
160330 $subject = wp_iso_descrambler($subject);
160331 }
160332 $subject = explode($phone_delim, $subject);
160333 $subject = $subject[0];
160334 }
160335
160336 // Set the author using the email address (From or Reply-To, the last used)
160337 // otherwise use the site admin
160338 if ( preg_match('/(From|Reply-To): /', $line) ) {
160339 if ( preg_match('|[a-z0-9_.-]+@[a-z0-9_.-]+(?!.*<)|i', $line, $matches) )
160340 $author = $matches[0];
160341 else
160342 $author = trim($line);
160343 $author = sanitize_email($author);
160344 if ( is_email($author) ) {
160345 echo '<p>' . sprintf(__('Author is %s'), $author) . '</p>';
160346 $userdata = get_user_by_email($author);
160347 if ( empty($userdata) ) {
160348 $author_found = false;
160349 } else {
160350 $post_author = $userdata->ID;
160351 $author_found = true;
160352 }
160353 } else {
160354 $author_found = false;
160355 }
160356 }
160357
160358 if (preg_match('/Date: /i', $line)) { // of the form '20 Mar 2002 20:32:37'
160359 $ddate = trim($line);
160360 $ddate = str_replace('Date: ', '', $ddate);
160361 if (strpos($ddate, ',')) {
160362 $ddate = trim(substr($ddate, strpos($ddate, ',') + 1, strlen($ddate)));
160363 }
160364 $date_arr = explode(' ', $ddate);
160365 $date_time = explode(':', $date_arr[3]);
160366
160367 $ddate_H = $date_time[0];
160368 $ddate_i = $date_time[1];
160369 $ddate_s = $date_time[2];
160370
160371 $ddate_m = $date_arr[1];
160372 $ddate_d = $date_arr[0];
160373 $ddate_Y = $date_arr[2];
160374 for ( $j = 0; $j < 12; $j++ ) {
160375 if ( $ddate_m == $dmonths[$j] ) {
160376 $ddate_m = $j+1;
160377 }
160378 }
160379
160380 $time_zn = intval($date_arr[4]) * 36;
160381 $ddate_U = gmmktime($ddate_H, $ddate_i, $ddate_s, $ddate_m, $ddate_d, $ddate_Y);
160382 $ddate_U = $ddate_U - $time_zn;
160383 $post_date = gmdate('Y-m-d H:i:s', $ddate_U + $time_difference);
160384 $post_date_gmt = gmdate('Y-m-d H:i:s', $ddate_U);
160385 }
160386 }
160387 }
160388
160389 // Set $post_status based on $author_found and on author's publish_posts capability
160390 if ( $author_found ) {
160391 $user = new WP_User($post_author);
160392 $post_status = ( $user->has_cap('publish_posts') ) ? 'publish' : 'pending';
160393 } else {
160394 // Author not found in DB, set status to pending. Author already set to admin.
160395 $post_status = 'pending';
160396 }
160397
160398 $subject = trim($subject);
160399
160400 if ( $content_type == 'multipart/alternative' ) {
160401 $content = explode('--'.$boundary, $content);
160402 $content = $content[2];
160403 // match case-insensitive content-transfer-encoding
160404 if ( preg_match( '/Content-Transfer-Encoding: quoted-printable/i', $content, $delim) ) {
160405 $content = explode($delim[0], $content);
160406 $content = $content[1];
160407 }
160408 $content = strip_tags($content, '<img><p><br><i><b><u><em><strong><strike><font><span><div>');
160409 }
160410 $content = trim($content);
160411
160412 if ( false !== stripos($content_transfer_encoding, "quoted-printable") ) {
160413 $content = quoted_printable_decode($content);
160414 }
160415
160416 if ( function_exists('iconv') && ! empty( $charset ) ) {
160417 $content = iconv($charset, get_option('blog_charset'), $content);
160418 }
160419
160420 // Captures any text in the body after $phone_delim as the body
160421 $content = explode($phone_delim, $content);
160422 $content = empty( $content[1] ) ? $content[0] : $content[1];
160423
160424 $content = trim($content);
160425
160426 $post_content = apply_filters('phone_content', $content);
160427
160428 $post_title = xmlrpc_getposttitle($content);
160429
160430 if ($post_title == '') $post_title = $subject;
160431
160432 $post_category = array(get_option('default_email_category'));
160433
160434 $post_data = compact('post_content','post_title','post_date','post_date_gmt','post_author','post_category', 'post_status');
160435 $post_data = add_magic_quotes($post_data);
160436
160437 $post_ID = wp_insert_post($post_data);
160438 if ( is_wp_error( $post_ID ) )
160439 echo "\n" . $post_ID->get_error_message();
160440
160441 // We couldn't post, for whatever reason. Better move forward to the next email.
160442 if ( empty( $post_ID ) )
160443 continue;
160444
160445 do_action('publish_phone', $post_ID);
160446
160447 echo "\n<p>" . sprintf(__('<strong>Author:</strong> %s'), wp_specialchars($post_author)) . '</p>';
160448 echo "\n<p>" . sprintf(__('<strong>Posted title:</strong> %s'), wp_specialchars($post_title)) . '</p>';
160449
160450 if(!$pop3->delete($i)) {
160451 echo '<p>' . sprintf(__('Oops: %s'), wp_specialchars($pop3->ERROR)) . '</p>';
160452 $pop3->reset();
160453 exit;
160454 } else {
160455 echo '<p>' . sprintf(__('Mission complete. Message <strong>%s</strong> deleted.'), $i) . '</p>';
160456 }
160457
160458 }
160459
160460 $pop3->quit();
160461
160462 ?>