Support from Acquia helps fund testing for Drupal Acquia logo

Comments

das.gautam27 created an issue. See original summary.

das.gautam’s picture

Attaching the patch.

das.gautam’s picture

Assigned: das.gautam » Unassigned
jrockowitz’s picture

Status: Needs review » Needs work

The 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?

jrockowitz’s picture

geroldk’s picture

The 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.

geroldk’s picture

Tried 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?

jrockowitz’s picture

#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.

geroldk’s picture

I 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):

In addition to the above ASCII characters, international characters above U+007F, encoded as UTF-8, are permitted by RFC 6531, though mail systems may restrict which characters to use when assigning local-parts.

Not sure what UTF8 characters get scrambled for @das.gautam27 ? All or only some?

Maybe everything is in order?

jrockowitz’s picture

Status: Needs work » Postponed (maintainer needs more info)

It 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.

das.gautam’s picture

Status: Postponed (maintainer needs more info) » Needs review
FileSize
2.39 KB

Hello @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.

  • das.gautam27 authored 9f6c804 on 8.x-5.x
    Issue #2896055 by das.gautam27: From header containing UTF-8 characters...
jrockowitz’s picture

@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.

jrockowitz’s picture

Status: Needs review » Fixed

  • das.gautam27 authored a2f5818 on 8.x-5.x
    Issue #2896055 by das.gautam27: From header containing UTF-8 characters...

Status: Fixed » Closed (fixed)

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

casey’s picture

FileSize
1.39 KB

After 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.

casey’s picture