Problem/Motivation

D8.9.3
After updating SM from 1.0-beta1 to 2.0-beta2, it get an error when sending email via Simplenews module :

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: 307)
Drupal\Core\Mail\MailManager->doMail('simplenews', 'test', 'bpelvillain@gmail.com', 'fr', Array, '"=?UTF-8?B?Q29vcMOpcmF0aXZlcyBkJ0FjdGl2aXTDqXMgZXQgZCdFbXBsb2kgZW4gSWxsZS0=?=
=?UTF-8?B?ZXQtVmlsYWluZQ==?=" ', 1) (Line: 179)
Drupal\Core\Mail\MailManager->Drupal\Core\Mail\{closure}() (Line: 573)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 180)
Drupal\Core\Mail\MailManager->mail('simplenews', 'test', 'bpelvillain@gmail.com', 'fr', Array, '"=?UTF-8?B?Q29vcMOpcmF0aXZlcyBkJ0FjdGl2aXTDqXMgZXQgZCdFbXBsb2kgZW4gSWxsZS0=?=
=?UTF-8?B?ZXQtVmlsYWluZQ==?=" ', 1) (Line: 70)
Drupal\mailsystem\MailsystemManager->mail('simplenews', 'test', 'bpelvillain@gmail.com', 'fr', Array, '"=?UTF-8?B?Q29vcMOpcmF0aXZlcyBkJ0FjdGl2aXTDqXMgZXQgZCdFbXBsb2kgZW4gSWxsZS0=?=
=?UTF-8?B?ZXQtVmlsYWluZQ==?=" ') (Line: 332)
Drupal\simplenews\Mail\Mailer->sendMail(Object) (Line: 388)
Drupal\simplenews\Mail\Mailer->sendTest(Object, Array) (Line: 211)
Drupal\simplenews\Form\NodeTabForm->submitTestMail(Array, Object)
call_user_func_array(Array, Array) (Line: 114)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 52)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 593)
Drupal\Core\Form\FormBuilder->processForm('simplenews_node_tab', Array, Object) (Line: 321)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 91)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 573)
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: 151)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
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: 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: 708)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

This issue does'nt appear when testing via /admin/config/swiftmailer/test.

Steps to reproduce

  1. Install and configure Simplenews.
  2. Create a content from 'Newsletter issue' content type.
  3. From this content, click on Newsletter tab and send a test.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#3 swiftmailer-3167898-03.patch2.02 KBRuedische
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

brulain created an issue. See original summary.

geek-merlin’s picture

Thanks for filing this issue and providing the backtrace!

I guess this happens when from or to field contains nonvalid mail addresses.

@brulain can you confirm this?

If that's true, in these lines we have to check for instanceof \Swift_Mime_Headers_MailboxHeader before we call the method.
Patch appreciated.

  public static function swiftmailer_filter_message(Swift_Message $message) {
...
    $senders = $headers->get('From')->getAddresses();
...
    $recipients = $headers->get('To')->getAddresses();
Ruedische’s picture

StatusFileSize
new2.02 KB

A working patch is applied.

brulain’s picture

Thanks a lot guys !
The patch #3 fixes this issue.

geek-merlin’s picture

Title: After updating to 2.0.0-beta1 » Exception on sending (probably when to: malformed)
Version: 8.x-2.0-beta1 » 8.x-2.x-dev
Status: Active » Needs work

Hint: After uploading a patch set status to needs-review. And always check current dev. Descriptive title helps too ;-)

Thanks for rolling and testing a patch!

1. Alas, we not have to check $headers (which is always instanceof Swift_Mime_SimpleHeaderSet), but $headers->get('from') / $headers->get('to').

2. Can you please provide the from/too headers so this can be reproduced.

3. We have to decide how to handle that error. I'm not sure how the rest of the module handles this. But just hiding the problem without even logging is not an option.

4. Whatever we decide, we need tests. (and therefore 2))

brulain’s picture

Here are the headers of a newsletter issue (test):

Delivered-To: bpelvillain@gmail.com
Received: by 2002:a2e:571b:0:0:0:0:0 with SMTP id l27csp2100644ljb;
Sat, 5 Sep 2020 00:19:25 -0700 (PDT)
X-Google-Smtp-Source: ABdhPJzxWIvTWIehenIL1rkITuh+4s2R4dmZ89sXTizcz9YH65ToE4auC+Qv3yXcmDBabU59bzYj
X-Received: by 2002:a5d:61c2:: with SMTP id q2mr12079689wrv.25.1599290365420;
Sat, 05 Sep 2020 00:19:25 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1599290365; cv=none;
d=google.com; s=arc-20160816;
b=HSvQ10pjsB3s3sexhUPlbDmjTyeplOwDyC0+7507oJEAiKKZY6ZJUD6pIFYT/Roy3I
ZCcIi2Z2Jz4PwMEBzRBSD3+uslAvaU2Xtbq4afdzOeL+ScOhF88TPaWn5IAkhrz04rwt
IHWpUAd485elHg5ETa94IMVY1iPmxkR+AS5hcbDcA4Ns8+dijKuXI19gMRWN60i4FDzW
DFy8FRPG2EeNmpKgbNfO2EUky2rj76rH25PgisJC5xvsFsEUUdLGAPuq63RXSqEP5iwq
Oj4XWFlMD4ffYsS1ePTO45tDvdcSe3VU9vJkqOygbMqy4jJDsm2CO5nhnylYq6vQjMAQ
TQ/Q==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
h=list-unsubscribe:precedence:mime-version:to:reply-to:from:subject
:date:message-id:sender;
bh=r7P9Xuv/iokyzK9Z+YFg5SQHfH3+9pX0029+1lPhVeE=;
b=GdqQb8HDSWfMmVSvIwc3Tou6Pxr6iE+FnymG2z+nwvXCf75FgIlYCf+CWWt+Q161Pg
9KSd5wNKji8jp3vcD/YFr15hB5R4Uwq2kxIkJL8cT/f4v4Yjjp8sg63sYCUT7rEM/HOC
DTe2A4ypsiJnFxKLAOhMBVdKFasHfrOcOyhgNUmb4vtAgGhJz84IYU3vkfcXIFU8aCMs
TVPM9DZqC5DETA5IWYKfmImZFR+BMTlk99eDOoyaG0ENBxA/H1w0EFbkjvuu6hlhfmWA
6uUvtk3aE/P0SUOY9/V88Byp6NFOY5ZFGnoLLn2KZI1v44K1xOI/FMDKOKII58yje+Fv
+Bow==
ARC-Authentication-Results: i=1; mx.google.com;
spf=pass (google.com: domain of contact@elancreateur.coop designates 217.70.183.194 as permitted sender) smtp.mailfrom=contact@elancreateur.coop
Return-Path:
Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net. [217.70.183.194])
by mx.google.com with ESMTPS id l13si3747703wrw.351.2020.09.05.00.19.25
for
(version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256);
Sat, 05 Sep 2020 00:19:25 -0700 (PDT)
Received-SPF: pass (google.com: domain of contact@elancreateur.coop designates 217.70.183.194 as permitted sender) client-ip=217.70.183.194;
Authentication-Results: mx.google.com;
spf=pass (google.com: domain of contact@elancreateur.coop designates 217.70.183.194 as permitted sender) smtp.mailfrom=contact@elancreateur.coop
X-Originating-IP: 51.91.102.202
Received: from [127.0.0.1] (202.ip-51-91-102.eu [51.91.102.202])
(Authenticated sender: smtp@cae35.coop)
by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id D952A40005
for ; Sat, 5 Sep 2020 07:19:24 +0000 (UTC)
Sender: contact@elancreateur.coop
Message-ID: <071da2427f43ff246608544ebba35ecc@dev-entrepreneurs.elancreateur.coop>
Date: Sat, 05 Sep 2020 09:19:24 +0200
Subject: [[simplenews-category:name]] L'info hebdo du 31/08/2020
From: =?UTF-8?Q?=22=3D=3FUTF-8=3FB=3FQ29vcMOpcmF0aXZlcyBkJ0FjdGl2aXTDq?=
=?UTF-8?Q?XMgZXQgZCdFbXBsb2kgZW4gSWxsZS0=3D=3F=3D=0A?=
=?UTF-8?B?ZXQtVmlsYWluZQ==?="
Reply-to: =?UTF-8?Q?=22=3D=3FUTF-8=3FB=3FQ29vcMOpcmF0aXZlcyBkJ0FjdGl2a?=
=?UTF-8?Q?XTDqXMgZXQgZCdFbXBsb2kgZW4gSWxsZS0=3D=3F=3D=0A?=
=?UTF-8?B?ZXQtVmlsYWluZQ==?="
To: bpelvillain@gmail.com
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="_=_swift_1599290364_c69427fa2f86a64f7bf299164d8510ec_=_"
X-Mailer: Drupal
Precedence: bulk
List-Unsubscribe:

--_=_swift_1599290364_c69427fa2f86a64f7bf299164d8510ec_=_
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

brulain’s picture

I have changed the From headers and rolled back the patch: no more error when sending a (test) newsletter issue.

Delivered-To: bpelvillain@gmail.com
Received: by 2002:a2e:571b:0:0:0:0:0 with SMTP id l27csp2107125ljb;
Sat, 5 Sep 2020 00:33:50 -0700 (PDT)
X-Google-Smtp-Source: ABdhPJy7mUg/MzcbATMV4TS0pSVmgrt6/brvGdlPHpDHvDEuXAAgUFM4si8DERtwYaB3o83V9CKI
X-Received: by 2002:a2e:920f:: with SMTP id k15mr5748215ljg.353.1599291230875;
Sat, 05 Sep 2020 00:33:50 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1599291230; cv=none;
d=google.com; s=arc-20160816;
b=XKBEUrWAloM+VL5RYL5qKkA5N+MacmOqa97wCCOM70pc/3rRsDJW4RQO6QNxMAmxKw
Jwx4gYsUvZS0nqDWd0RPmAjptg6FTI+1GBjxOR3l/pKy/bondfAodfJHmlx4Y83rx1fl
jVx0iquHNwtYj50rniLRfKSaP/i6zoMUN3vyR1la70jcsn6+f+0TiSDB8WbDVU6ZzXPh
BFUdiBO5mWZ3kwL5/xE+8emVcUiO09BlvVeTRq+k2YRhUPMmjai4zuxVxiyAd3E/4NqH
CGVfAceO4lQod0UC1eBSSq7M4vvvu+bflg/Pgv9BRrhjFGex0JytiEGxLa7ibDFGszBZ
/ukw==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
h=list-unsubscribe:precedence:mime-version:to:reply-to:from:subject
:date:message-id:sender;
bh=MyuCZDNsup2RXu2XzPMcS5HnNFUC41k7fsYGnEOtV2U=;
b=C9RQ2qfS/5tNHpIJGJIlJjukj1Nsgqd0/c/MCsqHCw1Xs0ndDNZDesvMG3HvZsGuAJ
C+OAgy6859H+gLgcF4MjDUf5T0DN0dnVsVykGO+zE/pbYXSkTc4YzydULsfxJr49AVXk
d02G9ll1V/L67/dZaCVIjfwqBlF0LMLQoeq18TyYwLfHXAfMl/PX5qXeLSBiOSthnD7w
m4sDWwQ8OpJnhmx/6YqA1cDk+4Dp8sfLrV4C7/HnR1O0e7E0+gFDpkIsSQmA/xMpQ19C
PLQAon5oNPUWy7MZOswKCofjVbBvLs5nsyYNYsB79qqPGPRrZt/5exSUpjeOxlXoFItO
WAsg==
ARC-Authentication-Results: i=1; mx.google.com;
spf=pass (google.com: domain of contact@elancreateur.coop designates 217.70.178.230 as permitted sender) smtp.mailfrom=contact@elancreateur.coop
Return-Path:
Received: from relay10.mail.gandi.net (relay10.mail.gandi.net. [217.70.178.230])
by mx.google.com with ESMTPS id k5si4619151lji.510.2020.09.05.00.33.50
for
(version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256);
Sat, 05 Sep 2020 00:33:50 -0700 (PDT)
Received-SPF: pass (google.com: domain of contact@elancreateur.coop designates 217.70.178.230 as permitted sender) client-ip=217.70.178.230;
Authentication-Results: mx.google.com;
spf=pass (google.com: domain of contact@elancreateur.coop designates 217.70.178.230 as permitted sender) smtp.mailfrom=contact@elancreateur.coop
Received: from [127.0.0.1] (202.ip-51-91-102.eu [51.91.102.202])
(Authenticated sender: smtp@cae35.coop)
by relay10.mail.gandi.net (Postfix) with ESMTPSA id 1DB8E24000D
for ; Sat, 5 Sep 2020 07:33:29 +0000 (UTC)
Sender: contact@elancreateur.coop
Message-ID: <8f8a3adb04c8cebddf852810f840026b@dev-entrepreneurs.elancreateur.coop>
Date: Sat, 05 Sep 2020 09:33:29 +0200
Subject: Espace collaboratif : L'info hebdo du 31/08/2020
From: =?UTF-8?B?w4lsYW4gY3LDqWF0ZXVy?=
Reply-to: =?UTF-8?B?w4lsYW4gY3LDqWF0ZXVy?=
To: bpelvillain@gmail.com
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="_=_swift_1599291209_bf128bef751323f775ca63bcb7f49d8a_=_"
X-Mailer: Drupal
Precedence: bulk
List-Unsubscribe:

--_=_swift_1599291209_bf128bef751323f775ca63bcb7f49d8a_=_
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

geek-merlin’s picture

Title: Exception on sending (probably when to: malformed) » Exception on sending (probably when from/to malformed)

@brulain: Do you have an explanation for this? I do not grok that utf8-encoding stuff in "from".

brulain’s picture

@geek-merlin: no explanation.
The original From value in Simplenews settings was: Coopérative d'activité et d'emploi - Ile et Vilaine
I changed it to: Élan créateur

geek-merlin’s picture

@brulain: So it looks like all these 'from' headers are invalid as email address, so it's no wonder sending fails.

So maybe we should just throw a descripive exception in such case.

brulain’s picture

@geek-merlin: In fact, I have only changed the value of the "From name" field in Simplenews settings (/admin/config/services/simplenews/manage/default).

shelane’s picture

I am getting the same error simply trying to use the test method on /admin/config/swiftmailer/test with my own email address. After applying the patch, I no longer got that error, but I got another instead:

Warning: reset() expects parameter 1 to be array, string given in Swift_Transport_AbstractSmtpTransport->getReversePath() (line 421 of /var/www/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php).

Swift_Transport_AbstractSmtpTransport->getReversePath(Object) (Line: 194)
Swift_Transport_AbstractSmtpTransport->send(Object, Array) (Line: 71)
Swift_Mailer->send(Object) (Line: 338)
Drupal\swiftmailer\Plugin\Mail\SwiftMailer->mail(Array) (Line: 50)
Drupal\mailsystem\Adapter->mail(Array) (Line: 307)
Drupal\Core\Mail\MailManager->doMail('swiftmailer', 'test', 'mytestemail@email.com', 'en', Array, NULL, 1) (Line: 179)
Drupal\Core\Mail\MailManager->Drupal\Core\Mail\{closure}() (Line: 573)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 180)
Drupal\Core\Mail\MailManager->mail('swiftmailer', 'test', 'mytestemail@email.com', 'en', Array, NULL, 1) (Line: 70)
Drupal\mailsystem\MailsystemManager->mail('swiftmailer', 'test', 'mytestemail@email.com', 'en') (Line: 57)
Drupal\swiftmailer\Form\TestForm->submitForm(Array, Object)
call_user_func_array(Array, Array) (Line: 114)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 52)
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: 91)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 573)
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: 151)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 67)
Drupal\simple_oauth\HttpMiddleware\BasicAuthSwap->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: 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: 708)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Warning: key() expects parameter 1 to be array, string given in Swift_Transport_AbstractSmtpTransport->getReversePath() (line 422 of /var/www/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php).

Swift_Transport_AbstractSmtpTransport->getReversePath(Object) (Line: 194)
Swift_Transport_AbstractSmtpTransport->send(Object, Array) (Line: 71)
Swift_Mailer->send(Object) (Line: 338)
Drupal\swiftmailer\Plugin\Mail\SwiftMailer->mail(Array) (Line: 50)
Drupal\mailsystem\Adapter->mail(Array) (Line: 307)
Drupal\Core\Mail\MailManager->doMail('swiftmailer', 'test', 'mytestemail@email.com', 'en', Array, NULL, 1) (Line: 179)
Drupal\Core\Mail\MailManager->Drupal\Core\Mail\{closure}() (Line: 573)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 180)
Drupal\Core\Mail\MailManager->mail('swiftmailer', 'test', 'mytestemail@email.com', 'en', Array, NULL, 1) (Line: 70)
Drupal\mailsystem\MailsystemManager->mail('swiftmailer', 'test', 'mytestemail@email.com', 'en') (Line: 57)
Drupal\swiftmailer\Form\TestForm->submitForm(Array, Object)
call_user_func_array(Array, Array) (Line: 114)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 52)
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: 91)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 573)
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: 151)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 67)
Drupal\simple_oauth\HttpMiddleware\BasicAuthSwap->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: 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: 708)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
shelane’s picture

Ok, my issue turned out to be that I was testing a site locally that did not have the site from name or email set. Once I set that, it worked without the patch.

mingsong’s picture

I came across this issue.

Steps to reproduce this issue:
1. Enable the Swiftmailer module (8.x-2.0-beta1).
2. Choose the Swiftmailer as the Sender at Configure the Mail System page (/admin/config/system/mailsystem)
3. Enable the Webform module if it hasn't.
4. Create a new Webform in which there is a plain text field called 'From'.
5. Create a email handler for this webform.
6. Choose the input from the 'From' field created from step 4 as the from address of the email sent out by this webform.
7. Go to the webform created and fill in an invalid email address for the 'From' text field. For example: 'My email'.
8. Submit this webform.

Once submitting this form, the white screen with the same PHP error message shows up.

Updated:
Patch at #3 avoids this error from happening.

AnnaE1990’s picture

swiftmailer-3167898-03.patch
i have some issue 2 websites witch the same module in one when i use mail system sender plugin swift mailer (simplenews) its work fine.
On second websites i have:
"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/swiftmailer/src/Utility/Conversion.php)."
This patch is applied.
i use modules:
Mail System 8.x-4.3
Swift Mailer 8.x-2.0
simplenews 3.0.0-alpha1

And report from website:
"Error: Call to undefined method Swift_Mime_Headers_UnstructuredHeader::getAddresses() w Drupal\swiftmailer\Utility\Conversion::swiftmailer_filter_message() (linia 413 w /home/e-jankowska/websites/pzg/modules/swiftmailer/src/Utility/Conversion.php)

#0 /home/e-jankowska/websites/pzg/modules/swiftmailer/src/Plugin/Mail/SwiftMailer.php(337): Drupal\swiftmailer\Utility\Conversion::swiftmailer_filter_message(Object(Swift_Message))
#1 /home/e-jankowska/websites/pzg/modules/mailsystem/src/Adapter.php(50): Drupal\swiftmailer\Plugin\Mail\SwiftMailer->mail(Array)
#2 /home/e-jankowska/websites/pzg/core/lib/Drupal/Core/Mail/MailManager.php(311): Drupal\mailsystem\Adapter->mail(Array)
#3 /home/e-jankowska/websites/pzg/core/lib/Drupal/Core/Mail/MailManager.php(180): Drupal\Core\Mail\MailManager->doMail('simplenews', 'test', 'pomoc@e-jankows...', 'pl', Array, '"=?UTF-8?B?IFfF...', true)
#4 /home/e-jankowska/websites/pzg/core/lib/Drupal/Core/Render/Renderer.php(578): Drupal\Core\Mail\MailManager->Drupal\Core\Mail\{closure}()
#5 /home/e-jankowska/websites/pzg/core/lib/Drupal/Core/Mail/MailManager.php(181): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#6 /home/e-jankowska/websites/pzg/modules/mailsystem/src/MailsystemManager.php(70): Drupal\Core\Mail\MailManager->mail('simplenews', 'test', 'pomoc@e-jankows...', 'pl', Array, '"=?UTF-8?B?IFfF...', true)
#7 /home/e-jankowska/websites/pzg/modules/contrib/simplenews/src/Mail/Mailer.php(332): Drupal\mailsystem\MailsystemManager->mail('simplenews', 'test', 'pomoc@e-jankows...', 'pl', Array, '"=?UTF-8?B?IFfF...')
#8 /home/e-jankowska/websites/pzg/modules/contrib/simplenews/src/Mail/Mailer.php(388): Drupal\simplenews\Mail\Mailer->sendMail(Object(Drupal\simplenews\Mail\MailEntity))
#9 /home/e-jankowska/websites/pzg/modules/contrib/simplenews/src/Form/NodeTabForm.php(211): Drupal\simplenews\Mail\Mailer->sendTest(Object(Drupal\node\Entity\Node), Array)
#10 [internal function]: Drupal\simplenews\Form\NodeTabForm->submitTestMail(Array, Object(Drupal\Core\Form\FormState))
#11 /home/e-jankowska/websites/pzg/core/lib/Drupal/Core/Form/FormSubmitter.php(113): call_user_func_array(Array, Array)
#12 /home/e-jankowska/websites/pzg/core/lib/Drupal/Core/Form/FormSubmitter.php(51): Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object(Drupal\Core\Form\FormState))
#13 /home/e-jankowska/websites/pzg/core/lib/Drupal/Core/Form/FormBuilder.php(593): Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object(Drupal\Core\Form\FormState))
#14 /home/e-jankowska/websites/pzg/core/lib/Drupal/Core/Form/FormBuilder.php(321): Drupal\Core\Form\FormBuilder->processForm('simplenews_node...', Array, Object(Drupal\Core\Form\FormState))
#15 /home/e-jankowska/websites/pzg/core/lib/Drupal/Core/Controller/FormController.php(73): Drupal\Core\Form\FormBuilder->buildForm(Object(Drupal\simplenews\Form\NodeTabForm), Object(Drupal\Core\Form\FormState))
#16 [internal function]: Drupal\Core\Controller\FormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch))
#17 /home/e-jankowska/websites/pzg/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
#18 /home/e-jankowska/websites/pzg/core/lib/Drupal/Core/Render/Renderer.php(578): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#19 /home/e-jankowska/websites/pzg/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#20 /home/e-jankowska/websites/pzg/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
#21 /home/e-jankowska/websites/pzg/vendor/symfony/http-kernel/HttpKernel.php(158): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#22 /home/e-jankowska/websites/pzg/vendor/symfony/http-kernel/HttpKernel.php(80): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#23 /home/e-jankowska/websites/pzg/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#24 /home/e-jankowska/websites/pzg/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#25 /home/e-jankowska/websites/pzg/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#26 /home/e-jankowska/websites/pzg/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#27 /home/e-jankowska/websites/pzg/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#28 /home/e-jankowska/websites/pzg/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#29 /home/e-jankowska/websites/pzg/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#30 /home/e-jankowska/websites/pzg/core/lib/Drupal/Core/DrupalKernel.php(716): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#31 /home/e-jankowska/websites/pzg/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#32 {main}"

g-brodiei’s picture

I've encountered the same issue today while upgrading our site from Drupal 9.1 to 9.2.

We're able to reproduce the issue with the following modules.

  1. Install new drupal site 9.2.
  2. Enable mail system, swiftmailer.
  3. Set your mailsystem to assure the default sender as Swiftmailer. (/admin/config/system/mailsystem)
  4. Configure your transport settings to any SMTP service you're using. (/admin/config/swiftmailer/transport)
  5. Set Site Name as Chinese character that is equivalent to 7 characters(Use: 台灣永續展望天) at Basic site settings (/admin/config/system/site-information). (Six characters doesn't show error, probably it suits the encoding of Symfony Mime without going wrong dealing with Chinese characters)
  6. Send a test email to see error message (/admin/config/swiftmailer/test).

We believe this was due to the issue in $mailbox->getBodyAsString() after the Mime change usage of Symfony in

https://www.drupal.org/project/drupal/issues/84883#comment-14052174

g-brodiei’s picture

The regex pattern used in swiftmailer_is_mailbox_header doesn't match the current Q-encoding format, 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.

g-brodiei’s picture

A patch was provided at #3219705-13: Call to undefined method Swift_Mime_Headers_UnstructuredHeader::getAddresses() aiming to fix the q-encoding issue after upgrading to 9.2.

Error: Call to undefined method Swift_Mime_Headers_UnstructuredHeader::getAddresses() in Drupal\swiftmailer\Utility\Conversion::swiftmailer_filter_message() (line 413 of modules/swiftmailer/src/Utility/Conversion.php)."

If that patch works for this issue, hopefully we can close it. (finger crossed)

berdir’s picture

I think this can happen separately from line break problems. We just had a case where this happened for a webform because the client selected a wrong field as sender that was not actually an e-mail.

So IMHO this fix/issue still makes sense. Not sure if the fix is correct though and just silently ignore that specific thing. Maybe the mail shouldn't be sent or with a fallback + a log message?

adamps’s picture

If I understand correctly, this issue is about this: the module throws an exception if the addresses are malformed.

I don't really understand why this is considered a bug. I guess we could ask improve the message to make the cause more obvious.

However this module is minimally supported now due to swiftmailer library soon becoming unsupported so I propose to commit major bug fixes only.

berdir’s picture

> If I understand correctly, this issue is about this: the module throws an exception if the addresses are malformed.

To slightly reword this:

the module throws a confusing, unhelpful exception if the addresses are malformed.

It would already be much better if incorrect user input would result in a clear, helpful exception message (E-mail address "foo" is invalid).

Mail plugins are not expected to throw an exception, that would need to be documented on https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Mail%21Ma... IMHO, similar to other interfaces to have documented exceptions. Then the mail manager or mail send code would be responsible to catch and deal with that exception, but that's now how the drupal mail API works. it has a return status instead, so IMHO, this problem should be caught with a helpful error message and the corresponding status returned.

adamps’s picture

Title: Exception on sending (probably when from/to malformed) » Improve error handling of malformed addresses
Category: Bug report » Task

Thanks @Berdir #21 sounds fine to me as an idea - I updated the title to match

jan kellermann made their first commit to this issue’s fork.