I am using forms with the email input. In the form email settings I use also "Email from name" which is selected from one of the form textfields.
When submitting such a form - the error happens which looks like this:
The submitted from address (=?UTF-8?B?Ij0/VVRGLTg/Qj9WbWxrWlhaMVpITXR4SUJ5YVdweklFeGhjSE5oTENCQmJtUnk=?= =?UTF-8?B?WldweklFdHlZWFBGaG1scmIzWnpMQ0JMeElFPT89CiA9P1VURi04P0I/Y214cGM=?= =?UTF-8?B?eUJUZEhKaGRYUno/PSIgPG1hcnRpbnMubGFzbWFuaXNAZ21haWwuY29tPg==?=) is not valid.
I digged the code and so far it seams that the problem comes from the function below where the name is mime_header_encoded:
webform_format_email_address($address, $name, $node = NULL, $submission = NULL, $encode = TRUE, $single = TRUE, $format = NULL){
...
if ($format == 'long' && !empty($name)) {
$name = _webform_filter_values($name, $node, $submission, NULL, FALSE, TRUE);
if ($encode) {
$name = mime_header_encode($name);
}
return '"' . $name . '" <' . $address . '>';
}
else {
return $address;
}
}
When the 'long' format is enabled in the global webform configuration - the email from address is encoded and it seams that smtp module does not like it, because the error comes from the smtp module.
In the webforms config "Email format settings" I switched Long format: "Example Name" to the Short format: name@example.com and now everything works fine. Seams that the SMTP module is not capable with the from address set to format: "Example Name" and encoded
Comment | File | Size | Author |
---|---|---|---|
#21 | smtp_email-validation-1790436-20.patch | 1.8 KB | indigoxela |
| |||
#19 | smtp_email-validation-1790436-test_only.patch | 1.24 KB | indigoxela |
Comments
Comment #1
quicksketchPlease move this to the correct queue if I selected the wrong SMTP module. Webform is only using the PHP function for encoding the FROM address as specified by e-mail standards. SMTP module should decode the headers if it's doing additional validation on the way out.
Comment #2
filnug CreditAttribution: filnug commentedThat helped me a lot.
Thank you
Comment #3
beto_beto CreditAttribution: beto_beto commentedfilnug
#2 it is work with me too thank you :)
i have another question i am using drupal as another language for my website
now
E-mail template
Submitted on %date
Submitted by user: %username
Submitted values are:
%email_values
The results of this submission may be viewed at:
%submission_url
Include all files as attachments
when the website send the email it send like
PGh0bWw+CiAgPGhlYWQ+CiAgICA8bWV0YSBodHRwLWVxdWl2PSJDb250ZW50LVR5cGUiIGNvbnRl bnQ9InRleHQvaHRtbDsgY2hhcnNldD11dGYtOCIgLz4KICAgICAgICA8c3R5bGUgdHlwZT0idGV4
this is what is send to me
Comment #3.0
beto_beto CreditAttribution: beto_beto commentedsmall text change
Comment #4
STINGER_LP CreditAttribution: STINGER_LP commentedSame issue on 7.x-1.0 version when E-mail settings in Webform module set to 'Long format'.
Comment #5
gifthorse CreditAttribution: gifthorse commentedI've found another workaround for this bug: E-mail format can be set to Long if 'Send e-mail as HTML' is also checked. But for this checkbox to appear the mimemail module should be enabled. Tested on D6 only.
Comment #6
zifiniti CreditAttribution: zifiniti as a volunteer commentedThis issue is caused by improper email validation on the From address when the From name contains new line characters in between the double quotes.
Per Section 3.1.1 of RFC 822, long header fields are permitted to contain new line breaks. Situations where this may occur are with modules such as Webform which runs the From header through mime_header_encode(). If the string is longer than 47 bytes it will be chunked apart with new line characters.
The problematic code from SMTP Authentication is in smtp.mail.inc starting at line ~105:
The first regex here is does not match new line characters in between the double quotes causing those specific From values with them to fail. Once that fails, it moves over to valid_email_address to attempt to validate where it will again fail as this function uses PHP's FILTER_VALIDATE_EMAIL filter which does not support whitespace folding.
I've created a patch to fix this problem as well as also reduce the number of regexes being used to match and pull out the name and email from this header value as there is no need to run the regex 3 times:
Comment #7
zifiniti CreditAttribution: zifiniti as a volunteer commentedComment #8
Nikolay ShapovalovI'm not sure about code quality, but patch worked great for me.
Comment #9
DamienMcKennaThere really should be a comment before the if() statement explaining what it's doing.
Comment #10
DamienMcKennaRerolling the patch.
Comment #11
DamienMcKennaPutting this back to needs work as there really ought to be some tests around the string handling.
Comment #12
thpoul CreditAttribution: thpoul as a volunteer commented+1 on the reroll. Manual tested it and I can confirm this is working in my case. Thank you for this.
Comment #13
Anskelt CreditAttribution: Anskelt at Lund University commentedPatches are not compatible with the current 7-1.x branch or 7-1.x-dev branch for me.
Comment #14
lamp5I have got the same problem when i mixed mimemail interface with smtp and i have got empty "Email from" settings in smtp. When i fill form "smtp settings" and save the errors goes away. For the problems with webform, i think that change email type in global webform settings should help.
Comment #15
emek CreditAttribution: emek at Lund University commentedSince the code in the previous patches was moved I tried to locate them and apply the changed regex there, this patch seems to do the trick for me.
Comment #16
bzaher CreditAttribution: bzaher commented#15 worked for me. It was patched onto 7.x-1.7.
Comment #17
armrus CreditAttribution: armrus at Initlab commentedWith #15 patch line breaks in email address and tabulations in name marked as valid.
But it wrong. In name allowed line breaks (@see https://www.ietf.org/rfc/rfc2047.txt)
Comment #18
armrus CreditAttribution: armrus at Initlab commentedComment #19
indigoxela CreditAttribution: indigoxela commentedFWIW: Here's a functional test for the encoded name scenario.
The short encoded name test passes also with the current code, but I added it for completeness.
Comment #21
indigoxela CreditAttribution: indigoxela commentedThe patch by armrus needs re-rolling (offset 38 lines), but the change is identical to #17.
So here's the combined patch and test. Ready for review.
Comment #22
indigoxela CreditAttribution: indigoxela commented