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.
When a user submits a webform, the user receives a scrambled From header in email.
Comment | File | Size | Author |
---|---|---|---|
#17 | 2896055-17.patch | 1.39 KB | casey |
#11 | webform-webform-UTF-8-characters-appears-scrambled-in-emails-2896055-11.patch | 2.39 KB | das.gautam |
| |||
#2 | webform-UTF-8-characters-appears-scrambled-in-emails-2896055-2.patch | 1.08 KB | das.gautam |
|
Comments
Comment #2
das.gautam CreditAttribution: das.gautam as a volunteer commentedAttaching the patch.
Comment #3
das.gautam CreditAttribution: das.gautam as a volunteer commentedComment #4
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedThe PhpMail class which is by the WebformPhpMail class already uses Unicode::mimeHeaderEncode for the headers.
@see http://cgit.drupalcode.org/drupal/tree/core/lib/Drupal/Core/Mail/Plugin/...
@see http://cgit.drupalcode.org/webform/tree/src/Plugin/Mail/WebformPhpMail.php
Are you using a contrib Mail module?
Can you please include some tests that confirm the issue is fixed?
Comment #5
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedComment #6
geroldk CreditAttribution: geroldk as a volunteer commentedThe patch doesn't work for me. Using Swiftmailer.
Tried it with a From name of: Special chars " ' < > sender
which gets turned into: sender
See https://www.drupal.org/node/2895140#comment-12181056 (#23) for a screenshot of the result.
Comment #7
geroldk CreditAttribution: geroldk as a volunteer commentedTried again with latest dev-5.x 8bf1eaf
From name of: Special chars " ' < > sender
gets turned into: Special chars ' sender
The double quote and less than and greater than symbols get stripped out, the single quote symbol stays.
Could this be normal (to be expected) behaviour?
Comment #8
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commented#7 The subject will definitely have HTML tags stripped because the subject is passed through to PlainTextOutput::renderFromHtml. I am not sure why the From name is having HTML tags stripped.
Comment #9
geroldk CreditAttribution: geroldk as a volunteer commentedI did some reading on email addresses and allowable characters.
At least for the testing that I did, it seems to work all according to specifications.
@see RFC3696 section 3 https://tools.ietf.org/html/rfc3696#page-5
The < > and " (double quote) characters are not listed under the allowable characters for the local part (the part before the @ symbol) of an email address, whereas ' (single quote) is allowed.
I suppose that the display name, which is the From field, has the same (or similar) restrictions on allowable characters as the local part of the email.
Further in relation to UTF8 encoded characters, I found this bit on Wikipedia (https://en.wikipedia.org/wiki/Email_address#Local-part):
Not sure what UTF8 characters get scrambled for @das.gautam27 ? All or only some?
Maybe everything is in order?
Comment #10
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedIt is very important to note that Drupal's PhpMail plugin is encoding all headers and I think this issue might be related to a different mail plugin not properly encoding the email headers.
Comment #11
das.gautam CreditAttribution: das.gautam as a volunteer commentedHello @jrockowitz,
I'm not using any contrib email modules. It seems like from_name in webform_mail() function is not encoded, since from_name is not the site name in this case.
A similar issue for Drupal core is mentioned here:
https://www.drupal.org/node/2717965
Attaching tests for the issue.
Comment #13
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commented@das.gautam27 I will honest that I don't fully understand your patch. I think the issue is my lack of understanding of email headers.
With that said, this ticket is a great example of someone providing a patch with enough information and then writing the needed tests... I can't say no to committing the code.
Thanks for your patience.
Comment #14
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedComment #17
casey CreditAttribution: casey at SWIS commentedAfter this patch landed #2717965: Site name is not UTF-8 encoded in email headers also introduced a $shorten parameter for Unicode::mimeHeaderEncode() which it also uses for the From header: https://www.drupal.org/project/drupal/issues/2717965#comment-12320178
Webform should do this too I guess.
Comment #18
casey CreditAttribution: casey at SWIS commentedSeparate issue: #2937761: Use shorten parameter of Unicode::mimeHeaderEncode() for From header