feat(mail): add Resend delivery, inbox replies and notification tiers
This commit is contained in:
1 parent
208536e1cb
commit
ad42a0e1e7
53 files changed
+2626
-43
No files matched your search
@@ -67,6 +67,29 @@ class ConfigSave extends FormRequest
|
||||
'email_encryption' => '',
|
||||
'email_from_address' => '',
|
||||
'remind_mail_enable' => '',
|
||||
'automatic_mail_level' => 'sometimes|integer|in:1,2,3',
|
||||
'mail_flow' => 'sometimes|array:enabled,resend_enabled,resend_key,resend_from,resend_webhook_secret,reply_to,daily_limit,monthly_limit,inbound_enabled,imap_host,imap_port,imap_username,imap_password,imap_folder,auto_reply_enabled,auto_reply_subject,auto_reply_text,report_enabled,master_url,master_bot_code,master_chat_code',
|
||||
'mail_flow.enabled' => 'sometimes|boolean',
|
||||
'mail_flow.resend_enabled' => 'sometimes|boolean',
|
||||
'mail_flow.resend_key' => 'nullable|string|max:256',
|
||||
'mail_flow.resend_from' => 'nullable|email|max:254',
|
||||
'mail_flow.resend_webhook_secret' => 'nullable|string|max:256',
|
||||
'mail_flow.reply_to' => 'nullable|email|max:254',
|
||||
'mail_flow.daily_limit' => 'sometimes|integer|min:1|max:100',
|
||||
'mail_flow.monthly_limit' => 'sometimes|integer|min:1|max:3000',
|
||||
'mail_flow.inbound_enabled' => 'sometimes|boolean',
|
||||
'mail_flow.imap_host' => 'nullable|string|regex:/^[a-zA-Z0-9.-]+$/|max:253',
|
||||
'mail_flow.imap_port' => 'sometimes|integer|min:1|max:65535',
|
||||
'mail_flow.imap_username' => 'nullable|string|max:254',
|
||||
'mail_flow.imap_password' => 'nullable|string|max:1024',
|
||||
'mail_flow.imap_folder' => 'sometimes|string|regex:/^[a-zA-Z0-9_ .\\/-]+$/|max:100',
|
||||
'mail_flow.auto_reply_enabled' => 'sometimes|boolean',
|
||||
'mail_flow.auto_reply_subject' => 'sometimes|string|max:200',
|
||||
'mail_flow.auto_reply_text' => 'sometimes|string|max:5000',
|
||||
'mail_flow.report_enabled' => 'sometimes|boolean',
|
||||
'mail_flow.master_url' => 'nullable|url:https|max:500',
|
||||
'mail_flow.master_bot_code' => 'nullable|string|max:100',
|
||||
'mail_flow.master_chat_code' => 'nullable|string|max:100',
|
||||
// telegram
|
||||
'telegram_bot_enable' => '',
|
||||
'telegram_bot_token' => '',
|
||||
@@ -123,6 +146,49 @@ class ConfigSave extends FormRequest
|
||||
return self::RULES;
|
||||
}
|
||||
|
||||
public function after(): array
|
||||
{
|
||||
return [function ($validator) {
|
||||
if ((int) $this->input('automatic_mail_level') === 2 && !\Illuminate\Support\Facades\Schema::hasTable('v2_mail_messages')) {
|
||||
$validator->errors()->add('automatic_mail_level', '二档到期通知需要先执行邮件记录数据库迁移。');
|
||||
}
|
||||
if (!$this->has('mail_flow')) { return; }
|
||||
$settings = array_replace(\App\Services\MailFlow\Settings::all(), (array) $this->input('mail_flow'));
|
||||
foreach (['resend_key', 'resend_webhook_secret', 'imap_password'] as $key) {
|
||||
if (empty($settings[$key])) { $settings[$key] = \App\Services\MailFlow\Settings::get($key); }
|
||||
}
|
||||
if (empty($settings['enabled'])) { return; }
|
||||
foreach (['v2_mail_messages', 'v2_mail_quota_buckets', 'v2_mail_daily_reports'] as $table) {
|
||||
if (!\Illuminate\Support\Facades\Schema::hasTable($table)) {
|
||||
$validator->errors()->add('mail_flow.enabled', '请先执行邮件功能数据库迁移。');
|
||||
break;
|
||||
}
|
||||
}
|
||||
$required = [];
|
||||
if (!empty($settings['resend_enabled'])) {
|
||||
$required = array_merge($required, ['resend_key', 'resend_from', 'resend_webhook_secret']);
|
||||
}
|
||||
if (!empty($settings['inbound_enabled'])) {
|
||||
$required = array_merge($required, ['imap_host', 'imap_username', 'imap_password']);
|
||||
if (!function_exists('imap_open')) {
|
||||
$validator->errors()->add('mail_flow.inbound_enabled', '请先安装 PHP IMAP 扩展。');
|
||||
}
|
||||
}
|
||||
if (!empty($settings['auto_reply_enabled'])) {
|
||||
$required[] = 'reply_to';
|
||||
if (empty($settings['inbound_enabled'])) {
|
||||
$validator->errors()->add('mail_flow.auto_reply_enabled', '请先启用常规邮箱收件。');
|
||||
}
|
||||
}
|
||||
if (!empty($settings['report_enabled'])) {
|
||||
$required = array_merge($required, ['master_url', 'master_bot_code', 'master_chat_code']);
|
||||
}
|
||||
foreach (array_unique($required) as $key) {
|
||||
if (empty($settings[$key])) { $validator->errors()->add('mail_flow.' . $key, '请补齐此项配置。'); }
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
// illiteracy prompt
|
||||
|
||||
Reference in new issue
Block a user