diff --git a/CHANGELOG.md b/CHANGELOG.md index 448dfbdf..d09b6765 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * `@mentions` in the JSON representation of the reply +### Improved + +* Direct Messages: Improve HTML to e-mail text conversion + ## [4.5.1] - 2024-12-18 ### Improved diff --git a/includes/class-mailer.php b/includes/class-mailer.php index de479b10..ceec4c66 100644 --- a/includes/class-mailer.php +++ b/includes/class-mailer.php @@ -171,10 +171,17 @@ public static function direct_message( $activity, $user_id ) { $email = $user->user_email; } + $content = \html_entity_decode( + \wp_strip_all_tags( + str_replace( '
', PHP_EOL . PHP_EOL, $activity['object']['content'] ) + ), + ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 + ); + /* translators: 1: Blog name, 2 Actor name */ $subject = \sprintf( \esc_html__( '[%1$s] Direct Message from: %2$s', 'activitypub' ), \esc_html( get_option( 'blogname' ) ), \esc_html( $actor['name'] ) ); /* translators: 1: Blog name, 2: Actor name */ - $message = \sprintf( \esc_html__( 'New Direct Message: %2$s', 'activitypub' ), \esc_html( get_option( 'blogname' ) ), \wp_strip_all_tags( $activity['object']['content'] ) ) . "\r\n\r\n"; + $message = \sprintf( \esc_html__( 'New Direct Message: %2$s', 'activitypub' ), \esc_html( get_option( 'blogname' ) ), $content ) . "\r\n\r\n"; /* translators: Actor name */ $message .= \sprintf( \esc_html__( 'From: %s', 'activitypub' ), \esc_html( $actor['name'] ) ) . "\r\n"; /* translators: Actor URL */ diff --git a/readme.txt b/readme.txt index 3d251f1d..afce2203 100644 --- a/readme.txt +++ b/readme.txt @@ -132,6 +132,10 @@ For reasons of data protection, it is not possible to see the followers of other == Changelog == += Unreleased = + +* Improved: HTML to e-mail text conversion + = 4.5.1 = * Added: `@mentions` in the JSON representation of the reply diff --git a/tests/includes/class-test-mailer.php b/tests/includes/class-test-mailer.php index 78b596b0..a424be08 100644 --- a/tests/includes/class-test-mailer.php +++ b/tests/includes/class-test-mailer.php @@ -307,4 +307,70 @@ function ( $args ) { remove_all_filters( 'wp_mail' ); wp_delete_user( $user_id ); } + + /** + * Data provider for direct message notification text. + * + * @return array + */ + public function direct_message_text_provider() { + return array( + 'HTML entities' => array( + json_decode( '"