102 $content_transfer_encoding = trim( $line ); |
105 $content_transfer_encoding = trim( $line ); |
103 $content_transfer_encoding = substr( $content_transfer_encoding, 27, strlen( $content_transfer_encoding ) - 27 ); |
106 $content_transfer_encoding = substr( $content_transfer_encoding, 27, strlen( $content_transfer_encoding ) - 27 ); |
104 $content_transfer_encoding = explode( ';', $content_transfer_encoding ); |
107 $content_transfer_encoding = explode( ';', $content_transfer_encoding ); |
105 $content_transfer_encoding = $content_transfer_encoding[0]; |
108 $content_transfer_encoding = $content_transfer_encoding[0]; |
106 } |
109 } |
107 if ( ( 'multipart/alternative' === $content_type ) && ( false !== strpos( $line, 'boundary="' ) ) && ( '' === $boundary ) ) { |
110 if ( 'multipart/alternative' === $content_type && str_contains( $line, 'boundary="' ) && '' === $boundary ) { |
108 $boundary = trim( $line ); |
111 $boundary = trim( $line ); |
109 $boundary = explode( '"', $boundary ); |
112 $boundary = explode( '"', $boundary ); |
110 $boundary = $boundary[1]; |
113 $boundary = $boundary[1]; |
111 } |
114 } |
112 if ( preg_match( '/Subject: /i', $line ) ) { |
115 if ( preg_match( '/Subject: /i', $line ) ) { |
132 } else { |
135 } else { |
133 $author = trim( $line ); |
136 $author = trim( $line ); |
134 } |
137 } |
135 $author = sanitize_email( $author ); |
138 $author = sanitize_email( $author ); |
136 if ( is_email( $author ) ) { |
139 if ( is_email( $author ) ) { |
137 /* translators: %s: Post author email address. */ |
|
138 echo '<p>' . sprintf( __( 'Author is %s' ), $author ) . '</p>'; |
|
139 $userdata = get_user_by( 'email', $author ); |
140 $userdata = get_user_by( 'email', $author ); |
140 if ( ! empty( $userdata ) ) { |
141 if ( ! empty( $userdata ) ) { |
141 $post_author = $userdata->ID; |
142 $post_author = $userdata->ID; |
142 $author_found = true; |
143 $author_found = true; |
143 } |
144 } |
144 } |
145 } |
145 } |
146 } |
146 |
147 |
147 if ( preg_match( '/Date: /i', $line ) ) { // Of the form '20 Mar 2002 20:32:37 +0100'. |
148 if ( preg_match( '/Date: /i', $line ) ) { // Of the form '20 Mar 2002 20:32:37 +0100'. |
148 $ddate = str_replace( 'Date: ', '', trim( $line ) ); |
149 $ddate = str_replace( 'Date: ', '', trim( $line ) ); |
149 // Remove parenthesised timezone string if it exists, as this confuses strtotime(). |
150 // Remove parenthesized timezone string if it exists, as this confuses strtotime(). |
150 $ddate = preg_replace( '!\s*\(.+\)\s*$!', '', $ddate ); |
151 $ddate = preg_replace( '!\s*\(.+\)\s*$!', '', $ddate ); |
151 $ddate_timestamp = strtotime( $ddate ); |
152 $ddate_timestamp = strtotime( $ddate ); |
152 $post_date = gmdate( 'Y-m-d H:i:s', $ddate_timestamp + $time_difference ); |
153 $post_date = gmdate( 'Y-m-d H:i:s', $ddate_timestamp + $time_difference ); |
153 $post_date_gmt = gmdate( 'Y-m-d H:i:s', $ddate_timestamp ); |
154 $post_date_gmt = gmdate( 'Y-m-d H:i:s', $ddate_timestamp ); |
154 } |
155 } |
168 |
169 |
169 if ( 'multipart/alternative' === $content_type ) { |
170 if ( 'multipart/alternative' === $content_type ) { |
170 $content = explode( '--' . $boundary, $content ); |
171 $content = explode( '--' . $boundary, $content ); |
171 $content = $content[2]; |
172 $content = $content[2]; |
172 |
173 |
173 // Match case-insensitive content-transfer-encoding. |
174 // Match case-insensitive Content-Transfer-Encoding. |
174 if ( preg_match( '/Content-Transfer-Encoding: quoted-printable/i', $content, $delim ) ) { |
175 if ( preg_match( '/Content-Transfer-Encoding: quoted-printable/i', $content, $delim ) ) { |
175 $content = explode( $delim[0], $content ); |
176 $content = explode( $delim[0], $content ); |
176 $content = $content[1]; |
177 $content = $content[1]; |
177 } |
178 } |
178 $content = strip_tags( $content, '<img><p><br><i><b><u><em><strong><strike><font><span><div>' ); |
179 $content = strip_tags( $content, '<img><p><br><i><b><u><em><strong><strike><font><span><div>' ); |
228 $post_ID = wp_insert_post( $post_data ); |
229 $post_ID = wp_insert_post( $post_data ); |
229 if ( is_wp_error( $post_ID ) ) { |
230 if ( is_wp_error( $post_ID ) ) { |
230 echo "\n" . $post_ID->get_error_message(); |
231 echo "\n" . $post_ID->get_error_message(); |
231 } |
232 } |
232 |
233 |
233 // We couldn't post, for whatever reason. Better move forward to the next email. |
234 // The post wasn't inserted or updated, for whatever reason. Better move forward to the next email. |
234 if ( empty( $post_ID ) ) { |
235 if ( empty( $post_ID ) ) { |
235 continue; |
236 continue; |
236 } |
237 } |
237 |
238 |
238 /** |
239 /** |