Skip to content
Snippets Groups Projects

Issue #3130107: Extend unit test coverage for LanguageNegotiationContentEntity

Open Stefanos Petrakis requested to merge issue/drupal-3130107:3130107-add-unit-test into 10.1.x
6 files
+ 222
15
Compare changes
  • Side-by-side
  • Inline
Files
6
  • f60143fd
    Issue #3226117 by MegaChriz, marthinal, longwave, sinn, dcam, ankithashetty,... · f60143fd
    Lee Rowlands authored
    Issue #3226117 by MegaChriz, marthinal, longwave, sinn, dcam, ankithashetty, itaran, catch: Uncaught RfcComplianceException when email From name contains a comma
@@ -33,11 +33,19 @@ class PhpMail implements MailInterface {
*/
protected $configFactory;
/**
* The currently active request object.
*
* @var \Symfony\Component\HttpFoundation\Request
*/
protected $request;
/**
* PhpMail constructor.
*/
public function __construct() {
$this->configFactory = \Drupal::configFactory();
$this->request = \Drupal::request();
}
/**
@@ -87,7 +95,9 @@ public function mail(array $message) {
$headers = new Headers();
foreach ($message['headers'] as $name => $value) {
if (in_array(strtolower($name), self::MAILBOX_LIST_HEADERS, TRUE)) {
$value = explode(',', $value);
// Split values by comma, but ignore commas encapsulated in double
// quotes.
$value = str_getcsv($value, ',');
}
$headers->addHeader($name, $value);
}
@@ -104,12 +114,7 @@ public function mail(array $message) {
$mail_headers = str_replace("\r\n", "\n", $headers->toString());
$mail_subject = str_replace("\r\n", "\n", $mail_subject);
$request = \Drupal::request();
// We suppress warnings and notices from mail() because of issues on some
// hosts. The return value of this method will still indicate whether mail
// was sent successfully.
if (!$request->server->has('WINDIR') && strpos($request->server->get('SERVER_SOFTWARE'), 'Win32') === FALSE) {
if (!$this->request->server->has('WINDIR') && !str_contains($this->request->server->get('SERVER_SOFTWARE'), 'Win32')) {
// On most non-Windows systems, the "-f" option to the sendmail command
// is used to set the Return-Path. There is no space between -f and
// the value of the return path.
@@ -117,7 +122,7 @@ public function mail(array $message) {
// we assume to be safe.
$site_mail = $this->configFactory->get('system.site')->get('mail');
$additional_headers = isset($message['Return-Path']) && ($site_mail === $message['Return-Path'] || static::_isShellSafe($message['Return-Path'])) ? '-f' . $message['Return-Path'] : '';
$mail_result = @mail(
$mail_result = $this->doMail(
$message['to'],
$mail_subject,
$mail_body,
@@ -130,7 +135,7 @@ public function mail(array $message) {
// Return-Path header.
$old_from = ini_get('sendmail_from');
ini_set('sendmail_from', $message['Return-Path']);
$mail_result = @mail(
$mail_result = $this->doMail(
$message['to'],
$mail_subject,
$mail_body,
@@ -142,6 +147,36 @@ public function mail(array $message) {
return $mail_result;
}
/**
* Wrapper around PHP's mail() function.
*
* We suppress warnings and notices from mail() because of issues on some
* hosts. The return value of this method will still indicate whether mail was
* sent successfully.
*
* @param string $to
* Receiver, or receivers of the mail.
* @param string $subject
* Subject of the email to be sent.
* @param string $message
* Message to be sent.
* @param array|string $additional_headers
* (optional) String or array to be inserted at the end of the email header.
* @param string $additional_params
* (optional) Can be used to pass additional flags as command line options.
*
* @see mail()
*/
protected function doMail(string $to, string $subject, string $message, array|string $additional_headers = [], string $additional_params = ''): bool {
return @mail(
$to,
$subject,
$message,
$additional_headers,
$additional_params
);
}
/**
* Disallows potentially unsafe shell characters.
*
Loading