From f74037220aef37e5f05c6aa124d2d62ee80e51f2 Mon Sep 17 00:00:00 2001 From: codex Date: Sun, 8 Nov 2026 17:15:00 +0800 Subject: [PATCH] Standardize English email branding --- web/app/Command/Job.php | 5 +- web/app/Controllers/Admin/UserController.php | 9 +- web/app/Controllers/AuthController.php | 8 +- .../Services/AccountEmailChangeService.php | 2 +- web/app/Services/AccountSecurityService.php | 2 +- .../Services/Cloud/CloudInvoiceService.php | 9 +- .../CloudMaintenanceNoticeDeliveryService.php | 8 +- ...ServiceCompensationNotificationService.php | 27 ++++-- web/app/Services/Mail.php | 7 +- web/app/Services/Mail/Mailgun.php | 7 +- web/app/Services/Mail/Smtp.php | 3 +- web/app/Services/MailSenderIdentity.php | 55 ++++++++++++ web/app/Services/Password.php | 3 +- web/app/Services/SiteName.php | 12 +++ .../Ticket/TicketNotificationDispatcher.php | 16 ++-- web/config/.config.php.example | 2 +- web/resources/email/auth/verify.tpl | 16 ++-- web/resources/email/cloud/invoice.tpl | 18 ++-- .../email/cloud/maintenance-notice.tpl | 18 ++-- .../email/cloud/provision-success.tpl | 28 +++---- .../email/cloud/service-compensation.tpl | 22 ++--- web/resources/email/layout.tpl | 8 +- web/resources/email/news/backup.tpl | 12 +-- .../email/news/daily-traffic-report.tpl | 12 +-- web/resources/email/news/finance.tpl | 12 +-- web/resources/email/news/monitor.tpl | 12 +-- web/resources/email/news/nian.tpl | 18 ++-- web/resources/email/news/warn.tpl | 12 +-- web/resources/email/password/reset.tpl | 16 ++-- web/resources/email/test.tpl | 10 +-- web/resources/email/ticket/created.tpl | 12 +-- web/resources/email/ticket/replied.tpl | 12 +-- .../user-copy/entries/auth.entries.php | 2 - web/tests/CloudMailOutboxDispatchTest.php | 7 +- web/tests/MailDeliveryLogTest.php | 9 ++ web/tests/MailNotificationContractTest.php | 21 +++-- web/tests/MailSenderIdentityTest.php | 61 ++++++++++++++ web/tests/MailSubjectContractTest.php | 76 +++++++++++++++++ web/tests/MailTemplateRenderTest.php | 25 +++--- web/tests/MailgunSenderIdentityTest.php | 84 +++++++++++++++++++ web/tests/SiteNameDefaultTitleTest.php | 67 +++++++++++++++ web/tests/SmtpSingleConfigTest.php | 17 +++- web/tests/UserCopyManifestContractTest.php | 4 +- 43 files changed, 596 insertions(+), 190 deletions(-) create mode 100644 web/app/Services/MailSenderIdentity.php create mode 100644 web/tests/MailSenderIdentityTest.php create mode 100644 web/tests/MailSubjectContractTest.php create mode 100644 web/tests/MailgunSenderIdentityTest.php create mode 100644 web/tests/SiteNameDefaultTitleTest.php diff --git a/web/app/Command/Job.php b/web/app/Command/Job.php index c9db4ec6..7dd78d65 100644 --- a/web/app/Command/Job.php +++ b/web/app/Command/Job.php @@ -129,9 +129,10 @@ class Job } if (!Mail::send( $recipient, - Config::get('appName') . '-数据库备份', + 'Database Backup', 'news/backup.tpl', - ['text' => '数据库 SQL 备份已使用 AES-256 加密,请使用您配置的备份口令解压。'], + ['text' => 'The SQL database backup is encrypted with AES-256. ' + . 'Use the configured backup passphrase to extract it.'], [$archive] )) { throw new \RuntimeException('备份已保存,但邮件服务未接受备份邮件。'); diff --git a/web/app/Controllers/Admin/UserController.php b/web/app/Controllers/Admin/UserController.php index dd0797ae..61a74e04 100644 --- a/web/app/Controllers/Admin/UserController.php +++ b/web/app/Controllers/Admin/UserController.php @@ -5,7 +5,6 @@ namespace App\Controllers\Admin; use App\Services\Auth; use App\Services\AdminDataMasker; use App\Services\AdminPermission; -use App\Services\Config; use App\Services\Mail; use App\Services\LoginSessionRevocationService; use App\Services\RedisClient; @@ -66,8 +65,10 @@ class UserController extends AdminController if (!$user->save()) { return $this->echoJson($response, ['ret' => 0, 'msg' => '创建失败']); } - $sent = Mail::send($email, Config::get('appName') . ' - 新用户注册通知', 'news/monitor.tpl', [ - 'user' => $user, 'text' => '管理员为您创建了账户,邮箱:' . $email . ',初始密码:' . $password, + $sent = Mail::send($email, 'Account Created', 'news/monitor.tpl', [ + 'user' => $user, + 'text' => 'An administrator created your account. Email: ' . $email + . '. Initial password: ' . $password, ]); return $this->echoJson($response, [ @@ -198,7 +199,7 @@ class UserController extends AdminController if (AdminPermission::isSuperAdmin() && $user) { $to = $user->email; - $subject = Config::get('appName') . ' - ' . $subjectFromFrontEnd; + $subject = trim((string) $subjectFromFrontEnd); $text = $contentFromFrontEnd; try { $sent = Mail::send($to, $subject, 'news/monitor.tpl', [ diff --git a/web/app/Controllers/AuthController.php b/web/app/Controllers/AuthController.php index d17641bb..a6479f83 100644 --- a/web/app/Controllers/AuthController.php +++ b/web/app/Controllers/AuthController.php @@ -644,9 +644,7 @@ class AuthController extends BaseController } try { - $sent = Mail::send($email, $this->publicCopy('auth.login', 'auth.login.verify.subject', [ - 'site' => (string) Config::get('appName'), - ]), 'auth/verify.tpl', [ + $sent = Mail::send($email, 'Login Verification', 'auth/verify.tpl', [ "code" => $code, "expire" => date("Y-m-d H:i:s", time() + (int) CaptchaConfig::get('email_verify_ttl')), "language" => $this->language, @@ -769,9 +767,7 @@ class AuthController extends BaseController return $response->getBody()->write(json_encode($res)); } - $subject = $this->publicCopy('auth.register', 'auth.register.verify.subject', [ - 'site' => (string) Config::get('appName'), - ]); + $subject = 'Email Verification'; try { $sent = Mail::send($email, $subject, 'auth/verify.tpl', [ diff --git a/web/app/Services/AccountEmailChangeService.php b/web/app/Services/AccountEmailChangeService.php index b8654b01..2b6aecb9 100644 --- a/web/app/Services/AccountEmailChangeService.php +++ b/web/app/Services/AccountEmailChangeService.php @@ -77,7 +77,7 @@ final class AccountEmailChangeService try { $sent = Mail::send( $newEmail, - Config::get('appName') . ' - 修改邮箱验证', + 'Email Change Verification', 'auth/verify.tpl', [ 'code' => $plainCode, diff --git a/web/app/Services/AccountSecurityService.php b/web/app/Services/AccountSecurityService.php index 9444627c..e3af8815 100644 --- a/web/app/Services/AccountSecurityService.php +++ b/web/app/Services/AccountSecurityService.php @@ -64,7 +64,7 @@ class AccountSecurityService try { $sent = Mail::send( $email, - Config::get('appName') . ' - 修改密码验证', + 'Password Change Verification', 'auth/verify.tpl', [ 'code' => $plainCode, diff --git a/web/app/Services/Cloud/CloudInvoiceService.php b/web/app/Services/Cloud/CloudInvoiceService.php index e191b9d8..be019284 100644 --- a/web/app/Services/Cloud/CloudInvoiceService.php +++ b/web/app/Services/Cloud/CloudInvoiceService.php @@ -807,10 +807,9 @@ final class CloudInvoiceService $error = '用户邮箱无效'; } else { $base = rtrim((string) Config::get('baseUrl', ''), '/'); - $appName = trim((string) Config::get('appName', '')); if ($kind === 'renewal_due') { $ok = Mail::send((string) $user->email, - ($appName !== '' ? $appName . ' - ' : '') . '实例续费账单已生成', + 'Renewal Invoice Created', 'cloud/invoice.tpl', [ 'invoice_id' => (string) $invoice->id, 'instance_name' => (string) $instance->name, @@ -845,20 +844,20 @@ final class CloudInvoiceService ?? $spec['template_id'] ?? '')); $loginName = trim((string) ($spec['login_name'] ?? '')); $ok = Mail::send((string) $user->email, - ($appName !== '' ? $appName . ' - ' : '') . '实例开通成功', + 'Instance Provisioned', 'cloud/provision-success.tpl', [ 'instance_name' => (string) $instance->name, 'instance_id' => (string) $instance->id, 'region' => $region !== '' ? $region : '—', 'public_ip' => $ip, - 'os_name' => $osName !== '' ? $osName : '云镜像系统', + 'os_name' => $osName !== '' ? $osName : 'Cloud image', 'login_name' => preg_match( '/^[A-Za-z_][A-Za-z0-9_.-]{0,31}$/D', $loginName ) === 1 ? $loginName : 'root', 'created_at' => date('Y-m-d H:i:s', (int) $instance->created_at), 'expires_at' => $instance->expires_at === null - ? '未设置' : date('Y-m-d H:i:s', + ? 'Not set' : date('Y-m-d H:i:s', (int) $instance->expires_at), 'instance_url' => $base . '/user/cloud/instances/' . (int) $instance->id, diff --git a/web/app/Services/Cloud/CloudMaintenanceNoticeDeliveryService.php b/web/app/Services/Cloud/CloudMaintenanceNoticeDeliveryService.php index 65702524..9b641397 100644 --- a/web/app/Services/Cloud/CloudMaintenanceNoticeDeliveryService.php +++ b/web/app/Services/Cloud/CloudMaintenanceNoticeDeliveryService.php @@ -207,10 +207,10 @@ final class CloudMaintenanceNoticeDeliveryService throw new \RuntimeException('Maintenance instance list is empty.'); } $impacts = [ - 'network_interruption' => '网络可能短时中断', - 'instance_restart' => '实例将重新启动', - 'service_interruption' => '服务可能短时中断', - 'no_interruption' => '预计不会中断服务', + 'network_interruption' => 'Network connectivity may be briefly interrupted', + 'instance_restart' => 'Instances will be restarted', + 'service_interruption' => 'Service may be briefly interrupted', + 'no_interruption' => 'No service interruption is expected', ]; $impact = $impacts[(string) $notice->impact] ?? null; if ($impact === null) { diff --git a/web/app/Services/Cloud/CloudServiceCompensationNotificationService.php b/web/app/Services/Cloud/CloudServiceCompensationNotificationService.php index 79e6481d..380cac28 100644 --- a/web/app/Services/Cloud/CloudServiceCompensationNotificationService.php +++ b/web/app/Services/Cloud/CloudServiceCompensationNotificationService.php @@ -330,10 +330,12 @@ final class CloudServiceCompensationNotificationService throw new \RuntimeException('Compensation payload is invalid.'); } return [ - 'subject' => '实例可用时间补偿已到账', + 'subject' => 'Service Time Compensation Applied', 'variables' => [ 'reason_text' => $payload['reason_text'], - 'scope_label' => (string) ($payload['scope_label'] ?? ''), + 'scope_label' => self::scopeLabel( + (string) ($payload['scope_label'] ?? '') + ), 'compensation_duration' => self::duration( $payload['compensation_seconds'] ), @@ -416,15 +418,26 @@ final class CloudServiceCompensationNotificationService private static function duration(int $seconds): string { if ($seconds % 86400 === 0) { - return (int) ($seconds / 86400) . ' 天'; + $value = (int) ($seconds / 86400); + return $value . ($value === 1 ? ' day' : ' days'); } if ($seconds % 3600 === 0) { - return (int) ($seconds / 3600) . ' 小时'; + $value = (int) ($seconds / 3600); + return $value . ($value === 1 ? ' hour' : ' hours'); } if ($seconds % 60 === 0) { - return (int) ($seconds / 60) . ' 分钟'; + $value = (int) ($seconds / 60); + return $value . ($value === 1 ? ' minute' : ' minutes'); + } + return $seconds . ($seconds === 1 ? ' second' : ' seconds'); + } + + private static function scopeLabel(string $label): string + { + if (preg_match('/^单实例\s*#(\d+)$/u', $label, $matches) === 1) { + return 'Instance #' . $matches[1]; } - return $seconds . ' 秒'; + return $label; } private static function incidentWindow(array $payload): string @@ -432,7 +445,7 @@ final class CloudServiceCompensationNotificationService $start = $payload['incident_starts_at'] ?? null; $end = $payload['incident_ends_at'] ?? null; if (!is_int($start) || !is_int($end)) { - return '未单独记录'; + return 'Not recorded separately'; } return gmdate('Y-m-d H:i:s \U\T\C', $start) . ' — ' . gmdate('Y-m-d H:i:s \U\T\C', $end); diff --git a/web/app/Services/Mail.php b/web/app/Services/Mail.php index e0eb25d6..f7bd94cb 100644 --- a/web/app/Services/Mail.php +++ b/web/app/Services/Mail.php @@ -45,8 +45,11 @@ class Mail $smarty->settemplatedir(BASE_PATH . '/resources/email/'); $smarty->setcompiledir(BASE_PATH . '/storage/framework/smarty/compile/'); $smarty->setcachedir(BASE_PATH . '/storage/framework/smarty/cache/'); - // add config - $smarty->assign('config', Config::getPublicConfig()); + // Mail branding is global. It must use the administrator-managed + // default title instead of a request-domain-specific site mapping. + $publicConfig = Config::getPublicConfig(); + $publicConfig['appName'] = MailSenderIdentity::displayName(); + $smarty->assign('config', $publicConfig); foreach ($ary as $key => $value) { $smarty->assign($key, $value); } diff --git a/web/app/Services/Mail/Mailgun.php b/web/app/Services/Mail/Mailgun.php index 6f0cf23d..d4f33173 100644 --- a/web/app/Services/Mail/Mailgun.php +++ b/web/app/Services/Mail/Mailgun.php @@ -3,6 +3,7 @@ namespace App\Services\Mail; use App\Services\Config; +use App\Services\MailSenderIdentity; use GuzzleHttp\Client as GuzzleClient; use GuzzleHttp\Psr7\HttpFactory; use Mailgun\HttpClient\HttpClientConfigurator; @@ -24,7 +25,11 @@ class Mailgun extends Base $this->validateConfig(); $this->mg = $this->createClient(); $this->domain = $this->config["domain"]; - $this->sender = $this->config["sender"]; + try { + $this->sender = MailSenderIdentity::header($this->config["sender"]); + } catch (\InvalidArgumentException $exception) { + throw new RuntimeException('Mailgun configuration mailgun_sender must contain a valid email address.', 0, $exception); + } } public function getConfig() diff --git a/web/app/Services/Mail/Smtp.php b/web/app/Services/Mail/Smtp.php index e3275826..b37f3842 100644 --- a/web/app/Services/Mail/Smtp.php +++ b/web/app/Services/Mail/Smtp.php @@ -4,6 +4,7 @@ namespace App\Services\Mail; use App\Services\Config; +use App\Services\MailSenderIdentity; use PHPMailer\PHPMailer\PHPMailer; class Smtp extends Base @@ -15,7 +16,7 @@ class Smtp extends Base "username" => Config::get('smtp_username'), "port" => Config::get('smtp_port'), "sender" => Config::get('smtp_sender'), - "name" => Config::get('smtp_name'), + "name" => MailSenderIdentity::displayName(), "passsword" => Config::get('smtp_passsword') ]; } diff --git a/web/app/Services/MailSenderIdentity.php b/web/app/Services/MailSenderIdentity.php new file mode 100644 index 00000000..4f1a7a5e --- /dev/null +++ b/web/app/Services/MailSenderIdentity.php @@ -0,0 +1,55 @@ +]+)\s*>\s*$/D', $sender, $matches) === 1) { + $sender = trim($matches[1]); + } + + if (filter_var($sender, FILTER_VALIDATE_EMAIL) === false) { + throw new InvalidArgumentException('The configured sender must contain a valid email address.'); + } + + return $sender; + } + + public static function header($configuredSender): string + { + $displayName = addcslashes(self::displayName(), "\\\""); + + return '"' . $displayName . '" <' . self::mailbox($configuredSender) . '>'; + } + + public static function sanitizeDisplayName($name): string + { + $name = str_replace(["\r", "\n"], ' ', (string) $name); + $name = preg_replace('/[\x00-\x1F\x7F]+/', ' ', $name); + $name = preg_replace('/\s+/', ' ', (string) $name); + $name = trim((string) $name); + + if ($name === '') { + return self::FALLBACK_NAME; + } + + if (function_exists('mb_substr')) { + return (string) mb_substr($name, 0, self::MAX_DISPLAY_NAME_LENGTH, 'UTF-8'); + } + + return substr($name, 0, self::MAX_DISPLAY_NAME_LENGTH); + } +} diff --git a/web/app/Services/Password.php b/web/app/Services/Password.php index 89720647..6ab97e81 100644 --- a/web/app/Services/Password.php +++ b/web/app/Services/Password.php @@ -28,8 +28,7 @@ class Password return false; } - $subject = Config::get('appName') . ($english - ? ' - Password reset' : ' - 重置密码'); + $subject = 'Password Reset'; $resetUrl = Config::get('baseUrl') . "/password/token/" . $pwdRst->token; try { $sent = Mail::send($email, $subject, 'password/reset.tpl', [ diff --git a/web/app/Services/SiteName.php b/web/app/Services/SiteName.php index 8095ea54..e0283b50 100644 --- a/web/app/Services/SiteName.php +++ b/web/app/Services/SiteName.php @@ -24,6 +24,18 @@ class SiteName return self::resolveFromConfig($host, $defaultName, $mappings ?? []); } + /** + * Return the administrator-managed default site title without applying a + * request-host mapping. Mail and other global identities must not vary by + * the domain that happened to trigger a background operation. + */ + public static function defaultName(): string + { + $name = trim(self::defaultAppName()); + + return $name !== '' ? $name : 'Site'; + } + public static function resolveFromConfig($host, $defaultName, array $mappings): string { $requestHost = self::normalizeHost($host); diff --git a/web/app/Services/Ticket/TicketNotificationDispatcher.php b/web/app/Services/Ticket/TicketNotificationDispatcher.php index 3bef8e79..5aa00a73 100644 --- a/web/app/Services/Ticket/TicketNotificationDispatcher.php +++ b/web/app/Services/Ticket/TicketNotificationDispatcher.php @@ -25,15 +25,14 @@ final class TicketNotificationDispatcher $root = $event->result->root; $owner = User::where('id', (int) $root->userid)->first(); $jobs = []; - $appName = (string) Config::get('appName'); $ticketUrl = rtrim((string) Config::get('baseUrl'), '/') . '/user/ticket/' . (int) $root->id . '/view'; if ($event->kind === 'created' && $owner !== null && trim((string) $owner->email) !== '') { - $jobs[] = ['mail:owner', function () use ($owner, $root, $ticketUrl, $appName): void { + $jobs[] = ['mail:owner', function () use ($owner, $root, $ticketUrl): void { $this->transport->sendMail( (string) $owner->email, - $appName . ' - 工单已创建', + 'Ticket Created', 'ticket/created.tpl', ['user' => $owner, 'ticket' => $root, 'ticket_url' => $ticketUrl], 'ticket_created' @@ -46,14 +45,15 @@ final class TicketNotificationDispatcher if (trim((string) $admin->email) === '') { continue; } - $jobs[] = ['mail:admin:' . (int) $admin->id, function () use ($admin, $root, $appName): void { + $jobs[] = ['mail:admin:' . (int) $admin->id, function () use ($admin, $root): void { $this->transport->sendMail( (string) $admin->email, - $appName . ' - ' . (string) $root->title, + 'New Ticket: ' . (string) $root->title, 'news/warn.tpl', [ 'user' => $admin, - 'text' => '工单 #' . (int) $root->id . ' 有新的消息,请在网站管理页面查看。', + 'text' => 'Ticket #' . (int) $root->id + . ' has a new message. Open the admin panel to review it.', ] ); }]; @@ -64,10 +64,10 @@ final class TicketNotificationDispatcher } if ($event->kind === 'admin_reply' && $owner !== null && trim((string) $owner->email) !== '') { - $jobs[] = ['mail:owner', function () use ($owner, $root, $ticketUrl, $appName): void { + $jobs[] = ['mail:owner', function () use ($owner, $root, $ticketUrl): void { $this->transport->sendMail( (string) $owner->email, - $appName . ' - 工单收到回复', + 'Ticket Reply Received', 'ticket/replied.tpl', ['user' => $owner, 'ticket' => $root, 'ticket_url' => $ticketUrl], 'ticket_replied' diff --git a/web/config/.config.php.example b/web/config/.config.php.example index 44b4e3fe..25a72cc5 100644 --- a/web/config/.config.php.example +++ b/web/config/.config.php.example @@ -9,7 +9,7 @@ $System_Config['mailgun_sender'] = ''; $System_Config['smtp_host'] = ''; $System_Config['smtp_username'] = ''; $System_Config['smtp_port'] = ''; -$System_Config['smtp_name'] = ''; +# The sender display name comes from Site Settings -> Default title. $System_Config['smtp_sender'] = ''; $System_Config['smtp_passsword'] = ''; $System_Config['smtp_ssl'] = 'true'; diff --git a/web/resources/email/auth/verify.tpl b/web/resources/email/auth/verify.tpl index 8732c49e..6acd09e5 100644 --- a/web/resources/email/auth/verify.tpl +++ b/web/resources/email/auth/verify.tpl @@ -1,31 +1,29 @@ {extends file='layout.tpl'} -{block name='email_title'} - {if $language == 'true'}{if !empty($scene) && $scene == 'login'}Login verification{elseif !empty($scene) && $scene == 'password_change'}Password change verification{elseif !empty($scene) && $scene == 'email_change'}Email change verification{else}Email verification{/if} | {$config["appName"]|escape:"html"}{else}{if !empty($scene) && $scene == 'login'}登录安全验证{elseif !empty($scene) && $scene == 'password_change'}修改密码验证{elseif !empty($scene) && $scene == 'email_change'}修改邮箱验证{else}注册邮箱验证{/if} | {$config["appName"]|escape:"html"}{/if} -{/block} -{block name='preheader'}{if $language == 'true'}Your verification code is {$code|escape:"html"}.{else}您的验证码是 {$code|escape:"html"}。{/if}{/block} +{block name='email_title'}{if !empty($scene) && $scene == 'login'}Login verification{elseif !empty($scene) && $scene == 'password_change'}Password change verification{elseif !empty($scene) && $scene == 'email_change'}Email change verification{else}Email verification{/if}{/block} +{block name='preheader'}Your verification code is {$code|escape:"html"}.{/block} {block name='content'}

{if !empty($scene) && $scene == 'login'}ACCOUNT SECURITY{elseif !empty($scene) && $scene == 'registration'}WELCOME TO THE CLOUD{elseif !empty($scene) && ($scene == 'password_change' || $scene == 'email_change')}ACCOUNT SECURITY{else}EMAIL VERIFICATION{/if}

- {if $language == 'true'}{if !empty($scene) && $scene == 'login'}Confirm your sign-in{elseif !empty($scene) && $scene == 'password_change'}Confirm your password change{elseif !empty($scene) && $scene == 'email_change'}Confirm your email change{else}Verify your email address{/if}{else}{if !empty($scene) && $scene == 'login'}确认本次登录{elseif !empty($scene) && $scene == 'password_change'}确认修改密码{elseif !empty($scene) && $scene == 'email_change'}确认修改邮箱{else}验证您的注册邮箱{/if}{/if} + {if !empty($scene) && $scene == 'login'}Confirm your sign-in{elseif !empty($scene) && $scene == 'password_change'}Confirm your password change{elseif !empty($scene) && $scene == 'email_change'}Confirm your email change{else}Verify your email address{/if}

- {if $language == 'true'}{if !empty($scene) && $scene == 'login'}Enter the code below to complete the security check for your sign-in.{elseif !empty($scene) && $scene == 'password_change'}Enter the code below on the account page to confirm your password change.{elseif !empty($scene) && $scene == 'email_change'}Enter the code below in account settings to verify this new email address before using it to sign in.{else}Enter the code below on the registration page to finish creating your account.{/if}{else}{if !empty($scene) && $scene == 'login'}请在登录页面输入下方验证码,完成本次安全验证。{elseif !empty($scene) && $scene == 'password_change'}请在账户设置页面输入下方验证码,确认修改密码。{elseif !empty($scene) && $scene == 'email_change'}请在账户设置中输入下方验证码,验证此新邮箱后再将其设为登录邮箱。{else}请在注册页面输入下方验证码,完成邮箱验证并继续创建账户。{/if}{/if} + {if !empty($scene) && $scene == 'login'}Enter the code below to complete the security check for your sign-in.{elseif !empty($scene) && $scene == 'password_change'}Enter the code below on the account page to confirm your password change.{elseif !empty($scene) && $scene == 'email_change'}Enter the code below in account settings to verify this new email address before using it to sign in.{else}Enter the code below on the registration page to finish creating your account.{/if}

-

{if $language == 'true'}Never share this code with anyone. If you did not request it, you can safely ignore this email.{else}请勿向任何人泄露此验证码。如果并非您本人操作,可以安全地忽略此邮件。{/if}

+

Never share this code with anyone. If you did not request it, you can safely ignore this email.

{/block} diff --git a/web/resources/email/cloud/invoice.tpl b/web/resources/email/cloud/invoice.tpl index 8ae14eba..dc9952da 100644 --- a/web/resources/email/cloud/invoice.tpl +++ b/web/resources/email/cloud/invoice.tpl @@ -1,22 +1,22 @@ {extends file='layout.tpl'} -{block name='email_title'}续费账单已生成 | {$config["appName"]|escape:"html"}{/block} -{block name='preheader'}实例 {$instance_name|escape:"html"} 的续费账单已生成,最晚可在 {$payment_deadline_at|escape:"html"} 前支付。{/block} +{block name='email_title'}Renewal invoice created{/block} +{block name='preheader'}The renewal invoice for {$instance_name|escape:"html"} is ready. Payment is available until {$payment_deadline_at|escape:"html"}.{/block} {block name='content'}

SERVICE RENEWAL

-

续费账单已生成

-

您的云服务器 {$instance_name|escape:"html"} 将于 {$due_at|escape:"html"} 到期。到期后网络会暂停,您仍可在 {$payment_deadline_at|escape:"html"} 前完成续费。

+

Renewal invoice created

+

Your cloud server {$instance_name|escape:"html"} expires at {$due_at|escape:"html"}. Network access will be suspended after expiry, but you can still renew it before {$payment_deadline_at|escape:"html"}.

- - - + + +
- + -
+
{/block} diff --git a/web/resources/email/cloud/maintenance-notice.tpl b/web/resources/email/cloud/maintenance-notice.tpl index b5baf0d9..f4ae6823 100644 --- a/web/resources/email/cloud/maintenance-notice.tpl +++ b/web/resources/email/cloud/maintenance-notice.tpl @@ -1,7 +1,7 @@ {extends file='layout.tpl'} -{block name='email_title'}{$notice_subject|escape:"html"} | {$config["appName"]|escape:"html"}{/block} -{block name='preheader'}{$scope_label|escape:"html"} 将进行维护,请查看受影响实例和 UTC 时间窗口。{/block} +{block name='email_title'}{$notice_subject|escape:"html"}{/block} +{block name='preheader'}Maintenance is scheduled for {$scope_label|escape:"html"}. Review the affected instances and UTC maintenance window.{/block} {block name='content'}

MAINTENANCE NOTICE

@@ -10,21 +10,21 @@ - - + + - - + +
-

受影响的实例

+

Affected instances

{foreach $instances as $instance} - +
{/foreach} -
+
{/block} diff --git a/web/resources/email/cloud/provision-success.tpl b/web/resources/email/cloud/provision-success.tpl index f5719ebd..bb896f88 100644 --- a/web/resources/email/cloud/provision-success.tpl +++ b/web/resources/email/cloud/provision-success.tpl @@ -1,31 +1,31 @@ {extends file='layout.tpl'} -{block name='email_title'}实例开通成功 | {$config["appName"]|escape:"html"}{/block} -{block name='preheader'}实例 {$instance_name|escape:"html"} 已创建完成,可以进入控制台管理。{/block} +{block name='email_title'}Instance provisioned{/block} +{block name='preheader'}Instance {$instance_name|escape:"html"} is ready to manage in the control panel.{/block} {block name='content'}

INSTANCE READY

-

实例已开通

-

您的云服务器 {$instance_name|escape:"html"} 已创建完成,现在可以进入控制台查看状态并进行管理。

+

Your instance is ready

+

Your cloud server {$instance_name|escape:"html"} has been created. You can now view its status and manage it in the control panel.

-
+
- - + + - - + + - - + + - +
- -

出于安全考虑,本邮件不会展示账户密码、私钥或其他登录凭据。请前往实例详情页面查看面板保存的信息。

+ +

For security, this email does not include account passwords, private keys, or other login credentials. Visit the instance details page to view information stored by the control panel.

{/block} diff --git a/web/resources/email/cloud/service-compensation.tpl b/web/resources/email/cloud/service-compensation.tpl index 38cb6b0f..b509238c 100644 --- a/web/resources/email/cloud/service-compensation.tpl +++ b/web/resources/email/cloud/service-compensation.tpl @@ -1,32 +1,32 @@ {extends file='layout.tpl'} -{block name='email_title'}实例可用时间补偿已到账 | {$config["appName"]|escape:"html"}{/block} -{block name='preheader'}受影响实例的服务到期时间已经延长,请查看补偿结果。{/block} +{block name='email_title'}Service time compensation applied{/block} +{block name='preheader'}The service expiry time of the affected instances has been extended. Review the compensation details.{/block} {block name='content'}

SERVICE CREDIT

-

实例可用时间补偿已到账

-

因以下事件受到影响的实例已完成服务时间补偿。本次操作不会产生账单,也不会改变账户余额或流量额度。

+

Service time compensation applied

+

Service time compensation has been applied to the instances affected by the event below. This action does not create an invoice or change your account balance or traffic allowance.

- - + + - +
事件时间(UTC){$incident_window_utc|escape:"html"}Incident window (UTC){$incident_window_utc|escape:"html"}
-

补偿原因

+

Compensation reason

{$reason_text|escape:"html"|nl2br}

-

已补偿的实例

+

Compensated instances

{foreach $instances as $instance} - +
{/foreach} -
+
{/block} diff --git a/web/resources/email/layout.tpl b/web/resources/email/layout.tpl index 46161c94..5361101d 100644 --- a/web/resources/email/layout.tpl +++ b/web/resources/email/layout.tpl @@ -1,5 +1,5 @@ - + @@ -87,10 +87,10 @@ -

{if !empty($language) && $language == 'true'}This is an automated message. Please do not reply.{else}此邮件由系统自动发送,请勿直接回复。{/if}

+

This is an automated message. Please do not reply.

- {if !empty($language) && $language == 'true'}Visit{else}访问{/if} {$config["appName"]|escape:"html"} - ·{if !empty($language) && $language == 'true'}Cloud control panel{else}云资源控制台{/if} + Visit {$config["appName"]|escape:"html"} + ·Cloud control panel

© 2026 {$config["appName"]|escape:"html"}. All rights reserved.

diff --git a/web/resources/email/news/backup.tpl b/web/resources/email/news/backup.tpl index 2d063e62..ca8daf24 100644 --- a/web/resources/email/news/backup.tpl +++ b/web/resources/email/news/backup.tpl @@ -1,16 +1,16 @@ {extends file='layout.tpl'} -{block name='email_title'}数据库备份已完成 | {$config["appName"]|escape:"html"}{/block} -{block name='preheader'}数据库备份已完成,备份文件随邮件发送。{/block} +{block name='email_title'}Database backup completed{/block} +{block name='preheader'}The database backup is complete and attached to this email.{/block} {block name='content'}

SYSTEM BACKUP

-

数据库备份已完成

-

系统已完成本次数据库备份,备份文件已作为附件随邮件发送。

+

Database backup completed

+

The database backup is complete. The backup file is attached to this email.

- +
-

请妥善保管备份附件及解密口令,不要将其转发给无关人员。

+

Keep the backup attachment and decryption passphrase secure. Do not forward them to unauthorized people.

{/block} diff --git a/web/resources/email/news/daily-traffic-report.tpl b/web/resources/email/news/daily-traffic-report.tpl index 8dbc4421..3b22a95a 100644 --- a/web/resources/email/news/daily-traffic-report.tpl +++ b/web/resources/email/news/daily-traffic-report.tpl @@ -1,17 +1,17 @@ {extends file='layout.tpl'} -{block name='email_title'}服务地址通知 | {$config["appName"]|escape:"html"}{/block} -{block name='preheader'}请使用最新的站点地址访问控制台。{/block} +{block name='email_title'}Service address notice{/block} +{block name='preheader'}Use the current site address to access the control panel.{/block} {block name='content'}

SERVICE NOTICE

-

服务地址通知

- {if !empty($user)}

您好,{$user->user_name|default:'用户'|escape:"html"}:

{/if} -

请通过下方站点地址访问服务,并注意核对浏览器地址栏,避免进入非官方页面。

+

Service address notice

+ {if !empty($user)}

Hello {$user->user_name|default:'User'|escape:"html"},

{/if} +

Use the site address below to access the service. Check the browser address bar carefully to avoid unofficial pages.

- + {/block} diff --git a/web/resources/email/news/finance.tpl b/web/resources/email/news/finance.tpl index 10fb3ad5..93f2a394 100644 --- a/web/resources/email/news/finance.tpl +++ b/web/resources/email/news/finance.tpl @@ -1,16 +1,16 @@ {extends file='layout.tpl'} -{block name='email_title'}{$title|default:'财务通知'|escape:"html"} | {$config["appName"]|escape:"html"}{/block} -{block name='preheader'}您有一条新的财务通知。{/block} +{block name='email_title'}{$title|default:'Billing notice'|escape:"html"}{/block} +{block name='preheader'}You have a new billing notice.{/block} {block name='content'}

BILLING NOTICE

-

{$title|default:'财务通知'|escape:"html"}

-

您好,{$user->user_name|default:'用户'|escape:"html"}:

+

{$title|default:'Billing notice'|escape:"html"}

+

Hello {$user->user_name|default:'User'|escape:"html"},

- +
- + {/block} diff --git a/web/resources/email/news/monitor.tpl b/web/resources/email/news/monitor.tpl index 04a55fec..05888664 100644 --- a/web/resources/email/news/monitor.tpl +++ b/web/resources/email/news/monitor.tpl @@ -1,16 +1,16 @@ {extends file='layout.tpl'} -{block name='email_title'}账户通知 | {$config["appName"]|escape:"html"}{/block} -{block name='preheader'}您有一条来自 {$config["appName"]|escape:"html"} 的账户通知。{/block} +{block name='email_title'}Account notice{/block} +{block name='preheader'}You have a new account notice from {$config["appName"]|escape:"html"}.{/block} {block name='content'}

ACCOUNT NOTICE

-

需要您的注意

-

您好,{$user->user_name|default:'用户'|escape:"html"}:

+

Account update

+

Hello {$user->user_name|default:'User'|escape:"html"},

- +
- + {/block} diff --git a/web/resources/email/news/nian.tpl b/web/resources/email/news/nian.tpl index 0acd370c..81f1d8f6 100644 --- a/web/resources/email/news/nian.tpl +++ b/web/resources/email/news/nian.tpl @@ -1,20 +1,20 @@ {extends file='layout.tpl'} -{block name='email_title'}新年专享优惠 | {$config["appName"]|escape:"html"}{/block} -{block name='preheader'}新年专享套餐优惠,登录控制台即可参与。{/block} +{block name='email_title'}New Year offer{/block} +{block name='preheader'}A New Year plan offer is available in the control panel.{/block} {block name='content'}

NEW YEAR OFFER

-

新年专享优惠

-

亲爱的用户,感谢您一直以来对 {$config["appName"]|escape:"html"} 的支持与信任。我们准备了新年专享套餐优惠,期待继续为您提供稳定的服务。

+

New Year offer

+

Thank you for your continued support and trust in {$config["appName"]|escape:"html"}. We have prepared a New Year plan offer and look forward to continuing to provide reliable service.

- - + +
-
+
- -

感谢您的支持。
{$config["appName"]|escape:"html"} 团队

+ +

Thank you for your support.
The {$config["appName"]|escape:"html"} team

{/block} diff --git a/web/resources/email/news/warn.tpl b/web/resources/email/news/warn.tpl index b537cff5..c19ab4b6 100644 --- a/web/resources/email/news/warn.tpl +++ b/web/resources/email/news/warn.tpl @@ -1,16 +1,16 @@ {extends file='layout.tpl'} -{block name='email_title'}重要提醒 | {$config["appName"]|escape:"html"}{/block} -{block name='preheader'}您有一条需要处理的重要提醒。{/block} +{block name='email_title'}Important notice{/block} +{block name='preheader'}You have an important notice that requires your attention.{/block} {block name='content'}

ACTION REQUIRED

-

需要您的注意

-

您好,{$user->user_name|default:'用户'|escape:"html"}:

+

Action required

+

Hello {$user->user_name|default:'User'|escape:"html"},

- +
- + {/block} diff --git a/web/resources/email/password/reset.tpl b/web/resources/email/password/reset.tpl index 18d5a000..0bcd93d1 100644 --- a/web/resources/email/password/reset.tpl +++ b/web/resources/email/password/reset.tpl @@ -1,21 +1,21 @@ {extends file='layout.tpl'} -{block name='email_title'}{if $language == 'true'}Reset your password{else}重置账户密码{/if} | {$config["appName"]|escape:"html"}{/block} -{block name='preheader'}{if $language == 'true'}Use the secure link in this email to reset your password.{else}请使用邮件中的安全链接重置账户密码。{/if}{/block} +{block name='email_title'}Reset your password{/block} +{block name='preheader'}Use the secure link in this email to reset your password.{/block} {block name='content'}

ACCOUNT SECURITY

-

{if $language == 'true'}Reset your password{else}重置账户密码{/if}

-

{if $language == 'true'}We received a request to reset the password for your {$config["appName"]|escape:"html"} account. Use the button below to continue.{else}我们收到了您为 {$config["appName"]|escape:"html"} 账户重置密码的请求,请点击下方按钮继续。{/if}

+

Reset your password

+

We received a request to reset the password for your {$config["appName"]|escape:"html"} account. Use the button below to continue.

- + {if !empty($expire)} -
+
{/if} -

{if $language == 'true'}If the button does not work, copy and paste this address into your browser:{else}如果按钮无法打开,请复制以下地址并粘贴到浏览器:{/if}

+

If the button does not work, copy and paste this address into your browser:

{$resetUrl|escape:"html"}

-
+
{/block} diff --git a/web/resources/email/test.tpl b/web/resources/email/test.tpl index 220904fb..0d81102f 100644 --- a/web/resources/email/test.tpl +++ b/web/resources/email/test.tpl @@ -1,11 +1,11 @@ {extends file='layout.tpl'} -{block name='email_title'}邮件服务测试 | {$config["appName"]|escape:"html"}{/block} -{block name='preheader'}这是一封邮件服务配置测试邮件。{/block} +{block name='email_title'}Email delivery test{/block} +{block name='preheader'}This is a test of the email delivery configuration.{/block} {block name='content'}

DELIVERY TEST

-

邮件服务连接正常

-

如果您收到这封邮件,说明 {$config["appName"]|escape:"html"} 的邮件发送配置工作正常。

-
+

Email delivery is working

+

If you received this message, the email delivery configuration for {$config["appName"]|escape:"html"} is working correctly.

+
{/block} diff --git a/web/resources/email/ticket/created.tpl b/web/resources/email/ticket/created.tpl index b09c5a9c..c3f209ef 100644 --- a/web/resources/email/ticket/created.tpl +++ b/web/resources/email/ticket/created.tpl @@ -1,10 +1,10 @@ {extends file='layout.tpl'} -{block name='email_title'}工单已创建 · {$config["appName"]|escape:"html"}{/block} -{block name='preheader'}你的工单已提交,管理员会尽快处理。{/block} +{block name='email_title'}Ticket created{/block} +{block name='preheader'}Your ticket has been submitted and will be reviewed as soon as possible.{/block} {block name='content'}

TICKET CREATED

-

工单已提交

-

您好,{$user->user_name|default:'用户'|escape:"html"},你的工单已经创建成功。管理员回复后,我们会再次通过邮件提醒你。

-
- +

Ticket submitted

+

Hello {$user->user_name|default:'User'|escape:"html"}, your ticket has been created successfully. We will notify you by email when an administrator replies.

+
+ {/block} diff --git a/web/resources/email/ticket/replied.tpl b/web/resources/email/ticket/replied.tpl index d3fd51ec..130e59e2 100644 --- a/web/resources/email/ticket/replied.tpl +++ b/web/resources/email/ticket/replied.tpl @@ -1,10 +1,10 @@ {extends file='layout.tpl'} -{block name='email_title'}工单收到回复 · {$config["appName"]|escape:"html"}{/block} -{block name='preheader'}管理员已回复你的工单。{/block} +{block name='email_title'}Ticket reply received{/block} +{block name='preheader'}An administrator has replied to your ticket.{/block} {block name='content'}

TICKET REPLY

-

工单收到回复

-

您好,{$user->user_name|default:'用户'|escape:"html"},管理员已经回复你的工单,请登录控制台查看完整内容。

-
- +

Ticket reply received

+

Hello {$user->user_name|default:'User'|escape:"html"}, an administrator has replied to your ticket. Sign in to the control panel to view the full response.

+
+ {/block} diff --git a/web/resources/user-copy/entries/auth.entries.php b/web/resources/user-copy/entries/auth.entries.php index 778865a0..15942a29 100644 --- a/web/resources/user-copy/entries/auth.entries.php +++ b/web/resources/user-copy/entries/auth.entries.php @@ -52,7 +52,6 @@ return [ $entry('auth.login.verify.email_limited', 'auth', 'auth.login', '此邮箱已请求太多次。', 'warning'), $entry('auth.login.verify.send_failed', 'auth', 'auth.login', '验证码发送失败,请稍后重试。', 'warning'), $entry('auth.login.verify.sent', 'auth', 'auth.login', '验证码发送成功,请检查邮箱。', 'status'), - $entry('auth.login.verify.subject', 'auth', 'auth.login', '{site} - 登录安全验证', 'label', ['site' => 'string']), $entry('auth.register.title', 'auth', 'auth.register', '注册', 'title'), $entry('auth.register.eyebrow', 'auth', 'auth.register', '创建账户'), $entry('auth.register.heading', 'auth', 'auth.register', '注册新账户', 'title'), @@ -78,7 +77,6 @@ return [ $entry('auth.register.error.email_registered', 'auth', 'auth.register', '该邮箱地址已被注册。', 'warning'), $entry('auth.register.verify.sent', 'auth', 'auth.register', '验证码发送成功,请检查邮箱;如果未收到,请检查垃圾箱。', 'status'), $entry('auth.register.verify.disabled', 'auth', 'auth.register', '邮箱验证码已关闭。', 'notice'), - $entry('auth.register.verify.subject', 'auth', 'auth.register', '{site} - 注册邮箱验证', 'label', ['site' => 'string']), $entry('auth.register.error.identity', 'auth', 'auth.register', '请填写有效的用户名和邮箱。', 'warning'), $entry('auth.register.error.email_not_allowed', 'auth', 'auth.register', '此邮箱暂不允许注册。', 'warning'), $entry('auth.register.error.email_code', 'auth', 'auth.register', '邮箱验证码错误或已过期。', 'warning'), diff --git a/web/tests/CloudMailOutboxDispatchTest.php b/web/tests/CloudMailOutboxDispatchTest.php index 119dfd39..bc40ab47 100644 --- a/web/tests/CloudMailOutboxDispatchTest.php +++ b/web/tests/CloudMailOutboxDispatchTest.php @@ -208,8 +208,8 @@ namespace { && (Mail::$messages[0]['emailType'] ?? null) === 'cloud_renewal_invoice' && (Mail::$messages[0]['data']['payment_deadline_at'] ?? null) === date('Y-m-d H:i:s', $now + 4 * 86400) - && str_contains((string) (Mail::$messages[0]['subject'] ?? ''), - '实例续费账单已生成'), + && (string) (Mail::$messages[0]['subject'] ?? '') + === 'Renewal Invoice Created', 'An open automatic renewal bill was not delivered and marked sent.'); $provisionedInstance = $newInstance(1, 'ready-vm', '8.8.8.11'); @@ -236,7 +236,8 @@ namespace { $provisionMessage = Mail::$messages[1] ?? []; $assert(($provisionMessage['template'] ?? null) === 'cloud/provision-success.tpl' && ($provisionMessage['emailType'] ?? null) === 'cloud_provision_success' - && str_contains((string) ($provisionMessage['subject'] ?? ''), '实例开通成功') + && (string) ($provisionMessage['subject'] ?? '') + === 'Instance Provisioned' && ($provisionMessage['data']['instance_name'] ?? null) === 'ready-vm' && ($provisionMessage['data']['public_ip'] ?? null) === '8.8.8.11' && !array_key_exists('root_password', $provisionMessage['data'] ?? []) diff --git a/web/tests/MailDeliveryLogTest.php b/web/tests/MailDeliveryLogTest.php index b437168e..69d26f17 100644 --- a/web/tests/MailDeliveryLogTest.php +++ b/web/tests/MailDeliveryLogTest.php @@ -19,6 +19,14 @@ namespace App\Models { } namespace App\Services { + class SiteName + { + public static function defaultName(): string + { + return 'Test site'; + } + } + class Config { public static array $values = [ @@ -146,6 +154,7 @@ namespace { $_SERVER['HTTP_HOST'] = 'site.example.test'; require dirname(__DIR__) . '/app/Services/Mail/Base.php'; + require dirname(__DIR__) . '/app/Services/MailSenderIdentity.php'; require dirname(__DIR__) . '/app/Services/Mail/Smtp.php'; require dirname(__DIR__) . '/app/Services/Mail/NullMail.php'; require dirname(__DIR__) . '/app/Services/Mail.php'; diff --git a/web/tests/MailNotificationContractTest.php b/web/tests/MailNotificationContractTest.php index f69222f0..7e9bc6f4 100644 --- a/web/tests/MailNotificationContractTest.php +++ b/web/tests/MailNotificationContractTest.php @@ -9,6 +9,7 @@ $assert = static function ($condition, string $message): void { $auth = file_get_contents($root . '/app/Controllers/AuthController.php'); $password = file_get_contents($root . '/app/Services/Password.php'); +$mailService = file_get_contents($root . '/app/Services/Mail.php'); $invoices = file_get_contents($root . '/app/Services/Cloud/CloudInvoiceService.php'); $worker = file_get_contents($root . '/app/Services/Cloud/CloudWorkerService.php'); $layout = file_get_contents($root . '/resources/email/layout.tpl'); @@ -41,6 +42,11 @@ $assert(str_contains($auth, '"scene" => "registration"') $assert(str_contains($password, '"expire" => date(') && str_contains($password, '$expiresAt = $now + 3600 * 24;'), 'Password reset email does not receive its real expiry timestamp.'); +$assert(str_contains( + $mailService, + "\$publicConfig['appName'] = MailSenderIdentity::displayName();" + ), + 'Email templates do not use the same default-title identity as the sender.'); foreach ($contentTemplates as $path => $template) { $assert(str_contains($template, "{extends file='layout.tpl'}"), @@ -48,6 +54,11 @@ foreach ($contentTemplates as $path => $template) { } $assert(count($contentTemplates) === 15, 'Expected every one of the 15 content email templates to be covered.'); +$assert(preg_match( + '/[\x{3400}-\x{9fff}]/u', + $layout . implode("\n", $contentTemplates) + ) !== 1, + 'A system email template still contains non-English static copy.'); foreach (['#edf3f8', '#102235', '#159da9', '#15243a', '#f5f8fb'] as $color) { $assert(str_contains(strtolower($layout), $color), 'Shared email layout is missing a user-panel theme color: ' . $color); @@ -64,7 +75,7 @@ $assert(str_contains($layout, '@media only screen and (max-width: 620px)') 'Shared email layout lost its mobile responsive rules.'); $assert(str_contains($layout, '© 2026 {$config["appName"]|escape:"html"}. All rights reserved.') - && strrpos($layout, '© 2026') > strrpos($layout, '云资源控制台'), + && strrpos($layout, '© 2026') > strrpos($layout, 'Cloud control panel'), 'Shared email footer is missing the final dynamic copyright line.'); $assert(preg_match('/border(?:-(?:top|right|bottom|left))?\s*:\s*[1-9]/i', $layout . implode("\n", $contentTemplates)) !== 1, @@ -103,8 +114,8 @@ $assert(str_contains($maintenance, '{foreach $instances as $instance}') && str_contains($maintenance, '{$instance.name|escape:"html"}') && str_contains($maintenance, '{$instance.ipv4|default:\'—\'|escape:"html"}') && str_contains($maintenance, '{$instance.ipv6|default:\'—\'|escape:"html"}') - && str_contains($maintenance, '开始时间(UTC)') - && str_contains($maintenance, '结束时间(UTC)'), + && str_contains($maintenance, 'Start time (UTC)') + && str_contains($maintenance, 'End time (UTC)'), 'Maintenance email lost its escaped instance list or UTC window.'); foreach (['reason_text', 'compensation_duration', 'incident_window_utc'] as $field) { @@ -113,7 +124,7 @@ foreach (['reason_text', 'compensation_duration', } $assert(str_contains( $compensation, - '{$scope_label|default:\'实例服务\'|escape:"html"}' + '{$scope_label|default:\'Instance service\'|escape:"html"}' ) && str_contains($compensation, '{foreach $instances as $instance}') && str_contains( @@ -128,7 +139,7 @@ $assert(str_contains( $compensation, '{$instance.new_expires_utc|escape:"html"}' ) - && str_contains($compensation, '时间统一使用 UTC'), + && str_contains($compensation, 'All times are shown in UTC'), 'Compensation email lost its escaped instance list or UTC contract.'); foreach (['root_password', 'private_key', 'sealed_credential', 'generated_password'] as $secret) { diff --git a/web/tests/MailSenderIdentityTest.php b/web/tests/MailSenderIdentityTest.php new file mode 100644 index 00000000..b5bbbb3f --- /dev/null +++ b/web/tests/MailSenderIdentityTest.php @@ -0,0 +1,61 @@ +') === '"Default \\"Cloud\\"" ', + 'The Mailgun sender header was not rebuilt from the default title and configured mailbox.' + ); + + $invalidWasRejected = false; + try { + MailSenderIdentity::mailbox("sender@example.com\r\nBcc: victim@example.com"); + } catch (\InvalidArgumentException $exception) { + $invalidWasRejected = true; + } + expectMailSenderIdentity($invalidWasRejected, 'A header-injection sender value was not rejected.'); + + $mailgunSource = file_get_contents(dirname(__DIR__) . '/app/Services/Mail/Mailgun.php'); + expectMailSenderIdentity( + is_string($mailgunSource) && str_contains($mailgunSource, 'MailSenderIdentity::header'), + 'Mailgun does not use the shared sender identity.' + ); + + echo 'Mail sender identity checks passed.' . PHP_EOL; +} diff --git a/web/tests/MailSubjectContractTest.php b/web/tests/MailSubjectContractTest.php new file mode 100644 index 00000000..152dab4f --- /dev/null +++ b/web/tests/MailSubjectContractTest.php @@ -0,0 +1,76 @@ + [ + "'Login Verification'", + "\$subject = 'Email Verification';", + ], + 'app/Services/AccountSecurityService.php' => [ + "'Password Change Verification'", + ], + 'app/Services/AccountEmailChangeService.php' => [ + "'Email Change Verification'", + ], + 'app/Services/Password.php' => [ + "\$subject = 'Password Reset';", + ], + 'app/Services/Cloud/CloudInvoiceService.php' => [ + "'Renewal Invoice Created'", + "'Instance Provisioned'", + ], + 'app/Services/Cloud/CloudServiceCompensationNotificationService.php' => [ + "'subject' => 'Service Time Compensation Applied'", + ], + 'app/Services/Ticket/TicketNotificationDispatcher.php' => [ + "'Ticket Created'", + "'New Ticket: ' . (string) \$root->title", + "'Ticket Reply Received'", + ], + 'app/Controllers/Admin/UserController.php' => [ + "'Account Created'", + "\$subject = trim((string) \$subjectFromFrontEnd);", + ], + 'app/Command/Job.php' => [ + "'Database Backup'", + ], +]; + +$sources = []; +foreach ($contracts as $relative => $needles) { + $source = file_get_contents($root . '/' . $relative); + $assert(is_string($source), 'Unable to read mail subject source: ' . $relative); + foreach ($needles as $needle) { + $assert( + str_contains($source, $needle), + 'A required event-only English subject contract is missing in ' + . $relative . ': ' . $needle + ); + } + $sources[] = $source; +} + +$combined = implode("\n", $sources); +$assert( + preg_match( + '/(?:Config::get\([\'\"]appName[\'\"]\)|\$appName)\s*\.\s*[\'\"][^\'\"]*[-–—]/', + $combined + ) !== 1, + 'A system email subject still prepends the site title.' +); + +$authEntries = file_get_contents( + $root . '/resources/user-copy/entries/auth.entries.php' +); +$assert(is_string($authEntries) + && !str_contains($authEntries, 'auth.login.verify.subject') + && !str_contains($authEntries, 'auth.register.verify.subject'), + 'Retired localized email-subject keys are still present in user copy.'); + +echo 'Event-only English mail subject contracts passed.' . PHP_EOL; diff --git a/web/tests/MailTemplateRenderTest.php b/web/tests/MailTemplateRenderTest.php index 1a7c6db1..b6fee703 100644 --- a/web/tests/MailTemplateRenderTest.php +++ b/web/tests/MailTemplateRenderTest.php @@ -153,23 +153,23 @@ try { '@media only screen and (max-width: 620px)'), 'A rendered email lost its shared theme, responsive CSS or footer.'); } - $assert(str_contains($registration, '验证您的注册邮箱') + $assert(str_contains($registration, 'Verify your email address') && str_contains($registration, '12<345') && str_contains($login, 'Confirm your sign-in') - && str_contains($emailChange, '确认修改邮箱') - && str_contains($emailChange, '验证此新邮箱后再将其设为登录邮箱') + && str_contains($emailChange, 'Confirm your email change') + && str_contains($emailChange, 'verify this new email address') && str_contains($emailChange, '246810'), 'Registration, login or email-change verification rendered the wrong scene.'); - $assert(str_contains($reset, '重置账户密码') + $assert(str_contains($reset, 'Reset your password') && str_contains($reset, '<unsafe>') && str_contains($reset, '&x=1'), 'Password-reset email did not render or escape its secure URL.'); - $assert(str_contains($renewal, '续费账单已生成') + $assert(str_contains($renewal, 'Renewal invoice created') && str_contains($renewal, '<script>') && str_contains($renewal, '#42') && str_contains($renewal, '2026-10-08 18:00:00'), 'Renewal invoice email did not render its safe public details.'); - $assert(str_contains($provisioned, '实例已开通') + $assert(str_contains($provisioned, 'Your instance is ready') && str_contains($provisioned, '<script>') && str_contains($provisioned, '203.0.113.43') && !str_contains($provisioned, 'not-for-email'), @@ -183,25 +183,26 @@ try { && str_contains($maintenance, '2001:db8::10') && str_contains($maintenance, '2026-11-06 03:00:00 UTC'), 'Maintenance email did not escape content or render its UTC scope.'); - $assert(str_contains($compensation, '实例可用时间补偿已到账') + $assert(str_contains($compensation, 'Service time compensation applied') && str_contains($compensation, '网络 <故障>') && !str_contains($compensation, '<故障>') && str_contains($compensation, 'HKG-A & IPv4 pool') && str_contains($compensation, 'vm-<one>') && str_contains($compensation, '2026-12-01 02:00:00 UTC'), 'Compensation email did not escape its frozen result.'); - $assert(str_contains($ticketCreated, '工单已提交') - && str_contains($ticketReplied, '工单收到回复') + $assert(str_contains($ticketCreated, 'Ticket submitted') + && str_contains($ticketReplied, 'Ticket reply received') && str_contains($ticketCreated, '网络 <异常> & 排查'), 'Ticket emails did not render their escaped shared content.'); $assert(str_contains($backup, '数据库备份已完成') + && str_contains($backup, 'Database backup completed') && str_contains($monitor, '<script>alert("notice")</script>') && !str_contains($monitor, '