private function SWIFTMailSystem::getApplicableCharset in Swift Mailer 7
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 SWIFTMailSystem::getApplicableCharset()
- SWIFTMailSystem::mail in includes/
classes/ SWIFTMailSystem.inc - Sends a message composed by drupal_mail().
File
- includes/
classes/ SWIFTMailSystem.inc, line 521 - The implementation of MailSystemInterface which delegates handling of e-mails to the Swift Mailer library.
Class
- SWIFTMailSystem
- @file The implementation of MailSystemInterface which delegates handling of e-mails to the Swift Mailer library.
Code
private function getApplicableCharset($message) {
// Get the configured default format.
$default_charset = variable_get('swiftmailer_character_set', SWIFTMAILER_VARIABLE_CHARACTER_SET_DEFAULT);
// Get whether the provided format is to be respected.
$respect_charset = variable_get('swiftmailer_respect_format', SWIFTMAILER_VARIABLE_RESPECT_FORMAT_DEFAULT);
// 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;
}