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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

quicksketch’s picture

Project: Webform » SMTP Authentication Support
Version: 6.x-3.x-dev » 6.x-1.x-dev

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

filnug’s picture

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

That helped me a lot.

Thank you

beto_beto’s picture

filnug

#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

beto_beto’s picture

Issue summary: View changes

small text change

STINGER_LP’s picture

Version: 6.x-1.x-dev » 7.x-1.0
Priority: Normal » Critical
Issue summary: View changes

Same issue on 7.x-1.0 version when E-mail settings in Webform module set to 'Long format'.

gifthorse’s picture

I'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.

zifiniti’s picture

This 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:

if (preg_match('/^"?.*"?\s*<.*>$/', $from)) {
      // . == Matches any single character except line break characters \r and \n.
      // * == Repeats the previous item zero or more times.
      $from_name = preg_replace('/"?([^("\t\n)]*)"?.*$/', '$1', $from); // It gives: Name
      $from      = preg_replace("/(.*)\<(.*)\>/i", '$2', $from); // It gives: name@domain.tld
}
elseif (!valid_email_address($from)) {
       drupal_set_message(t('The submitted from address (@from) is not valid.', array('@from' => $from)), 'error');
       if ($logging) {
         watchdog('smtp', 'The submitted from address (@from) is not valid.', array('@from' => $from), WATCHDOG_ERROR);
       }
       return FALSE;
     }

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:

     if (preg_match('/^"?([^"]*)"?\s*<(.*)>$/', $from, $matches)) {
       // First parenthesis contains the quoted sender's name
       $from_name = $matches[1];
       // Second parenthesis contains the sender's email address
       $from = $matches[2];
     } 
     elseif ...
zifiniti’s picture

Status: Active » Needs review
Nikolay Shapovalov’s picture

I'm not sure about code quality, but patch worked great for me.

DamienMcKenna’s picture

Version: 7.x-1.0 » 7.x-1.x-dev

There really should be a comment before the if() statement explaining what it's doing.

DamienMcKenna’s picture

FileSize
1 KB

Rerolling the patch.

DamienMcKenna’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Putting this back to needs work as there really ought to be some tests around the string handling.

thpoul’s picture

+1 on the reroll. Manual tested it and I can confirm this is working in my case. Thank you for this.

Anskelt’s picture

Patches are not compatible with the current 7-1.x branch or 7-1.x-dev branch for me.

lamp5’s picture

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

emek’s picture

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

bzaher’s picture

#15 worked for me. It was patched onto 7.x-1.7.

armrus’s picture

With #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)

An 'encoded-word' may not be more than 75 characters long, including
'charset', 'encoding', 'encoded-text', and delimiters. If it is
desirable to encode more text than will fit in an 'encoded-word' of
75 characters, multiple 'encoded-word's (separated by CRLF SPACE) may
be used.

armrus’s picture

Status: Needs work » Needs review
indigoxela’s picture

FWIW: 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.

Status: Needs review » Needs work

The last submitted patch, 19: smtp_email-validation-1790436-test_only.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

indigoxela’s picture

Status: Needs work » Needs review
FileSize
1.8 KB

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

indigoxela’s picture

Issue tags: -Needs tests