2013-10-25 00:58:23 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Gets the email message from the user's mailbox to add as
|
|
|
|
* a WordPress post. Mailbox connection information must be
|
|
|
|
* configured under Settings > Writing
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** Make sure that the WordPress bootstrap has run before continuing. */
|
2020-02-06 07:33:11 +01:00
|
|
|
require __DIR__ . '/wp-load.php';
|
2013-10-25 00:58:23 +02:00
|
|
|
|
2013-10-25 00:59:20 +02:00
|
|
|
/** This filter is documented in wp-admin/options.php */
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( ! apply_filters( 'enable_post_by_email_configuration', true ) ) {
|
2016-08-23 16:02:39 +02:00
|
|
|
wp_die( __( 'This action has been disabled by the administrator.' ), 403 );
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2013-10-25 00:58:23 +02:00
|
|
|
|
2017-01-11 06:13:43 +01:00
|
|
|
$mailserver_url = get_option( 'mailserver_url' );
|
|
|
|
|
|
|
|
if ( 'mail.example.com' === $mailserver_url || empty( $mailserver_url ) ) {
|
|
|
|
wp_die( __( 'This action has been disabled by the administrator.' ), 403 );
|
|
|
|
}
|
|
|
|
|
2013-11-13 12:58:12 +01:00
|
|
|
/**
|
|
|
|
* Fires to allow a plugin to do a complete takeover of Post by Email.
|
|
|
|
*
|
|
|
|
* @since 2.9.0
|
|
|
|
*/
|
2019-07-05 03:45:56 +02:00
|
|
|
do_action( 'wp-mail.php' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
|
2013-10-25 00:58:23 +02:00
|
|
|
|
2016-08-31 18:31:29 +02:00
|
|
|
/** Get the POP3 class with which to access the mailbox. */
|
2020-02-06 07:33:11 +01:00
|
|
|
require_once ABSPATH . WPINC . '/class-pop3.php';
|
2016-08-31 18:31:29 +02:00
|
|
|
|
2013-10-25 00:58:23 +02:00
|
|
|
/** Only check at this interval for new messages. */
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( ! defined( 'WP_MAIL_INTERVAL' ) ) {
|
2020-01-29 01:45:18 +01:00
|
|
|
define( 'WP_MAIL_INTERVAL', 5 * MINUTE_IN_SECONDS );
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2013-10-25 00:58:23 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
$last_checked = get_transient( 'mailserver_last_checked' );
|
2013-10-25 00:58:23 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( $last_checked ) {
|
|
|
|
wp_die( __( 'Slow down cowboy, no need to check for new mails so often!' ) );
|
|
|
|
}
|
2013-10-25 00:58:23 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
set_transient( 'mailserver_last_checked', true, WP_MAIL_INTERVAL );
|
2013-10-25 00:58:23 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
$time_difference = get_option( 'gmt_offset' ) * HOUR_IN_SECONDS;
|
2013-10-25 00:58:23 +02:00
|
|
|
|
|
|
|
$phone_delim = '::';
|
|
|
|
|
|
|
|
$pop3 = new POP3();
|
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( ! $pop3->connect( get_option( 'mailserver_url' ), get_option( 'mailserver_port' ) ) || ! $pop3->user( get_option( 'mailserver_login' ) ) ) {
|
2013-10-25 00:58:23 +02:00
|
|
|
wp_die( esc_html( $pop3->ERROR ) );
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2013-10-25 00:58:23 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
$count = $pop3->pass( get_option( 'mailserver_pass' ) );
|
2013-10-25 00:58:23 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( false === $count ) {
|
2013-10-25 00:58:23 +02:00
|
|
|
wp_die( esc_html( $pop3->ERROR ) );
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2013-10-25 00:58:23 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( 0 === $count ) {
|
2013-10-25 00:58:23 +02:00
|
|
|
$pop3->quit();
|
Administration: Replace contracted verb forms for better consistency.
This changeset replaces contracted verb forms like `doesn't`, `can't`, or `isn't` with non-contracted forms like `does not`, `cannot`, or `is not`, for better consistency across the WordPress administration. It also updates some corresponding unit tests strings.
Props Presskopp, socalchristina, aandrewdixon, francina, SergeyBiryukov, JeffPaul, audrasjb, hellofromTonya.
Fixes #38913.
See #39176.
Built from https://develop.svn.wordpress.org/trunk@52978
git-svn-id: http://core.svn.wordpress.org/trunk@52567 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-03-22 17:25:03 +01:00
|
|
|
wp_die( __( 'There does not seem to be any new mail.' ) );
|
2013-10-25 00:58:23 +02:00
|
|
|
}
|
|
|
|
|
2022-10-17 13:02:17 +02:00
|
|
|
// Always run as an unauthenticated user.
|
|
|
|
wp_set_current_user( 0 );
|
|
|
|
|
2013-10-25 00:58:23 +02:00
|
|
|
for ( $i = 1; $i <= $count; $i++ ) {
|
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
$message = $pop3->get( $i );
|
2013-10-25 00:58:23 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
$bodysignal = false;
|
|
|
|
$boundary = '';
|
|
|
|
$charset = '';
|
|
|
|
$content = '';
|
|
|
|
$content_type = '';
|
2013-10-25 00:58:23 +02:00
|
|
|
$content_transfer_encoding = '';
|
2017-12-01 00:11:00 +01:00
|
|
|
$post_author = 1;
|
|
|
|
$author_found = false;
|
2021-09-22 23:01:00 +02:00
|
|
|
$post_date = null;
|
|
|
|
$post_date_gmt = null;
|
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
foreach ( $message as $line ) {
|
2014-07-17 11:12:16 +02:00
|
|
|
// Body signal.
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( strlen( $line ) < 3 ) {
|
2013-10-25 00:58:23 +02:00
|
|
|
$bodysignal = true;
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2013-10-25 00:58:23 +02:00
|
|
|
if ( $bodysignal ) {
|
|
|
|
$content .= $line;
|
|
|
|
} else {
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( preg_match( '/Content-Type: /i', $line ) ) {
|
|
|
|
$content_type = trim( $line );
|
|
|
|
$content_type = substr( $content_type, 14, strlen( $content_type ) - 14 );
|
|
|
|
$content_type = explode( ';', $content_type );
|
2013-10-25 00:58:23 +02:00
|
|
|
if ( ! empty( $content_type[1] ) ) {
|
2017-12-01 00:11:00 +01:00
|
|
|
$charset = explode( '=', $content_type[1] );
|
|
|
|
$charset = ( ! empty( $charset[1] ) ) ? trim( $charset[1] ) : '';
|
2013-10-25 00:58:23 +02:00
|
|
|
}
|
|
|
|
$content_type = $content_type[0];
|
|
|
|
}
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( preg_match( '/Content-Transfer-Encoding: /i', $line ) ) {
|
|
|
|
$content_transfer_encoding = trim( $line );
|
|
|
|
$content_transfer_encoding = substr( $content_transfer_encoding, 27, strlen( $content_transfer_encoding ) - 27 );
|
|
|
|
$content_transfer_encoding = explode( ';', $content_transfer_encoding );
|
2013-10-25 00:58:23 +02:00
|
|
|
$content_transfer_encoding = $content_transfer_encoding[0];
|
|
|
|
}
|
2020-01-09 01:55:05 +01:00
|
|
|
if ( ( 'multipart/alternative' === $content_type ) && ( false !== strpos( $line, 'boundary="' ) ) && ( '' === $boundary ) ) {
|
2017-12-01 00:11:00 +01:00
|
|
|
$boundary = trim( $line );
|
|
|
|
$boundary = explode( '"', $boundary );
|
2013-10-25 00:58:23 +02:00
|
|
|
$boundary = $boundary[1];
|
|
|
|
}
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( preg_match( '/Subject: /i', $line ) ) {
|
|
|
|
$subject = trim( $line );
|
|
|
|
$subject = substr( $subject, 9, strlen( $subject ) - 9 );
|
2020-01-29 01:45:18 +01:00
|
|
|
// Captures any text in the subject before $phone_delim as the subject.
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( function_exists( 'iconv_mime_decode' ) ) {
|
|
|
|
$subject = iconv_mime_decode( $subject, 2, get_option( 'blog_charset' ) );
|
2013-10-25 00:58:23 +02:00
|
|
|
} else {
|
2017-12-01 00:11:00 +01:00
|
|
|
$subject = wp_iso_descrambler( $subject );
|
2013-10-25 00:58:23 +02:00
|
|
|
}
|
2017-12-01 00:11:00 +01:00
|
|
|
$subject = explode( $phone_delim, $subject );
|
2013-10-25 00:58:23 +02:00
|
|
|
$subject = $subject[0];
|
|
|
|
}
|
|
|
|
|
2014-07-17 11:12:16 +02:00
|
|
|
/*
|
|
|
|
* Set the author using the email address (From or Reply-To, the last used)
|
|
|
|
* otherwise use the site admin.
|
|
|
|
*/
|
2013-10-25 00:58:23 +02:00
|
|
|
if ( ! $author_found && preg_match( '/^(From|Reply-To): /', $line ) ) {
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( preg_match( '|[a-z0-9_.-]+@[a-z0-9_.-]+(?!.*<)|i', $line, $matches ) ) {
|
2013-10-25 00:58:23 +02:00
|
|
|
$author = $matches[0];
|
2017-12-01 00:11:00 +01:00
|
|
|
} else {
|
|
|
|
$author = trim( $line );
|
|
|
|
}
|
|
|
|
$author = sanitize_email( $author );
|
|
|
|
if ( is_email( $author ) ) {
|
|
|
|
$userdata = get_user_by( 'email', $author );
|
2013-10-25 00:58:23 +02:00
|
|
|
if ( ! empty( $userdata ) ) {
|
2017-12-01 00:11:00 +01:00
|
|
|
$post_author = $userdata->ID;
|
2013-10-25 00:58:23 +02:00
|
|
|
$author_found = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
if ( preg_match( '/Date: /i', $line ) ) { // Of the form '20 Mar 2002 20:32:37 +0100'.
|
|
|
|
$ddate = str_replace( 'Date: ', '', trim( $line ) );
|
2023-01-11 14:59:13 +01:00
|
|
|
// Remove parenthesized timezone string if it exists, as this confuses strtotime().
|
2020-01-29 01:45:18 +01:00
|
|
|
$ddate = preg_replace( '!\s*\(.+\)\s*$!', '', $ddate );
|
2020-01-09 01:55:05 +01:00
|
|
|
$ddate_timestamp = strtotime( $ddate );
|
|
|
|
$post_date = gmdate( 'Y-m-d H:i:s', $ddate_timestamp + $time_difference );
|
|
|
|
$post_date_gmt = gmdate( 'Y-m-d H:i:s', $ddate_timestamp );
|
2013-10-25 00:58:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Set $post_status based on $author_found and on author's publish_posts capability.
|
2013-10-25 00:58:23 +02:00
|
|
|
if ( $author_found ) {
|
2017-12-01 00:11:00 +01:00
|
|
|
$user = new WP_User( $post_author );
|
|
|
|
$post_status = ( $user->has_cap( 'publish_posts' ) ) ? 'publish' : 'pending';
|
2013-10-25 00:58:23 +02:00
|
|
|
} else {
|
|
|
|
// Author not found in DB, set status to pending. Author already set to admin.
|
|
|
|
$post_status = 'pending';
|
|
|
|
}
|
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
$subject = trim( $subject );
|
2013-10-25 00:58:23 +02:00
|
|
|
|
2020-01-09 01:55:05 +01:00
|
|
|
if ( 'multipart/alternative' === $content_type ) {
|
2017-12-01 00:11:00 +01:00
|
|
|
$content = explode( '--' . $boundary, $content );
|
2013-10-25 00:58:23 +02:00
|
|
|
$content = $content[2];
|
2014-07-17 11:12:16 +02:00
|
|
|
|
|
|
|
// Match case-insensitive content-transfer-encoding.
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( preg_match( '/Content-Transfer-Encoding: quoted-printable/i', $content, $delim ) ) {
|
|
|
|
$content = explode( $delim[0], $content );
|
2013-10-25 00:58:23 +02:00
|
|
|
$content = $content[1];
|
|
|
|
}
|
2017-12-01 00:11:00 +01:00
|
|
|
$content = strip_tags( $content, '<img><p><br><i><b><u><em><strong><strike><font><span><div>' );
|
2013-10-25 00:58:23 +02:00
|
|
|
}
|
2017-12-01 00:11:00 +01:00
|
|
|
$content = trim( $content );
|
2013-10-25 00:58:23 +02:00
|
|
|
|
2013-11-13 12:58:12 +01:00
|
|
|
/**
|
2016-05-23 18:44:27 +02:00
|
|
|
* Filters the original content of the email.
|
2013-11-13 12:58:12 +01:00
|
|
|
*
|
|
|
|
* Give Post-By-Email extending plugins full access to the content, either
|
|
|
|
* the raw content, or the content of the last quoted-printable section.
|
|
|
|
*
|
|
|
|
* @since 2.8.0
|
|
|
|
*
|
|
|
|
* @param string $content The original email content.
|
|
|
|
*/
|
|
|
|
$content = apply_filters( 'wp_mail_original_content', $content );
|
2013-10-25 00:58:23 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( false !== stripos( $content_transfer_encoding, 'quoted-printable' ) ) {
|
|
|
|
$content = quoted_printable_decode( $content );
|
2013-10-25 00:58:23 +02:00
|
|
|
}
|
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( function_exists( 'iconv' ) && ! empty( $charset ) ) {
|
|
|
|
$content = iconv( $charset, get_option( 'blog_charset' ), $content );
|
2013-10-25 00:58:23 +02:00
|
|
|
}
|
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Captures any text in the body after $phone_delim as the body.
|
2017-12-01 00:11:00 +01:00
|
|
|
$content = explode( $phone_delim, $content );
|
2013-10-25 00:58:23 +02:00
|
|
|
$content = empty( $content[1] ) ? $content[0] : $content[1];
|
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
$content = trim( $content );
|
2013-10-25 00:58:23 +02:00
|
|
|
|
2013-11-13 12:58:12 +01:00
|
|
|
/**
|
2016-05-23 18:44:27 +02:00
|
|
|
* Filters the content of the post submitted by email before saving.
|
2013-11-13 12:58:12 +01:00
|
|
|
*
|
|
|
|
* @since 1.2.0
|
|
|
|
*
|
|
|
|
* @param string $content The email content.
|
|
|
|
*/
|
|
|
|
$post_content = apply_filters( 'phone_content', $content );
|
2013-10-25 00:58:23 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
$post_title = xmlrpc_getposttitle( $content );
|
2013-10-25 00:58:23 +02:00
|
|
|
|
2020-04-14 13:32:06 +02:00
|
|
|
if ( '' === trim( $post_title ) ) {
|
2017-12-01 00:11:00 +01:00
|
|
|
$post_title = $subject;
|
|
|
|
}
|
2013-10-25 00:58:23 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
$post_category = array( get_option( 'default_email_category' ) );
|
2013-10-25 00:58:23 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
$post_data = compact( 'post_content', 'post_title', 'post_date', 'post_date_gmt', 'post_author', 'post_category', 'post_status' );
|
|
|
|
$post_data = wp_slash( $post_data );
|
2013-10-25 00:58:23 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
$post_ID = wp_insert_post( $post_data );
|
|
|
|
if ( is_wp_error( $post_ID ) ) {
|
2013-10-25 00:58:23 +02:00
|
|
|
echo "\n" . $post_ID->get_error_message();
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2013-10-25 00:58:23 +02:00
|
|
|
|
Docs: Revise comments using “we” in WordPress root directory files.
This updates some inline comments to better match the guidelines and recommendations set forth in the make/core and make/docs handbooks:
> In general, use second person in your documentation. Second person depicts a friendly tone, with a perfect focus on the reader. In addition to this, directly addressing the reader helps avoid passive voice; thereby preventing unwanted confusion.
> ...
> the word “we” should be avoided (...) unless its made very clear which group is speaking.
Includes:
* Replacing first-person usage of "we" with second person point of view.
* Making small clarification adjustments where the voice is much too casual or lacks clear context, especially for non-native English speakers.
References:
* [https://make.wordpress.org/docs/style-guide/language-grammar/grammatical-person/ Style Guide: Grammatical person]
* [https://make.wordpress.org/docs/handbook/documentation-team-handbook/handbooks-style-and-formatting-guide/ Handbooks & HelpHub Style and Formatting Guide]
* [https://make.wordpress.org/core/handbook/best-practices/post-comment-guidelines/#style-and-substance Post & Comment Guidelines: Style and Substance]
Follow-up to [2176], [3430], [4676], [6009], [7991], [12688], [12762], [26008], [28978], [44488], [44962], [51979], [53131], [53132], [53156], [53131], [54200].
Props ironprogrammer, costdev, jorbin, SergeyBiryukov.
See #57052.
Built from https://develop.svn.wordpress.org/trunk@54866
git-svn-id: http://core.svn.wordpress.org/trunk@54418 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-11-23 16:43:13 +01:00
|
|
|
// The post wasn't inserted or updated, for whatever reason. Better move forward to the next email.
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( empty( $post_ID ) ) {
|
2013-10-25 00:58:23 +02:00
|
|
|
continue;
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2013-10-25 00:58:23 +02:00
|
|
|
|
2013-11-13 12:58:12 +01:00
|
|
|
/**
|
|
|
|
* Fires after a post submitted by email is published.
|
|
|
|
*
|
|
|
|
* @since 1.2.0
|
|
|
|
*
|
|
|
|
* @param int $post_ID The post ID.
|
|
|
|
*/
|
|
|
|
do_action( 'publish_phone', $post_ID );
|
2013-10-25 00:58:23 +02:00
|
|
|
|
2015-09-20 04:53:25 +02:00
|
|
|
echo "\n<p><strong>" . __( 'Author:' ) . '</strong> ' . esc_html( $post_author ) . '</p>';
|
|
|
|
echo "\n<p><strong>" . __( 'Posted title:' ) . '</strong> ' . esc_html( $post_title ) . '</p>';
|
2013-10-25 00:58:23 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( ! $pop3->delete( $i ) ) {
|
2015-09-20 04:53:25 +02:00
|
|
|
echo '<p>' . sprintf(
|
2019-09-03 02:41:05 +02:00
|
|
|
/* translators: %s: POP3 error. */
|
2015-09-20 04:53:25 +02:00
|
|
|
__( 'Oops: %s' ),
|
|
|
|
esc_html( $pop3->ERROR )
|
|
|
|
) . '</p>';
|
2013-10-25 00:58:23 +02:00
|
|
|
$pop3->reset();
|
|
|
|
exit;
|
|
|
|
} else {
|
2015-09-20 04:53:25 +02:00
|
|
|
echo '<p>' . sprintf(
|
2019-09-03 02:41:05 +02:00
|
|
|
/* translators: %s: The message ID. */
|
2015-09-20 04:53:25 +02:00
|
|
|
__( 'Mission complete. Message %s deleted.' ),
|
|
|
|
'<strong>' . $i . '</strong>'
|
|
|
|
) . '</p>';
|
2013-10-25 00:58:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$pop3->quit();
|