Mercurial > hg > isophonics-drupal-site
diff core/lib/Drupal/Core/Mail/MailManager.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 7a779792577d |
children |
line wrap: on
line diff
--- a/core/lib/Drupal/Core/Mail/MailManager.php Tue Jul 10 15:07:59 2018 +0100 +++ b/core/lib/Drupal/Core/Mail/MailManager.php Thu Feb 28 13:21:36 2019 +0000 @@ -2,13 +2,17 @@ namespace Drupal\Core\Mail; +use Drupal\Component\Render\MarkupInterface; use Drupal\Component\Render\PlainTextOutput; -use Drupal\Component\Utility\Unicode; +use Drupal\Component\Utility\Html; +use Drupal\Component\Utility\Mail as MailHelper; use Drupal\Core\Logger\LoggerChannelFactoryInterface; +use Drupal\Core\Messenger\MessengerTrait; use Drupal\Core\Plugin\DefaultPluginManager; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Config\ConfigFactoryInterface; +use Drupal\Core\Render\Markup; use Drupal\Core\Render\RenderContext; use Drupal\Core\Render\RendererInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; @@ -23,6 +27,7 @@ */ class MailManager extends DefaultPluginManager implements MailManagerInterface { + use MessengerTrait; use StringTranslationTrait; /** @@ -249,12 +254,8 @@ // Return-Path headers should have a domain authorized to use the // originating SMTP server. $headers['Sender'] = $headers['Return-Path'] = $site_mail; - // Headers are usually encoded in the mail plugin that implements - // \Drupal\Core\Mail\MailInterface::mail(), for example, - // \Drupal\Core\Mail\Plugin\Mail\PhpMail::mail(). The site name must be - // encoded here to prevent mail plugins from encoding the email address, - // which would break the header. - $headers['From'] = Unicode::mimeHeaderEncode($site_config->get('name'), TRUE) . ' <' . $site_mail . '>'; + // Make sure the site-name is a RFC-2822 compliant 'display-name'. + $headers['From'] = MailHelper::formatDisplayName($site_config->get('name')) . ' <' . $site_mail . '>'; if ($reply) { $headers['Reply-to'] = $reply; } @@ -275,6 +276,13 @@ // Retrieve the responsible implementation for this message. $system = $this->getInstance(['module' => $module, 'key' => $key]); + // Attempt to convert relative URLs to absolute. + foreach ($message['body'] as &$body_part) { + if ($body_part instanceof MarkupInterface) { + $body_part = Markup::create(Html::transformRootRelativeUrlsToAbsolute((string) $body_part, \Drupal::request()->getSchemeAndHttpHost())); + } + } + // Format the message body. $message = $system->format($message); @@ -303,7 +311,7 @@ '%to' => $message['to'], '%reply' => $message['reply-to'] ? $message['reply-to'] : $this->t('not set'), ]); - drupal_set_message($this->t('Unable to send email. Contact the site administrator if the problem persists.'), 'error'); + $this->messenger()->addError($this->t('Unable to send email. Contact the site administrator if the problem persists.')); } } }