diff --git a/config/install/swiftmailer.message.yml b/config/install/swiftmailer.message.yml index fa86216..20a47be 100644 --- a/config/install/swiftmailer.message.yml +++ b/config/install/swiftmailer.message.yml @@ -1,4 +1,5 @@ format: text/plain +filter_format: plain_text respect_format: true convert_mode: false character_set: UTF-8 diff --git a/config/schema/swiftmailer.schema.yml b/config/schema/swiftmailer.schema.yml index bbfa947..5235b9f 100644 --- a/config/schema/swiftmailer.schema.yml +++ b/config/schema/swiftmailer.schema.yml @@ -5,6 +5,9 @@ swiftmailer.message: format: type: string label: 'Message format' + filter_format: + type: string + label: 'Filter format' respect_format: type: boolean label: 'Respect format' diff --git a/src/Plugin/Mail/SwiftMailer.php b/src/Plugin/Mail/SwiftMailer.php index eeda5c1..727a667 100644 --- a/src/Plugin/Mail/SwiftMailer.php +++ b/src/Plugin/Mail/SwiftMailer.php @@ -589,7 +589,8 @@ public function massageMessageBody(array $message) { // and then treat the result as safe markup. $line_endings = Settings::get('mail_line_endings', PHP_EOL); $applicable_format = $this->getApplicableFormat($message); - $message['body'] = Markup::create(implode($line_endings, array_map(function ($body) use ($applicable_format) { + $filter_format = $this->config['message']['filter_format']; + $message['body'] = Markup::create(implode($line_endings, array_map(function ($body) use ($applicable_format, $filter_format) { // If the body contains no html tags but the applicable format is HTML, // we can assume newlines will need be converted to
. if ($applicable_format == SWIFTMAILER_FORMAT_HTML && strlen(strip_tags($body)) === strlen($body)) { @@ -598,6 +599,7 @@ public function massageMessageBody(array $message) { $build = [ '#type' => 'processed_text', '#text' => $body, + '#format' => $filter_format, ]; $body = $this->renderer->renderPlain($build); } diff --git a/swiftmailer.install b/swiftmailer.install index 815138e..1a9b6ab 100644 --- a/swiftmailer.install +++ b/swiftmailer.install @@ -32,3 +32,12 @@ function swiftmailer_install() { 'sender' => 'swiftmailer', ])->save(); } + +/** + * Set default filter_format for HTML emails with no HTML markup. + */ +function swiftmailer_update_8400() { + Drupal::configFactory()->getEditable('swiftmailer.message') + ->set('filter_format', 'plain_text') + ->save(); +}