All letters (including from /admin/config/swiftmailer/test) not sent with error:
The website encountered an unexpected error. Please try again later.
Error: Call to undefined method Swift_Mime_Headers_UnstructuredHeader::getAddresses() in Drupal\swiftmailer\Utility\Conversion::swiftmailer_filter_message() (line 413 of modules/contrib/swiftmailer/src/Utility/Conversion.php).
Drupal\swiftmailer\Utility\Conversion::swiftmailer_filter_message(Object) (Line: 337)
Drupal\swiftmailer\Plugin\Mail\SwiftMailer->mail(Array) (Line: 50)
Drupal\mailsystem\Adapter->mail(Array) (Line: 311)
Drupal\Core\Mail\MailManager->doMail('swiftmailer', 'test', 'info@sday-lom.ru', 'ru', Array, NULL, 1) (Line: 180)
Drupal\Core\Mail\MailManager->Drupal\Core\Mail\{closure}() (Line: 578)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 181)
Drupal\Core\Mail\MailManager->mail('swiftmailer', 'test', 'info@sday-lom.ru', 'ru', Array, NULL, 1) (Line: 70)
Drupal\mailsystem\MailsystemManager->mail('swiftmailer', 'test', 'info@sday-lom.ru', 'ru') (Line: 57)
Drupal\swiftmailer\Form\TestForm->submitForm(Array, Object)
call_user_func_array(Array, Array) (Line: 113)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 51)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 593)
Drupal\Core\Form\FormBuilder->processForm('swiftmailer_test_form', Array, Object) (Line: 321)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 578)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 158)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 80)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 50)
Drupal\ban\BanMiddleware->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 716)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
I guess issue is related to Unicode::mimeHeaderEncode() doesn't correctly follow RFC 2047
If $site_mail is multibyte string like Сдай-лом.рф and from address info@sday-lom.ru
$mailbox->getBodyAsString() in
if ($site_mail) {
$mailbox = new MailboxHeader('From', new Address($site_mail, $site_config->get('name') ?: ''));
$headers['From'] = $mailbox->getBodyAsString();
}
produces:
=?utf-8?Q?=D0=A1=D0=B4=D0=B0=D0=B9-=D0=BB=D0=BE=D0=BC?=
=?utf-8?Q?=2E=D1=80=D1=84?=
The workaround is patch #3 from https://www.drupal.org/project/swiftmailer/issues/3167898
But letter's From became =?utf-8?Q?=D0=A1=D0=B4=D0=B0=D0=B9-=D0=BB=D0=BE=D0=BC?=.рф <info@sday-lom.ru>
So I guess in $headers['From'] = $mailbox->getBodyAsString(); is something wrong.
| Comment | File | Size | Author |
|---|---|---|---|
| #23 | interdiff-21-23.txt | 1.41 KB | g-brodiei |
| #23 | success-fix-qEncoding-3219705-23.patch | 2.76 KB | g-brodiei |
| #21 | interdiff-20-21.txt | 498 bytes | g-brodiei |
| #21 | success-fix-qEncoding-3219705-21.patch | 3.14 KB | g-brodiei |
| #20 | success-test-conversion.patch | 3.14 KB | g-brodiei |
Comments
Comment #2
super_romeo commentedComment #3
super_romeo commentedComment #4
tr commentedComment #5
super_romeo commentedPHP 8
Drupal 9.2-dev.
Comment #6
alexpottThe From field in the issue summary is correctly encoded... as far as I can see...
Comment #7
g-brodieiBackground
We've encountered the same issue after we upgraded Core from Drupal 9.1.10 to 9.2.2
Mail System 8.x-4.3
SwiftMailer 8.x-2.0
Steps to reproduce the issue
Temp Solution We Figured out
The temporary solution of this issue for us was by changing our site name to pure english. (We're building a Chinese Site).
The Cause
As mailManager.php has been updated since Drupal 9.2, \Drupal\Component\Utility\Mail::formatDisplayName() was replaced by \Symfony\Component\Mime\Header\MailboxHeader.
New code as seen below.
Read Change Records. https://www.drupal.org/node/3207439
While processing through $mailbox->getBodyAsString(), our Chinese encoding has gone wrong running getTokenAsEncodedWord() in vendor/symfony/mime/Header/AbstractHeader.php.
Drupal 9.1 "=?UTF-8?B?5Y+w54Gj5rC457qM5bGV5pyb5aSp?="
Drupal 9.2 (6 Character, 台灣永續展望) "=?utf-8?Q?=E5=8F=B0=E7=81=A3=E6=B0=B8=E7=BA=8C=E5=B1=95=E6=9C=9B?="
Drupal 9.2 (7 Character, 台灣永續展望天) "=?utf-8?Q?=E5=8F=B0=E7=81=A3=E6=B0=B8=E7=BA=8C?=
=?utf-8?Q?=E5=B1=95=E6=9C=9B=E5=A4=A9?="
When seen in our mailhog, with patch#3 given by OP, it shows the wrong character on the FROM name of email.
Comment #8
g-brodieiSo for now the preg_match pattern in SwiftMailer that checks doesn't fit the new Q-encoding styling in
web/modules/contrib/swiftmailer/src/Utility/Conversion.php
Therefore returning false, not setting the headerType correctly in line 248 of web/modules/contrib/swiftmailer/src/Plugin/Mail/SwiftMailer.php.
should be "mailbox", instead "text" was returned.
Comment #9
g-brodieiAdd patch to remove new lines and carriage in returned string for encoded long site name.
Comment #10
g-brodieiSetting issue status to need review
Comment #11
super_romeo commentedPatch #9 works. Thank you @g-brodiei!
Comment #12
tr commentedPatch adds 2 coding standards violations. You should be using short array syntax, [] instead of array().
Otherwise, looks good.
Comment #13
g-brodieiUpdate patch to meet coding standards, thanks @TR!
Hooray! @super_romeo
Comment #14
a.kovrigin commentedPatch from #13 worked for me.
Comment #15
adamps commentedThanks for the patch. Please can someone explain in more detail? It seems that this patch is saying that line-breaks are legitimate inside mailbox headers and they can safely be ignored. Is there a webpage or specification that confirms this?
The comments should be updated to contain the explanation please. And I suggest to remove the reference to a specific version of Drupal.
It would be great to have a test to validate this case. It should be simple: just use the example from the issue summary or one of the comments.
Comment #16
alexpott@AdamPS yes line breaks are totally legitimate within a mime header. The spec on mime headers is very specific about line lengths. Note that a line break within a header does not mean a line break within the header value. Have a look at #84883: Unicode::mimeHeaderEncode() doesn't correctly follow RFC 2047 and the related RFCs.
Comment #17
adamps commentedThanks @alexpott.
I would suggest the comments could be written as Alex says:
Comment #18
g-brodieiUpdated patch comment by suggestion on #17, thanks to @AdamPS and @alexpott.
Comment #19
adamps commentedGreat thanks. All this needs now is a simple test (see #15) then it can be committed.
Comment #20
g-brodieiAdded fail and success test on Utilities of Conversion static function
1. swiftmailer_is_mailbox_header (should return true after patch)
2. swiftmailer_parse_mailboxes (decoded text should match site_name given after patch)
Comment #21
g-brodieiSwapping the assertEquals to meet argument description (swapping expected and actual variables).
Add interdiff.txt
Comment #22
adamps commentedGreat thanks. Please can you fix the 4 extra coding standards messages? After that it's good to commit.
Comment #23
g-brodieiHi @AdamPS, thanks for reviewing the patch, but I think I'm missing two other that's within the scope?
Currently I fixed
Line 217 Line exceeds 80 characters; contains 89 characters
Line 302 Line exceeds 80 characters; contains 95 characters
Comment #24
g-brodieiComment #25
adamps commentedThanks. You did it right - removing the use statements fixed the other 2.
Comment #26
g-brodieiGood to know, thanks!
Comment #27
niklanCan someone explain why is this issue marked as "Fixed"? I didn't see any related commits into the module.
Comment #28
alexpott@AdamPS maybe you need to push :) (the number of times I've forgotten to do that...)
Comment #30
adamps commentedOops thanks for the reminder.