Invalid unsubscribe link for test

Created on 8 November 2018, over 5 years ago
Updated 21 October 2023, 8 months ago

Problem/Motivation

1) A test newsletter contains an invalid link is created containing a text string. This comes from the following code in simplenews.tokens.inc:

case 'unsubscribe-url':
            if (!$subscriber->id()) {
              // Temporary test subscriber.
              $replacements[$original] = t('No unsubscribe link for test subscribers.');
              continue;
            }

Proposed resolution

  1. The token code should make no replacements if the subscriber has no ID
  2. Instead we catch this case in template_preprocess_simplenews_newsletter_body() and set the opt_out_hidden variable.
πŸ› Bug report
Status

Fixed

Version

4.0

Component

Documentation

Created by

πŸ‡ΈπŸ‡¬Singapore adominique

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.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    59 pass
  • πŸ‡©πŸ‡ͺGermany mkalkbrenner πŸ‡©πŸ‡ͺ
  • πŸ‡¬πŸ‡§United Kingdom AdamPS
  • Status changed to Needs review 9 months ago
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.1 & MySQL 8
    last update 9 months ago
    60 pass
  • πŸ‡¬πŸ‡§United Kingdom AdamPS
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.1 & MySQL 8
    last update 9 months ago
    60 pass
  • πŸ‡¬πŸ‡§United Kingdom AdamPS
    • AdamPS β†’ committed c167d46f on 4.x
      Issue #3012160 by AdamPS, tostinni: Invalid unsubscribe link for test
      
  • Status changed to Fixed 9 months ago
  • πŸ‡¬πŸ‡§United Kingdom AdamPS
  • πŸ‡¬πŸ‡§United Kingdom AdamPS
  • Status changed to Active 8 months ago
  • πŸ‡¨πŸ‡¦Canada yang_yi_cn

    The "fix" seems to be breaking it again...

    The website encountered an unexpected error. Please try again later.
    
    InvalidArgumentException: The user-entered string '[simplenews-subscriber:unsubscribe-url]' must begin with a '/', '?', or '#'. in Drupal\Core\Url::fromUserInput() (line 216 of core/lib/Drupal/Core/Url.php).
    Drupal\mimemail\Utility\MimeMailFormatHelper::mimeMailUrl('[simplenews-subscriber:unsubscribe-url]') (Line: 207)
    Drupal\mimemail\Utility\MimeMailFormatHelper::Drupal\mimemail\Utility\{closure}(Array)
    preg_replace_callback('/(<a>]+href=")([^"]*)/mi', Object, '
    
      
        
        Mime Mail message template
    
  • πŸ‡¨πŸ‡¦Canada yang_yi_cn

    Ok I guess this is somewhat a documentation (or maybe adding to description so it could be a "Coding") issue.

    Basically, this ticket is about "Invalid unsubscribe link for TEST", which is the NodeTabForm at a newsletter node > newsletter tab, where you can send test emails to preview, without actually sending the email to the whole list, very useful feature.

    The NodeTabForm.php load the "current user email" as the DEFAULT e-mail (this is important),
    then does some validation to ensure all emails are valid emails,
    then eventually calls

     $this->mailer->sendTest(...
    

    where the Mailer.php does the test sends. However, during the test send, it checkes if the emails are actually subscribers or not. IF THE EMAIL IS NOT A SUBSCRIBER, IT PASSES EMPTY SUBSCRIBER TO THE EMAIL BUILDER.

    It all makes sense but now
    - if the current user doing the test is not a subscriber to the newsletter
    - when email subscriber is empty, the [simplenews-subscriber:unsubscribe-url] token replacement is skipped, so the token is still there in the body text.
    - MimeMail does a check on all links and found
    - WSOD

    I think for the bare minimal, we need to add this info after the test email description "A comma-separated list of email addresses.", so it becomes:
    "A comma-separated list of email addresses. The e-mails MUST BE SUBSCRIBERS OF THE NEWSLETTER, or the unsubscribe URL might cause the sending to fail."

    Or ideally we validate those emails are actually subsribers when submitting the NodeTabForm, and if they are not subscribers, show an validation error.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.1 & MySQL 8
    last update 8 months ago
    61 pass
  • @yang_yi_cn opened merge request.
  • Status changed to Fixed 8 months ago
  • πŸ‡¬πŸ‡§United Kingdom AdamPS

    For me it works perfectly to send a test email to a non-subscriber.

    Please check your simplenews-newsletter-body.html.twig template. You should have something like below. This means the unsubscribe link is skipped for a non-subscriber.

          {% if unsubscribe_text %}
            <a href="[simplenews-subscriber:unsubscribe-url]">{{ unsubscribe_text }}</a>
          {% endif %}
    

    If you still have problems then please open a new issue. This fix for this one has been released and it will cause confusion if we use the same issue again.

    MimeMail is no longer a supported Mail plug-in. If gives WSOD for <a href="[simplenews-subscriber:unsubscribe-url]"> then I'd say that's a bug.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024