comment:body token arriving with HTML tags

Created on 14 August 2020, over 4 years ago
Updated 14 May 2024, 6 months ago

Problem/Motivation

When I receive comment notify emails I'm having the problem that the [comment:body] token is being sent as HTML (e.g., with tags like this around the text:

text

). The [comment:title] is fine. I'm sending using swiftmailer.

Steps to reproduce

  1. Enable and configure a module for sending emails with HTML, such as SwiftMailer
  2. Configure Comment Notify's message body to include the token [comment:body]
  3. Leave a comment with formatted text.
  4. View the email triggered by the recently posted comment

Proposed resolution

Convert the results of token->replace() with PlainTextOutput::renderFromHtml().

here https://www.drupal.org/project/auto_entitylabel/issues/2850962 πŸ› Some characters replaced with HTML entities in tokenised labels Fixed

So I changed the line 454 in comment_notify.module from
$message['body'] = \Drupal::token()->replace($raw_values['body'], $token_data);
to
$message['body'] = PlainTextOutput::renderFromHtml(\Drupal::token()->replace($raw_values['body'], $token_data));

Remaining tasks

  • βœ… Write patch
  • βœ… Test
  • ❌ Code review
πŸ› Bug report
Status

RTBC

Version

1.0

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom benjarlett

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡§πŸ‡ͺBelgium RandalV

    I've tested the MR and that also solves the issue for us.
    HTML mails are turned on via a contrib module, all other HTML mails / markup works.

    Thanks for the fix. Hopefully it gets committed.

  • Assigned to gnuget
  • πŸ‡ΊπŸ‡ΈUnited States cedewey Denver, CO

    Thanks all for working on this fix. I'm updating this to a Bug report and assigning it to gnuget for a code review.

  • πŸ‡³πŸ‡ΏNew Zealand dominictaylor

    Hi All,

    I'm running into the same problem, HTML emails are fine for other system emails, but not for this module. e.g

    lorem ipsum

    I updated to version "1.x-dev@dev", but still the same issue so I assume it hasn't been reviewed and merged yet?
    Can I change the settings so Comment Notify just sends plain text or something until such time it is merged ?

    Thanks very much

  • πŸ‡³πŸ‡ΏNew Zealand dominictaylor

    Re: my previous comment, turns out it was due to an issue with SMTP mailer detailed here
    https://www.drupal.org/project/smtp/issues/3323386 πŸ› Error sending e-mail: Invalid address RTBC

    Applying the patch from there solved it for me.

    Cheers

Production build 0.71.5 2024