diff --git a/wp-mail.php b/wp-mail.php
index 07820e6..1c9bba5 100644
|
a
|
b
|
|
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | 10 | /** Make sure that the WordPress bootstrap has run before continuing. */ |
| 11 | | require(dirname(__FILE__) . '/wp-load.php'); |
| | 11 | require( dirname(__FILE__) . '/wp-load.php' ); |
| 12 | 12 | |
| 13 | 13 | /** This filter is documented in wp-admin/options.php */ |
| 14 | 14 | if ( ! apply_filters( 'enable_post_by_email_configuration', true ) ) |
| … |
… |
do_action( 'wp-mail.php' ); |
| 25 | 25 | require_once( ABSPATH . WPINC . '/class-pop3.php' ); |
| 26 | 26 | |
| 27 | 27 | /** Only check at this interval for new messages. */ |
| 28 | | if ( !defined('WP_MAIL_INTERVAL') ) |
| 29 | | define('WP_MAIL_INTERVAL', 300); // 5 minutes |
| | 28 | if ( ! defined( 'WP_MAIL_INTERVAL' ) ) |
| | 29 | define( 'WP_MAIL_INTERVAL', 300 ); // 5 minutes |
| 30 | 30 | |
| 31 | | $last_checked = get_transient('mailserver_last_checked'); |
| | 31 | $last_checked = get_transient( 'mailserver_last_checked' ); |
| 32 | 32 | |
| 33 | 33 | if ( $last_checked ) |
| 34 | | wp_die(__('Slow down cowboy, no need to check for new mails so often!')); |
| | 34 | wp_die( __( 'Slow down cowboy, no need to check for new mails so often!' ) ); |
| 35 | 35 | |
| 36 | | set_transient('mailserver_last_checked', true, WP_MAIL_INTERVAL); |
| | 36 | set_transient( 'mailserver_last_checked', true, WP_MAIL_INTERVAL ); |
| 37 | 37 | |
| 38 | | $time_difference = get_option('gmt_offset') * HOUR_IN_SECONDS; |
| | 38 | $time_difference = get_option( 'gmt_offset' ) * HOUR_IN_SECONDS; |
| 39 | 39 | |
| 40 | 40 | $phone_delim = '::'; |
| 41 | 41 | |
| 42 | 42 | $pop3 = new POP3(); |
| 43 | 43 | |
| 44 | | if ( !$pop3->connect( get_option('mailserver_url'), get_option('mailserver_port') ) || !$pop3->user( get_option('mailserver_login') ) ) |
| | 44 | if ( ! $pop3->connect( get_option( 'mailserver_url' ), get_option( 'mailserver_port' ) ) || ! $pop3->user( get_option( 'mailserver_login' ) ) ) |
| 45 | 45 | wp_die( esc_html( $pop3->ERROR ) ); |
| 46 | 46 | |
| 47 | | $count = $pop3->pass( get_option('mailserver_pass') ); |
| | 47 | $count = $pop3->pass( get_option( 'mailserver_pass' ) ); |
| 48 | 48 | |
| 49 | 49 | if( false === $count ) |
| 50 | 50 | wp_die( esc_html( $pop3->ERROR ) ); |
| 51 | 51 | |
| 52 | 52 | if( 0 === $count ) { |
| 53 | 53 | $pop3->quit(); |
| 54 | | wp_die( __('There doesn’t seem to be any new mail.') ); |
| | 54 | wp_die( __( 'There doesn’t seem to be any new mail.' ) ); |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | for ( $i = 1; $i <= $count; $i++ ) { |
| 58 | 58 | |
| 59 | | $message = $pop3->get($i); |
| | 59 | $message = $pop3->get( $i ); |
| 60 | 60 | |
| 61 | 61 | $bodysignal = false; |
| 62 | 62 | $boundary = ''; |
| … |
… |
for ( $i = 1; $i <= $count; $i++ ) { |
| 66 | 66 | $content_transfer_encoding = ''; |
| 67 | 67 | $post_author = 1; |
| 68 | 68 | $author_found = false; |
| 69 | | $dmonths = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'); |
| 70 | | foreach ($message as $line) { |
| | 69 | foreach ( $message as $line ) { |
| 71 | 70 | // Body signal. |
| 72 | | if ( strlen($line) < 3 ) |
| | 71 | if ( strlen( $line ) < 3 ) |
| 73 | 72 | $bodysignal = true; |
| 74 | 73 | if ( $bodysignal ) { |
| 75 | 74 | $content .= $line; |
| 76 | 75 | } else { |
| 77 | | if ( preg_match('/Content-Type: /i', $line) ) { |
| 78 | | $content_type = trim($line); |
| 79 | | $content_type = substr($content_type, 14, strlen($content_type) - 14); |
| 80 | | $content_type = explode(';', $content_type); |
| | 76 | if ( preg_match( '/Content-Type: /i', $line ) ) { |
| | 77 | $content_type = trim( $line ); |
| | 78 | $content_type = substr( $content_type, 14, strlen( $content_type ) - 14 ); |
| | 79 | $content_type = explode( ';', $content_type ); |
| 81 | 80 | if ( ! empty( $content_type[1] ) ) { |
| 82 | | $charset = explode('=', $content_type[1]); |
| 83 | | $charset = ( ! empty( $charset[1] ) ) ? trim($charset[1]) : ''; |
| | 81 | $charset = explode( '=', $content_type[1] ); |
| | 82 | $charset = ( ! empty( $charset[1] ) ) ? trim( $charset[1] ) : ''; |
| 84 | 83 | } |
| 85 | 84 | $content_type = $content_type[0]; |
| 86 | 85 | } |
| 87 | | if ( preg_match('/Content-Transfer-Encoding: /i', $line) ) { |
| 88 | | $content_transfer_encoding = trim($line); |
| 89 | | $content_transfer_encoding = substr($content_transfer_encoding, 27, strlen($content_transfer_encoding) - 27); |
| 90 | | $content_transfer_encoding = explode(';', $content_transfer_encoding); |
| | 86 | if ( preg_match( '/Content-Transfer-Encoding: /i', $line ) ) { |
| | 87 | $content_transfer_encoding = trim( $line ); |
| | 88 | $content_transfer_encoding = substr( $content_transfer_encoding, 27, strlen( $content_transfer_encoding ) - 27 ); |
| | 89 | $content_transfer_encoding = explode( ';', $content_transfer_encoding ); |
| 91 | 90 | $content_transfer_encoding = $content_transfer_encoding[0]; |
| 92 | 91 | } |
| 93 | | if ( ( $content_type == 'multipart/alternative' ) && ( false !== strpos($line, 'boundary="') ) && ( '' == $boundary ) ) { |
| 94 | | $boundary = trim($line); |
| 95 | | $boundary = explode('"', $boundary); |
| | 92 | if ( ( 'multipart/alternative' == $content_type ) && ( false !== strpos( $line, 'boundary="' ) ) && ( '' == $boundary ) ) { |
| | 93 | $boundary = trim( $line ); |
| | 94 | $boundary = explode( '"', $boundary ); |
| 96 | 95 | $boundary = $boundary[1]; |
| 97 | 96 | } |
| 98 | | if (preg_match('/Subject: /i', $line)) { |
| 99 | | $subject = trim($line); |
| 100 | | $subject = substr($subject, 9, strlen($subject) - 9); |
| | 97 | if ( preg_match( '/Subject: /i', $line ) ) { |
| | 98 | $subject = trim( $line ); |
| | 99 | $subject = substr( $subject, 9, strlen( $subject ) - 9 ); |
| 101 | 100 | // Captures any text in the subject before $phone_delim as the subject |
| 102 | 101 | if ( function_exists('iconv_mime_decode') ) { |
| 103 | | $subject = iconv_mime_decode($subject, 2, get_option('blog_charset')); |
| | 102 | $subject = iconv_mime_decode( $subject, 2, get_option( 'blog_charset' ) ); |
| 104 | 103 | } else { |
| 105 | | $subject = wp_iso_descrambler($subject); |
| | 104 | $subject = wp_iso_descrambler( $subject ); |
| 106 | 105 | } |
| 107 | | $subject = explode($phone_delim, $subject); |
| | 106 | $subject = explode( $phone_delim, $subject ); |
| 108 | 107 | $subject = $subject[0]; |
| 109 | 108 | } |
| 110 | 109 | |
| … |
… |
for ( $i = 1; $i <= $count; $i++ ) { |
| 113 | 112 | * otherwise use the site admin. |
| 114 | 113 | */ |
| 115 | 114 | if ( ! $author_found && preg_match( '/^(From|Reply-To): /', $line ) ) { |
| 116 | | if ( preg_match('|[a-z0-9_.-]+@[a-z0-9_.-]+(?!.*<)|i', $line, $matches) ) |
| | 115 | if ( preg_match( '|[a-z0-9_.-]+@[a-z0-9_.-]+(?!.*<)|i', $line, $matches ) ) |
| 117 | 116 | $author = $matches[0]; |
| 118 | 117 | else |
| 119 | | $author = trim($line); |
| 120 | | $author = sanitize_email($author); |
| 121 | | if ( is_email($author) ) { |
| 122 | | echo '<p>' . sprintf(__('Author is %s'), $author) . '</p>'; |
| 123 | | $userdata = get_user_by('email', $author); |
| | 118 | $author = trim( $line ); |
| | 119 | $author = sanitize_email( $author ); |
| | 120 | if ( is_email( $author ) ) { |
| | 121 | echo '<p>' . sprintf( __( 'Author is %s' ), $author ) . '</p>'; |
| | 122 | $userdata = get_user_by( 'email', $author ); |
| 124 | 123 | if ( ! empty( $userdata ) ) { |
| 125 | 124 | $post_author = $userdata->ID; |
| 126 | 125 | $author_found = true; |
| … |
… |
for ( $i = 1; $i <= $count; $i++ ) { |
| 140 | 139 | |
| 141 | 140 | // Set $post_status based on $author_found and on author's publish_posts capability |
| 142 | 141 | if ( $author_found ) { |
| 143 | | $user = new WP_User($post_author); |
| | 142 | $user = new WP_User( $post_author ); |
| 144 | 143 | $post_status = ( $user->has_cap('publish_posts') ) ? 'publish' : 'pending'; |
| 145 | 144 | } else { |
| 146 | 145 | // Author not found in DB, set status to pending. Author already set to admin. |
| 147 | 146 | $post_status = 'pending'; |
| 148 | 147 | } |
| 149 | 148 | |
| 150 | | $subject = trim($subject); |
| | 149 | $subject = trim( $subject ); |
| 151 | 150 | |
| 152 | | if ( $content_type == 'multipart/alternative' ) { |
| 153 | | $content = explode('--'.$boundary, $content); |
| | 151 | if ( 'multipart/alternative' == $content_type ) { |
| | 152 | $content = explode( '--' . $boundary, $content ); |
| 154 | 153 | $content = $content[2]; |
| 155 | 154 | |
| 156 | 155 | // Match case-insensitive content-transfer-encoding. |
| 157 | | if ( preg_match( '/Content-Transfer-Encoding: quoted-printable/i', $content, $delim) ) { |
| 158 | | $content = explode($delim[0], $content); |
| | 156 | if ( preg_match( '/Content-Transfer-Encoding: quoted-printable/i', $content, $delim ) ) { |
| | 157 | $content = explode( $delim[0], $content ); |
| 159 | 158 | $content = $content[1]; |
| 160 | 159 | } |
| 161 | | $content = strip_tags($content, '<img><p><br><i><b><u><em><strong><strike><font><span><div>'); |
| | 160 | $content = strip_tags( $content, '<img><p><br><i><b><u><em><strong><strike><font><span><div>' ); |
| 162 | 161 | } |
| 163 | | $content = trim($content); |
| | 162 | $content = trim( $content ); |
| 164 | 163 | |
| 165 | 164 | /** |
| 166 | 165 | * Filters the original content of the email. |
| … |
… |
for ( $i = 1; $i <= $count; $i++ ) { |
| 174 | 173 | */ |
| 175 | 174 | $content = apply_filters( 'wp_mail_original_content', $content ); |
| 176 | 175 | |
| 177 | | if ( false !== stripos($content_transfer_encoding, "quoted-printable") ) { |
| 178 | | $content = quoted_printable_decode($content); |
| | 176 | if ( false !== stripos( $content_transfer_encoding, "quoted-printable" ) ) { |
| | 177 | $content = quoted_printable_decode( $content ); |
| 179 | 178 | } |
| 180 | 179 | |
| 181 | 180 | if ( function_exists('iconv') && ! empty( $charset ) ) { |
| 182 | | $content = iconv($charset, get_option('blog_charset'), $content); |
| | 181 | $content = iconv( $charset, get_option( 'blog_charset' ), $content ); |
| 183 | 182 | } |
| 184 | 183 | |
| 185 | 184 | // Captures any text in the body after $phone_delim as the body |
| 186 | | $content = explode($phone_delim, $content); |
| | 185 | $content = explode( $phone_delim, $content ); |
| 187 | 186 | $content = empty( $content[1] ) ? $content[0] : $content[1]; |
| 188 | 187 | |
| 189 | | $content = trim($content); |
| | 188 | $content = trim( $content ); |
| 190 | 189 | |
| 191 | 190 | /** |
| 192 | 191 | * Filters the content of the post submitted by email before saving. |
| … |
… |
for ( $i = 1; $i <= $count; $i++ ) { |
| 197 | 196 | */ |
| 198 | 197 | $post_content = apply_filters( 'phone_content', $content ); |
| 199 | 198 | |
| 200 | | $post_title = xmlrpc_getposttitle($content); |
| | 199 | $post_title = xmlrpc_getposttitle( $content ); |
| 201 | 200 | |
| 202 | | if ($post_title == '') $post_title = $subject; |
| | 201 | if ( '' == $post_title ) $post_title = $subject; |
| 203 | 202 | |
| 204 | | $post_category = array(get_option('default_email_category')); |
| | 203 | $post_category = array( get_option( 'default_email_category' ) ); |
| 205 | 204 | |
| 206 | | $post_data = compact('post_content','post_title','post_date','post_date_gmt','post_author','post_category', 'post_status'); |
| 207 | | $post_data = wp_slash($post_data); |
| | 205 | $post_data = compact( 'post_content', 'post_title', 'post_date', 'post_date_gmt', 'post_author', 'post_category', 'post_status' ); |
| | 206 | $post_data = wp_slash( $post_data ); |
| 208 | 207 | |
| 209 | | $post_ID = wp_insert_post($post_data); |
| | 208 | $post_ID = wp_insert_post( $post_data ); |
| 210 | 209 | if ( is_wp_error( $post_ID ) ) |
| 211 | 210 | echo "\n" . $post_ID->get_error_message(); |
| 212 | 211 | |
| … |
… |
for ( $i = 1; $i <= $count; $i++ ) { |
| 226 | 225 | echo "\n<p><strong>" . __( 'Author:' ) . '</strong> ' . esc_html( $post_author ) . '</p>'; |
| 227 | 226 | echo "\n<p><strong>" . __( 'Posted title:' ) . '</strong> ' . esc_html( $post_title ) . '</p>'; |
| 228 | 227 | |
| 229 | | if(!$pop3->delete($i)) { |
| | 228 | if ( ! $pop3->delete( $i ) ) { |
| 230 | 229 | echo '<p>' . sprintf( |
| 231 | 230 | /* translators: %s: POP3 error */ |
| 232 | 231 | __( 'Oops: %s' ), |
| … |
… |
for ( $i = 1; $i <= $count; $i++ ) { |
| 244 | 243 | |
| 245 | 244 | } |
| 246 | 245 | |
| 247 | | $pop3->quit(); |
| | 246 | $pop3->quit(); |
| | 247 | No newline at end of file |