Support from Acquia helps fund testing for Drupal Acquia logo

Comments

weseze created an issue. See original summary.

weseze’s picture

Issue summary: View changes
jrockowitz’s picture

We should move most of the code webform_mail to \Drupal\webform\Plugin\WebformHandler\EmailWebformHandler::getMessage

weseze’s picture

Can you explain why that would be better? Wouldn't that get in the way of using a custom mailhandlers? (I for example use my own HTML mailhander, not webforms)

Anyway I've had to revisit my code above since it wasn't working properly. Attached is a functional patch now.

I removed some todo's and logic because it shouldn't be webforms responsibility to check for correct things to avoid SPAM. That should be the responsibility of the site builder. We could indicate in the config screens of webform and the submissions mail handler what to do and not to do.

Basically, to make sure messages are never marked as SPAM:
1/ The "to", "from" and "reply-to" can be anything you want it to be
2/ The "return-path" should always be internal and a verifiable address
3/ The "sender" should be an internal and a verifiable address, but it can be omitted if the "from" is an internal and a verifiable address

weseze’s picture

Issue summary: View changes
jrockowitz’s picture

The reply_to, return_path, sender_path, and sender_name all are coming from the EmailWebformHandler. I also seeing the default values being set correctly. I think you found a issue/bug that just needs to be fixed in the EmailWebformHandler.

weseze’s picture

I think I understand now :) I'll have another crack at it soon.

jrockowitz’s picture

@weseze I think the key is writing some tests that check the reply_to, return_path, sender_path, and sender_name so that then you can verify that tokens are being replace correctly.

Keep in mind the webform_mail() overrides values set via \Drupal\Core\Mail\MailManager::doMail

I made an architecture mistake by putting too much business logic into webform_mail().

weseze’s picture

I figured out why the tokens weren't working, in fact some parameters were just never set.

This line of code prevented "sender, return_path" from ever being set because they are not configurable within an email handler and can never have the value "default": (EmailWebformHandler::getMessage())

// Set default value.
if ($configuration_value === 'default') {
  $configuration_value = $this->getDefaultConfigurationValue($configuration_key);
}

So I changed to:

// Set default value.
if ($configuration_value === 'default' || empty($configuration_value)) {
  $configuration_value = $this->getDefaultConfigurationValue($configuration_key);
}

And things started working properly.

I've attached a patch with this fix included.
Fixed a few other minor issues with the headers and from/to-thingies in the mailhandler.
I've gotten rid of most of the logic in the hook_mail. (it's indeed better to do as little as possible there)
I've also updated the default settings for return_path and sender_mail/name, because those are vital at preventing spam detection if you start using submission tokens in the from address.

I have not added tests yet. Could you confirm I'm on the right path here?

jrockowitz’s picture

Status: Active » Needs review

Sound right. Let's see if all the tests pass.

The last submitted patch, 4: webform-header_tokens-2936713-4-D8.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 9: webform-header_tokens-2936713-9-D8.patch, failed testing. View results

jrockowitz’s picture

The patch should only address the immediate issue #2936713: Not all email headers allow tokens with some test coverage.

Any additional improvements should be handled in new tickets.

weseze’s picture

I've removed any other changes and just kept the changes to make token replacements in the headers work. (still need to add tests)

jrockowitz’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 14: webform-headertokens-2936713-14-D8.patch, failed testing. View results

weseze’s picture

Status: Needs work » Needs review
FileSize
4.74 KB

Still an issue left with the From header that wasn't correctly set with the previous patch.

Not sure why it was failing... let's try again.

Status: Needs review » Needs work

The last submitted patch, 17: webform-headertokens-2936713-17-D8.patch, failed testing. View results

weseze’s picture

OK, I was patching against RC1, not dev. That was the problem... Attached is the patch against RC1, I will make one against latest dev as well.

weseze’s picture

Status: Needs work » Needs review
FileSize
4.76 KB

And the patch against dev.

Status: Needs review » Needs work

The last submitted patch, 20: webform-headertokens-2936713-19-D8.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

  • jrockowitz committed ee6ac4a on 2936713-email-header-tokens
    Issue #2936713 by weseze: Not all email headers allow tokens
    

  • jrockowitz committed 347ad3a on 2936713-email-header-tokens
    Issue #2936713 by weseze: Not all email headers allow tokens
    

  • jrockowitz committed 3756200 on 8.x-5.x
    Issue #2936713 by weseze: Not all email headers allow tokens
    

  • jrockowitz committed b3386a7 on 8.x-5.x
    Revert "Issue #2936713 by weseze: Not all email headers allow tokens"...

  • jrockowitz committed cf3c790 on 2936713-email-header-tokens
    Issue #2936713 by weseze: Not all email headers allow tokens
    

  • jrockowitz committed 74647ad on 2936713-email-header-tokens
    Issue #2936713 by weseze: Not all email headers allow tokens
    
jrockowitz’s picture

I decided to write the failing test first and then methodically fixed the handler by just adding...

      // Determine if configuration value set to 'default'.
      $is_default_configuration = ($configuration_value === 'default');
      // Determine if configuration value should use global configuration.
      $is_global_configuration = in_array($configuration_key, ['reply_to', 'return_path', 'sender_mail', 'sender_name']);
      if ($is_default_configuration || (!$configuration_value && $is_global_configuration)) {
        $configuration_value = $this->getDefaultConfigurationValue($configuration_key);
      }

...and then I removed all calls to \Drupal::config('webform.settings') in webform_mail().

@weseze Does this solution make sense? Are you okay with it? We have to be really careful when fixing email handlers.

jrockowitz’s picture

Status: Needs work » Needs review

The last submitted patch, 19: webform-headertokens-2936713-19-D8-5.0-rc1.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 28: 2936713-21.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jrockowitz’s picture

Status: Needs work » Needs review

@weseze Please review the patch. Thanks

weseze’s picture

(ignore this comment, didn't see you created a new patch :))

jrockowitz’s picture

@weseze That weird prefix error is from Drupal.org's testbot and always goes away after retesting the patch.

The last submitted patch, 28: 2936713-failing-test-21.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jrockowitz’s picture

Status: Needs review » Fixed

I committed the patch. Please download the latest dev release to review.

jrockowitz’s picture

Status: Fixed » Reviewed & tested by the community

Git.drupal.org is down for maintenance. I will push the commit in the next few hours.

  • jrockowitz committed 8d4974a on 8.x-5.x
    Issue #2936713 by weseze, jrockowitz: Not all email headers allow tokens
    
jrockowitz’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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