You are here

private function SwiftMailer::getApplicableCharset in Swift Mailer 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/Mail/SwiftMailer.php \Drupal\swiftmailer\Plugin\Mail\SwiftMailer::getApplicableCharset()

Returns the applicable charset.

Parameters

array $message: The message for which the applicable charset is to be determined.

Return value

string A string being the applicable charset.

1 call to SwiftMailer::getApplicableCharset()
SwiftMailer::mail in src/Plugin/Mail/SwiftMailer.php
Sends a message composed by drupal_mail().

File

src/Plugin/Mail/SwiftMailer.php, line 496

Class

SwiftMailer
Provides a 'Swift Mailer' plugin to send emails.

Namespace

Drupal\swiftmailer\Plugin\Mail

Code

private function getApplicableCharset($message) {

  // Get the configured default format.
  $default_charset = $this->config['message']['character_set'];

  // Get whether the provided format is to be respected.
  $respect_charset = $this->config['message']['respect_format'];

  // Check if a format has been provided particularly for this message. If
  // that is the case, then apply that format instead of the default format.
  $applicable_charset = !empty($message['params']['charset']) ? $message['params']['charset'] : $default_charset;

  // Check if the provided format is to be respected, and if a format has been
  // set through the header "Content-Type". If that is the case, the apply the
  // format provided. This will override any format which may have been set
  // through $message['params']['format'].
  if ($respect_charset && !empty($message['headers']['Content-Type'])) {
    $format = $message['headers']['Content-Type'];
    $format = preg_match('/charset.*=.*\\;/U', $format, $matches);
    if ($format > 0) {
      $applicable_charset = trim(substr($matches[0], 0, -1));
      $applicable_charset = preg_replace('/charset=/', '', $applicable_charset);
    }
    else {
      $applicable_charset = $default_charset;
    }
  }
  return $applicable_charset;
}