Blocked user email produces error with Symfony Mailer

Created on 26 August 2022, about 3 years ago
Updated 16 January 2023, over 2 years ago

Problem/Motivation

When a user attempting to login exceeds the login-attempt threshold, the system blocks the user and an email is sent out. Currently, the last step is producing an exception.

The website encountered an unexpected error. Please try again later.
TypeError: Drupal\symfony_mailer\MailerHelper::parseAddress(): Argument #2 ($langcode) must be of type ?string, Drupal\Core\Language\Language given, called in /app/web/modules/contrib/symfony_mailer/modules/symfony_mailer_bc/src/Plugin/EmailBuilder/LegacyEmailBuilder.php on line 91 in Drupal\symfony_mailer\MailerHelper->parseAddress() (line 78 of modules/contrib/symfony_mailer/src/MailerHelper.php).
Drupal\symfony_mailer\MailerHelper->parseAddress('abc@123.com', Object) (Line: 91)
Drupal\symfony_mailer_bc\Plugin\EmailBuilder\LegacyEmailBuilder->build(Object)
call_user_func(Array, Object) (Line: 460)
Drupal\symfony_mailer\Email->process() (Line: 164)
Drupal\symfony_mailer\Mailer->doSend(Object) (Line: 139)
Drupal\symfony_mailer\Mailer->Drupal\symfony_mailer\{closure}() (Line: 564)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 148)
Drupal\symfony_mailer\Mailer->send(Object) (Line: 278)
Drupal\symfony_mailer\Email->send() (Line: 97)
Drupal\symfony_mailer_bc\MailManagerReplacement->mail('login_security', 'block_user_notify', 'abc@123.com', Object, Array, 'no-reply@mailer.example.com', 1) (Line: 392)
login_user_block_user_name(Array, Object) (Line: 192)
login_security_validate(Array, Object)
call_user_func_array('login_security_validate', Array) (Line: 82)
Drupal\Core\Form\FormValidator->executeValidateHandlers(Array, Object) (Line: 275)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object, 'user_login_form') (Line: 118)
Drupal\Core\Form\FormValidator->validateForm('user_login_form', Array, Object) (Line: 588)
Drupal\Core\Form\FormBuilder->processForm('user_login_form', Array, Object) (Line: 320)
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: 564)
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: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
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: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 709)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Steps to reproduce

Install Login Security and Symfony Mailer modules.
Configure the Login Security threshold.
Create a new user and activate.
In a separate browser or incognito, produce failed logins for the new user to trigger the account blocking.
Observe the exception shown above.

Proposed resolution

The issue is that a language object is passed instead of a language code in login_security.module:392.

The reason I am reporting this here, instead of Symfony Mailer, is because the core MailManagerInterface (Drupal\Core\Mail\MailManagerInterface) specifies the language argument should be a string.

Remaining tasks

Update the code.

User interface changes

n/a

API changes

n/a

Data model changes

n/a

πŸ› Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States bfuzze9898

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

No activities found.

Production build 0.71.5 2024