Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@
<element value="CharSet"/>
<element value="ContentType"/>
<element value="Encoding"/>
<element value="From"/>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these a leftover? I think they are already covered by phpcs:disable

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, they might be, but Core should be aware that they are valid fields. PHPCS nagged me about them and tried to get me to introduce defects because of it.

<element value="FromName"/>
<element value="Hostname"/>
<element value="mailHeader"/>
<element value="MIMEBody"/>
Expand Down
70 changes: 48 additions & 22 deletions src/wp-includes/pluggable.php
Original file line number Diff line number Diff line change
Expand Up @@ -1841,17 +1841,30 @@ function wp_notify_postauthor( $comment_id, $deprecated = null ) {
$blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
$comment_content = wp_specialchars_decode( $comment->comment_content );

/*

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel that having the exact same anonymus function here and in L2072 could lead in the future, to one deviating unnecessarily from the other (although AI tends to catch all coincidences pretty wel). Still I would rather opt to extract both and move it into a common place.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my use of the anonymous function was an attempt to avoid new abstractions during the release cycle for WordPress 7.2. I’m happy to expand these afterwards, but I think we want to be careful about creating a name for this transformation which is very specific to mail header fields.

if nothing else, I would want @ignore and @access private and something very specific, like _wp_ioslate_email_header_field_corrupting_violations()

probably for the WordPress 7.2 release I will want to keep it the same. I hesitated to abstract it at all into a closure after @westonruter’s comment, but I think it was reasonable to ask that the behavior be repeatable.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still, I'm not sure which is the difference from a release perspective. Maybe I'm missing some rule.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the difference is that now we have the release candidate and are focusing on fixing issues that arose during the period since WordPress 7.1.

Adding a new function raises questions about the interface and how best to design it, which is work for the normal release cycle. Adding one now adds a new function to the global namespace and invites usage by plugins which can lock it into place even if it’s the “wrong” interface.

as I hesitated to even add the closure, for fear of over-eager abstraction, I am less interested in tossing something last-minute into public view, even if it comes with @ignore.

I appreciate the desire though. when I started this work I started with a slightly more complete question: how can we properly communicate email header fields? and that escalated so I pared back the patch. it would be lovely if we could move into an even-more nuanced approach for setting these fields, in WordPress 7.3 or later

* Line breaks in the comment author fields would end the header or line they
* are placed in, letting the comment author add email headers or lines of their own.
*/
$isolate_header_value = static function ( $value ): string {
$is_stringy = is_string( $value ) || ( is_object( $value ) && method_exists( $value, '__toString' ) );
$value = $is_stringy ? (string) $value : '';
return trim( (string) preg_replace( '/[\r\n]+/', ' ', $value ) );
};
$comment_author = $isolate_header_value( $comment->comment_author );
$comment_author_email = $isolate_header_value( $comment->comment_author_email );
$comment_author_url = $isolate_header_value( $comment->comment_author_url );

$wp_email = 'wordpress@' . preg_replace( '#^www\.#', '', wp_parse_url( network_home_url(), PHP_URL_HOST ) );

if ( '' === $comment->comment_author ) {
if ( '' === $comment_author ) {
$from = "From: \"$blogname\" <$wp_email>";
if ( '' !== $comment->comment_author_email ) {
$reply_to = "Reply-To: $comment->comment_author_email";
if ( is_email( $comment_author_email ) ) {
$reply_to = "Reply-To: $comment_author_email";
}
} else {
$from = "From: \"$comment->comment_author\" <$wp_email>";
if ( '' !== $comment->comment_author_email ) {
$reply_to = "Reply-To: \"$comment->comment_author_email\" <$comment->comment_author_email>";
$from = "From: \"$comment_author\" <$wp_email>";
if ( is_email( $comment_author_email ) ) {
$reply_to = "Reply-To: \"$comment_author_email\" <$comment_author_email>";
}
}
Comment on lines -1846 to 1869

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good. So previously it was just checking if the email was a non-empty-string. Now it's also checking if it is an actual valid email.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And if the email is less than 6 characters, is_email() returns false always. (Ahem, unless the is_email filter overrides this.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inasmuch as Core is able to determine “valid”


Expand Down Expand Up @@ -1886,9 +1899,9 @@ function wp_notify_postauthor( $comment_id, $deprecated = null ) {
/* translators: %s: Post title. */
$notify_message = sprintf( __( 'New trackback on your post "%s"' ), $post->post_title ) . "\r\n";
/* translators: 1: Trackback/pingback website name, 2: Website IP address, 3: Website hostname. */
$notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
$notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
/* translators: %s: Trackback/pingback/comment author URL. */
$notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n";
$notify_message .= sprintf( __( 'URL: %s' ), $comment_author_url ) . "\r\n";
/* translators: %s: Comment text. */
$notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n";
$notify_message .= __( 'You can see all trackbacks on this post here:' ) . "\r\n";
Expand All @@ -1900,9 +1913,9 @@ function wp_notify_postauthor( $comment_id, $deprecated = null ) {
/* translators: %s: Post title. */
$notify_message = sprintf( __( 'New pingback on your post "%s"' ), $post->post_title ) . "\r\n";
/* translators: 1: Trackback/pingback website name, 2: Website IP address, 3: Website hostname. */
$notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
$notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
/* translators: %s: Trackback/pingback/comment author URL. */
$notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n";
$notify_message .= sprintf( __( 'URL: %s' ), $comment_author_url ) . "\r\n";
/* translators: %s: Comment text. */
$notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n";
$notify_message .= __( 'You can see all pingbacks on this post here:' ) . "\r\n";
Expand All @@ -1914,9 +1927,9 @@ function wp_notify_postauthor( $comment_id, $deprecated = null ) {
/* translators: %s: Post title. */
$notify_message = sprintf( __( 'New note on your post "%s"' ), $post->post_title ) . "\r\n";
/* translators: 1: Note author's name, 2: Note author's IP address, 3: Note author's hostname. */
$notify_message .= sprintf( __( 'Author: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
$notify_message .= sprintf( __( 'Author: %1$s (IP address: %2$s, %3$s)' ), $comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
/* translators: %s: Note author email. */
$notify_message .= sprintf( __( 'Email: %s' ), $comment->comment_author_email ) . "\r\n";
$notify_message .= sprintf( __( 'Email: %s' ), $comment_author_email ) . "\r\n";
/* translators: %s: Note text. */
$notify_message .= sprintf( __( 'Note: %s' ), "\r\n" . ( empty( $comment_content ) ? __( 'resolved/reopened' ) : $comment_content ) ) . "\r\n\r\n";
$notify_message .= __( 'You can see all notes on this post here:' ) . "\r\n";
Expand All @@ -1928,11 +1941,11 @@ function wp_notify_postauthor( $comment_id, $deprecated = null ) {
/* translators: %s: Post title. */
$notify_message = sprintf( __( 'New comment on your post "%s"' ), $post->post_title ) . "\r\n";
/* translators: 1: Comment author's name, 2: Comment author's IP address, 3: Comment author's hostname. */
$notify_message .= sprintf( __( 'Author: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
$notify_message .= sprintf( __( 'Author: %1$s (IP address: %2$s, %3$s)' ), $comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
/* translators: %s: Comment author email. */
$notify_message .= sprintf( __( 'Email: %s' ), $comment->comment_author_email ) . "\r\n";
$notify_message .= sprintf( __( 'Email: %s' ), $comment_author_email ) . "\r\n";
/* translators: %s: Trackback/pingback/comment author URL. */
$notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n";
$notify_message .= sprintf( __( 'URL: %s' ), $comment_author_url ) . "\r\n";

if ( $comment->comment_parent && user_can( $post->post_author, 'edit_comment', $comment->comment_parent ) ) {
/* translators: Comment moderation. %s: Parent comment edit URL. */
Expand Down Expand Up @@ -2056,6 +2069,19 @@ function wp_notify_moderator( $comment_id ) {
$blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
$comment_content = wp_specialchars_decode( $comment->comment_content );

/*
* Line breaks in the comment author fields would end the header or line they
* are placed in, letting the comment author add email headers or lines of their own.
*/
$isolate_header_value = static function ( $value ): string {
$is_stringy = is_string( $value ) || ( is_object( $value ) && method_exists( $value, '__toString' ) );
$value = $is_stringy ? (string) $value : '';
return trim( (string) preg_replace( '/[\r\n]+/', ' ', $value ) );
};
$comment_author = $isolate_header_value( $comment->comment_author );
$comment_author_email = $isolate_header_value( $comment->comment_author_email );
$comment_author_url = $isolate_header_value( $comment->comment_author_url );

$message_headers = '';

/**
Expand Down Expand Up @@ -2093,9 +2119,9 @@ function wp_notify_moderator( $comment_id ) {
$notify_message = sprintf( __( 'A new trackback on the post "%s" is waiting for your approval' ), $post->post_title ) . "\r\n";
$notify_message .= get_permalink( $comment->comment_post_ID ) . "\r\n\r\n";
/* translators: 1: Trackback/pingback website name, 2: Website IP address, 3: Website hostname. */
$notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
$notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
/* translators: %s: Trackback/pingback/comment author URL. */
$notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n";
$notify_message .= sprintf( __( 'URL: %s' ), $comment_author_url ) . "\r\n";
/* translators: %s: Trackback excerpt text. */
$notify_message .= sprintf( __( 'Trackback excerpt: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n";
break;
Expand All @@ -2105,9 +2131,9 @@ function wp_notify_moderator( $comment_id ) {
$notify_message = sprintf( __( 'A new pingback on the post "%s" is waiting for your approval' ), $post->post_title ) . "\r\n";
$notify_message .= get_permalink( $comment->comment_post_ID ) . "\r\n\r\n";
/* translators: 1: Trackback/pingback website name, 2: Website IP address, 3: Website hostname. */
$notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
$notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
/* translators: %s: Trackback/pingback/comment author URL. */
$notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n";
$notify_message .= sprintf( __( 'URL: %s' ), $comment_author_url ) . "\r\n";
/* translators: %s: Pingback excerpt text. */
$notify_message .= sprintf( __( 'Pingback excerpt: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n";
break;
Expand All @@ -2117,11 +2143,11 @@ function wp_notify_moderator( $comment_id ) {
$notify_message = sprintf( __( 'A new comment on the post "%s" is waiting for your approval' ), $post->post_title ) . "\r\n";
$notify_message .= get_permalink( $comment->comment_post_ID ) . "\r\n\r\n";
/* translators: 1: Comment author's name, 2: Comment author's IP address, 3: Comment author's hostname. */
$notify_message .= sprintf( __( 'Author: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
$notify_message .= sprintf( __( 'Author: %1$s (IP address: %2$s, %3$s)' ), $comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
/* translators: %s: Comment author email. */
$notify_message .= sprintf( __( 'Email: %s' ), $comment->comment_author_email ) . "\r\n";
$notify_message .= sprintf( __( 'Email: %s' ), $comment_author_email ) . "\r\n";
/* translators: %s: Trackback/pingback/comment author URL. */
$notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n";
$notify_message .= sprintf( __( 'URL: %s' ), $comment_author_url ) . "\r\n";

if ( $comment->comment_parent ) {
/* translators: Comment moderation. %s: Parent comment edit URL. */
Expand Down
Loading
Loading