Upgrade mail configuration (#455)

* Upgrade the mail configuration

* Update mail configuration to match Laravel 12

* Update mail configuration to properly set none or null

* Pint code

* Upgrade Symfony Mailers
This commit is contained in:
Darko Gjorgjijoski
2025-08-31 03:04:31 +02:00
committed by GitHub
parent d1bca362de
commit bae8dbe083
10 changed files with 233 additions and 53 deletions

View File

@@ -26,7 +26,7 @@ class EnvironmentManager
/**
* Set the .env and .env.example paths.
*/
public function __construct()
public function __construct($path = null)
{
$this->envPath = base_path('.env');
}
@@ -64,7 +64,7 @@ class EnvironmentManager
// Check if new or old key
if ($entry[0] == $data_key) {
$env[$env_key] = $data_key.'='.$this->encode($data_value);
$env[$env_key] = sprintf('%s=%s', $data_key, $this->encode($data_value));
$updated = true;
}
}
@@ -89,8 +89,25 @@ class EnvironmentManager
*/
private function encode($str)
{
// Convert to string if not already
$str = (string) $str;
if ((strpos($str, ' ') !== false || preg_match('/'.preg_quote('^\'£$%^&*()}{@#~?><,@|-=-_+-¬', '/').'/', $str)) && ($str[0] != '"' || $str[strlen($str) - 1] != '"')) {
// If the value is already properly quoted, return as is
if (strlen($str) >= 2 && $str[0] === '"' && $str[strlen($str) - 1] === '"') {
return $str;
}
// Check if the value contains characters that need quoting
// Using a character class regex to properly match special characters
$specialChars = '\^\'£$%&*()}{@#~?><,|=\-_+¬!';
$needsQuoting = (
strpos($str, ' ') !== false ||
preg_match('/['.preg_quote($specialChars, '/').']/', $str)
);
if ($needsQuoting) {
// Escape any existing double quotes in the string
$str = str_replace('"', '\\"', $str);
$str = '"'.$str.'"';
}
@@ -314,12 +331,12 @@ class EnvironmentManager
case 'smtp':
$mailEnv = [
'MAIL_DRIVER' => $request->get('mail_driver'),
'MAIL_MAILER' => $request->get('mail_driver'),
'MAIL_HOST' => $request->get('mail_host'),
'MAIL_PORT' => $request->get('mail_port'),
'MAIL_USERNAME' => $request->get('mail_username'),
'MAIL_PASSWORD' => $request->get('mail_password'),
'MAIL_ENCRYPTION' => $request->get('mail_encryption') !== 'none' ? $request->get('mail_encryption') : 'null',
'MAIL_SCHEME' => $request->get('mail_encryption') !== 'none' ? $request->get('mail_encryption') : 'null',
'MAIL_FROM_ADDRESS' => $request->get('from_mail'),
'MAIL_FROM_NAME' => $request->get('from_name'),
];
@@ -329,12 +346,11 @@ class EnvironmentManager
case 'mailgun':
$mailEnv = [
'MAIL_DRIVER' => $request->get('mail_driver'),
'MAIL_MAILER' => $request->get('mail_driver'),
'MAIL_HOST' => $request->get('mail_host'),
'MAIL_PORT' => $request->get('mail_port'),
'MAIL_USERNAME' => config('mail.username'),
'MAIL_PASSWORD' => config('mail.password'),
'MAIL_ENCRYPTION' => $request->get('mail_encryption'),
'MAIL_FROM_ADDRESS' => $request->get('from_mail'),
'MAIL_FROM_NAME' => $request->get('from_name'),
'MAILGUN_DOMAIN' => $request->get('mail_mailgun_domain'),
@@ -347,7 +363,7 @@ class EnvironmentManager
case 'ses':
$mailEnv = [
'MAIL_DRIVER' => $request->get('mail_driver'),
'MAIL_MAILER' => $request->get('mail_driver'),
'MAIL_HOST' => $request->get('mail_host'),
'MAIL_PORT' => $request->get('mail_port'),
'MAIL_USERNAME' => config('mail.username'),
@@ -366,7 +382,7 @@ class EnvironmentManager
case 'mail':
$mailEnv = [
'MAIL_DRIVER' => $request->get('mail_driver'),
'MAIL_MAILER' => $request->get('mail_driver'),
'MAIL_HOST' => config('mail.host'),
'MAIL_PORT' => config('mail.port'),
'MAIL_USERNAME' => config('mail.username'),