Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
After https://www.drupal.org/project/webform/issues/2906792 made it in, it seems that not all mail headers (address and name) allow tokens.
Not quite sure why some work and some don't...
I've replaced (as a test) the function webform_mail() with:
REMOVED CODE: SEE PATCH
Would this be the correct place to do the token replacements?
Comment | File | Size | Author |
---|---|---|---|
#28 | 2936713-21.patch | 5.44 KB | jrockowitz |
| |||
#28 | 2936713-failing-test-21.patch | 1.43 KB | jrockowitz |
#20 | webform-headertokens-2936713-19-D8.patch | 4.76 KB | weseze |
#19 | webform-headertokens-2936713-19-D8-5.0-rc1.patch | 4.74 KB | weseze |
#17 | webform-headertokens-2936713-17-D8.patch | 4.74 KB | weseze |
Comments
Comment #2
weseze CreditAttribution: weseze as a volunteer commentedComment #3
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedWe should move most of the code webform_mail to \Drupal\webform\Plugin\WebformHandler\EmailWebformHandler::getMessage
Comment #4
weseze CreditAttribution: weseze as a volunteer commentedCan 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
Comment #5
weseze CreditAttribution: weseze as a volunteer commentedComment #6
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedThe 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.
Comment #7
weseze CreditAttribution: weseze as a volunteer commentedI think I understand now :) I'll have another crack at it soon.
Comment #8
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commented@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().
Comment #9
weseze CreditAttribution: weseze as a volunteer commentedI 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())
So I changed to:
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?
Comment #10
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedSound right. Let's see if all the tests pass.
Comment #13
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedThe 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.
Comment #14
weseze CreditAttribution: weseze as a volunteer commentedI've removed any other changes and just kept the changes to make token replacements in the headers work. (still need to add tests)
Comment #15
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedComment #17
weseze CreditAttribution: weseze as a volunteer commentedStill 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.
Comment #19
weseze CreditAttribution: weseze as a volunteer commentedOK, 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.
Comment #20
weseze CreditAttribution: weseze as a volunteer commentedAnd the patch against dev.
Comment #28
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedI decided to write the failing test first and then methodically fixed the handler by just adding...
...and then I removed all calls to
\Drupal::config('webform.settings')
inwebform_mail()
.@weseze Does this solution make sense? Are you okay with it? We have to be really careful when fixing email handlers.
Comment #29
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedComment #32
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commented@weseze Please review the patch. Thanks
Comment #33
weseze CreditAttribution: weseze as a volunteer commented(ignore this comment, didn't see you created a new patch :))
Comment #34
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commented@weseze That weird prefix error is from Drupal.org's testbot and always goes away after retesting the patch.
Comment #36
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedI committed the patch. Please download the latest dev release to review.
Comment #37
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedGit.drupal.org is down for maintenance. I will push the commit in the next few hours.
Comment #39
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commented