• Resolved jgoldbloom

    (@jgoldbloom)


    Minor issue:

    It seems HTML entities are not being decoded for forum titles in topic subscription emails:

    [Cancer Defiance Support Network] New topic: Jim's blog and welcome message

    If the proper HTML header is included in the email that would be okay and get decoded by mail clients but seems like text email, hence this, I suspect?

Viewing 11 replies - 1 through 11 (of 11 total)
  • Thread Starter jgoldbloom

    (@jgoldbloom)

    This support forum decoded my example above even though I encased it in a code block — sigh. I’m referring to the apostrophy ‘ which became &amp… Etc

    Ugh

    Plugin Author Asgaros

    (@asgaros)

    Hello @jgoldbloom

    the sent mails should contain the HTML-header so images of posts/topics are included as well. So basically this seems not to be a problem for me. Have you removed the HTML header?

    Thread Starter jgoldbloom

    (@jgoldbloom)

    Nope and using standard Mac mail. I will look deeper on my end try different mail clients plus examine the headers.

    Thread Starter jgoldbloom

    (@jgoldbloom)

    Okay, remember this is about the subject line not the body. The issue is when character encoding is UTF-8 in the headser the subject line must be ASCII.

    Details on this including a work around: https://ncona.com/2011/06/using-utf-8-characters-on-an-e-mail-subject/

    But might be just simple to entity decode the subject line and retain your header.

    Below is an example of actual headers from a typical email which led me to this with the ***subject line*** modified by me for this support forum post:

    [Cancer Defiance Support Network] New answer: jim ***& #039;***s test
    To: [email protected]
    Mime-Version: 1.0
    Content-Type: text/html; charset=UTF-8
    Envelope-To: [email protected]
    X-Mailer: PHPMailer 5.2.22 (https://github.com/PHPMailer/PHPMailer)
    Return-Path: <[email protected]>
    Return-Path: <[email protected]>
    Delivery-Date: Wed, 22 Mar 2017 07:39:21 -0400
    Message-Id: <[email protected]>
    Received: from server.cancerdefiance.com by server.cancerdefiance.com (Dovecot) with LMTP id iJmIBmli0lihSQAAD4BhsQ for <[email protected]>; Wed, 22 Mar 2017 07:39:21 -0400
    Received: from ip72-219-201-235.dc.dc.cox.net ([72.219.201.235]:60439 helo=local-cancerdefiance.net) by server.cancerdefiance.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.87) (envelope-from <[email protected]>) id 1cqebp-0004tf-0X for [email protected]; Wed, 22 Mar 2017 07:39:21 -0400
    Delivered-To: [email protected]

    Plugin Author Asgaros

    (@asgaros)

    Hello @jgoldbloom

    So this means that the subject-line is always interpreted as ASCII and I dont need to escape HTML inside it because it will never get executed anyway? What happens when there are UTF-8 characters in the subject-line?

    I dont know if I have to fix this by myself or if this is a bug in WordPress core because basically I just give the text-string to the wp_mail function.

    Anyway, can you please check if the following changes fix the bug for you?

    In asgaros-forum/includes/forum-notifications.php

    Around line 146.

    Replace:

    $notification_subject = sprintf(__('[%s] New answer: %s', 'asgaros-forum'), get_bloginfo('name'), esc_html(stripslashes($topic_name)));

    With:

    $notification_subject = sprintf(__('[%s] New answer: %s', 'asgaros-forum'), get_bloginfo('name'), stripslashes($topic_name));

    Around line 206.

    Replace:

    $notification_subject = sprintf(__('[%s] New topic: %s', 'asgaros-forum'), get_bloginfo('name'), esc_html(stripslashes($topic_name)));

    With:

    $notification_subject = sprintf(__('[%s] New topic: %s', 'asgaros-forum'), get_bloginfo('name'), stripslashes($topic_name));

    Thread Starter jgoldbloom

    (@jgoldbloom)

    Only ASCII is allowed in the subject if UTF-8 encoded, which is the encoding I would use overall, but maybe apply something like the following for the subject line only:

    <?php html_entity_decode($subject, ENT_QUOTES | ENT_XML1, 'UTF-8') ?>

    … in addition to stripping HTML/slashes for the subject. It’s the &xxx; entities in question here. esc_html() is more or less lossless — it just turns HTML markup into encoded visible text, so that it’s not rendered as markup by browser.

    Thread Starter jgoldbloom

    (@jgoldbloom)

    Plugin Author Asgaros

    (@asgaros)

    Thank you, @jgoldbloom

    I just fixed this in the development-version of the plugin and it will be included in the upcoming v1.4.5 release:
    https://github.com/Asgaros/asgaros-forum/commit/1e1dc9d9245e09e3d45daa1c673b1f8d0b61edb1

    Thread Starter jgoldbloom

    (@jgoldbloom)

    Thank you, @asgaros — if any issues I’ll post here when time permits me to test. Cheers and welcome back.

    Thread Starter jgoldbloom

    (@jgoldbloom)

    Subject line still broken in dev version.

    New topic: Jim’s test

    Became:

    New topic: Jim & quot;s test <—- edit: modified to add space after ampersand as this support forum decoded it even in a code block , ugh.

    hmmmm…

    Aha! Just add ENT_QUOTES as 2nd argument to wp_specialchars_decode() which according to the docs decodes single/double quotes also. I looked at your code and no 2nd argument defined so the function defaults to ENT_NOQUOTES which does not decode quotes!

    Simple fix and you’ll nail it! ??

    • This reply was modified 7 years, 7 months ago by jgoldbloom.
    Plugin Author Asgaros

    (@asgaros)

    Thanks, fixed! ??

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘HTML entities in topic subscription emails’ is closed to new replies.