You are here

protected function BodyAnalyzer::analyzeBody in Mailhandler 8

Analyzes the message body and updates it.

Parameters

\Drupal\inmail\MIME\MimeMessageInterface $message: A mail message to be analyzed.

\Drupal\inmail\DefaultAnalyzerResult $result: The analyzer result.

1 call to BodyAnalyzer::analyzeBody()
BodyAnalyzer::analyze in src/Plugin/inmail/Analyzer/BodyAnalyzer.php

File

src/Plugin/inmail/Analyzer/BodyAnalyzer.php, line 45

Class

BodyAnalyzer
A message body analyzer.

Namespace

Drupal\mailhandler\Plugin\inmail\Analyzer

Code

protected function analyzeBody(MimeMessageInterface $message, DefaultAnalyzerResult $result) {

  // Get the processed body if available. Otherwise, fallback to default one.
  $body = $result
    ->getBody() ?: $message
    ->getBody();

  // Remove the empty spaces from the beginning and from the end of message.
  $body = trim($body);

  // Add HTML line breaks before all newlines if body doesn't contain tags.
  if ($body == strip_tags($body)) {
    $body = nl2br($body);
  }

  // Update the processed body.
  $result
    ->setBody($body);
}