mirror of
https://github.com/dreamhunter2333/cloudflare_temp_email.git
synced 2026-09-05 15:38:34 +08:00
feat: hide send mail UI when not configured (#827)
- Add isSendMailEnabled and isAnySendMailEnabled functions in common.ts - Return enableSendMail field in /open_api/settings - Hide sendmail tab, sendbox tab, and reply button when send mail is not configured - Check RESEND_TOKEN, SMTP_CONFIG, and SEND_MAIL binding per domain Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.5
parent
e4b6c82e92
commit
0f418d7e94
@@ -34,6 +34,7 @@ export const useGlobalState = createGlobalState(
|
|||||||
cfTurnstileSiteKey: '',
|
cfTurnstileSiteKey: '',
|
||||||
enableWebhook: false,
|
enableWebhook: false,
|
||||||
isS3Enabled: false,
|
isS3Enabled: false,
|
||||||
|
enableSendMail: false,
|
||||||
showGithub: true,
|
showGithub: true,
|
||||||
disableAdminPasswordCheck: false,
|
disableAdminPasswordCheck: false,
|
||||||
enableAddressPassword: false,
|
enableAddressPassword: false,
|
||||||
|
|||||||
@@ -156,15 +156,15 @@ onMounted(() => {
|
|||||||
</n-button>
|
</n-button>
|
||||||
</n-input-group>
|
</n-input-group>
|
||||||
</div>
|
</div>
|
||||||
<MailBox :key="mailBoxKey" :showEMailTo="false" :showReply="true" :showSaveS3="openSettings.isS3Enabled"
|
<MailBox :key="mailBoxKey" :showEMailTo="false" :showReply="openSettings.enableSendMail" :showSaveS3="openSettings.isS3Enabled"
|
||||||
:saveToS3="saveToS3" :enableUserDeleteEmail="openSettings.enableUserDeleteEmail"
|
:saveToS3="saveToS3" :enableUserDeleteEmail="openSettings.enableUserDeleteEmail"
|
||||||
:fetchMailData="fetchMailData" :deleteMail="deleteMail" :showFilterInput="true" />
|
:fetchMailData="fetchMailData" :deleteMail="deleteMail" :showFilterInput="true" />
|
||||||
</n-tab-pane>
|
</n-tab-pane>
|
||||||
<n-tab-pane name="sendbox" :tab="t('sendbox')">
|
<n-tab-pane v-if="openSettings.enableSendMail" name="sendbox" :tab="t('sendbox')">
|
||||||
<SendBox :fetchMailData="fetchSenboxData" :enableUserDeleteEmail="openSettings.enableUserDeleteEmail"
|
<SendBox :fetchMailData="fetchSenboxData" :enableUserDeleteEmail="openSettings.enableUserDeleteEmail"
|
||||||
:deleteMail="deleteSenboxMail" />
|
:deleteMail="deleteSenboxMail" />
|
||||||
</n-tab-pane>
|
</n-tab-pane>
|
||||||
<n-tab-pane name="sendmail" :tab="t('sendmail')">
|
<n-tab-pane v-if="openSettings.enableSendMail" name="sendmail" :tab="t('sendmail')">
|
||||||
<SendMail />
|
<SendMail />
|
||||||
</n-tab-pane>
|
</n-tab-pane>
|
||||||
<n-tab-pane name="accountSettings" :tab="t('accountSettings')">
|
<n-tab-pane name="accountSettings" :tab="t('accountSettings')">
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { Hono } from 'hono'
|
|||||||
import utils from './utils';
|
import utils from './utils';
|
||||||
import { CONSTANTS } from './constants';
|
import { CONSTANTS } from './constants';
|
||||||
import { isS3Enabled } from './mails_api/s3_attachment';
|
import { isS3Enabled } from './mails_api/s3_attachment';
|
||||||
|
import { isAnySendMailEnabled } from './common';
|
||||||
|
|
||||||
const api = new Hono<HonoCustomType>
|
const api = new Hono<HonoCustomType>
|
||||||
|
|
||||||
@@ -38,6 +39,7 @@ api.get('/open_api/settings', async (c) => {
|
|||||||
"cfTurnstileSiteKey": c.env.CF_TURNSTILE_SITE_KEY,
|
"cfTurnstileSiteKey": c.env.CF_TURNSTILE_SITE_KEY,
|
||||||
"enableWebhook": utils.getBooleanValue(c.env.ENABLE_WEBHOOK),
|
"enableWebhook": utils.getBooleanValue(c.env.ENABLE_WEBHOOK),
|
||||||
"isS3Enabled": isS3Enabled(c),
|
"isS3Enabled": isS3Enabled(c),
|
||||||
|
"enableSendMail": isAnySendMailEnabled(c),
|
||||||
"version": CONSTANTS.VERSION,
|
"version": CONSTANTS.VERSION,
|
||||||
"showGithub": !utils.getBooleanValue(c.env.DISABLE_SHOW_GITHUB),
|
"showGithub": !utils.getBooleanValue(c.env.DISABLE_SHOW_GITHUB),
|
||||||
"disableAdminPasswordCheck": utils.getBooleanValue(c.env.DISABLE_ADMIN_PASSWORD_CHECK),
|
"disableAdminPasswordCheck": utils.getBooleanValue(c.env.DISABLE_ADMIN_PASSWORD_CHECK),
|
||||||
|
|||||||
+33
-1
@@ -1,7 +1,8 @@
|
|||||||
import { Context } from 'hono';
|
import { Context } from 'hono';
|
||||||
import { Jwt } from 'hono/utils/jwt'
|
import { Jwt } from 'hono/utils/jwt'
|
||||||
|
import { WorkerMailerOptions } from 'worker-mailer';
|
||||||
|
|
||||||
import { getBooleanValue, getDomains, getStringValue, getIntValue, getUserRoles, getDefaultDomains, getJsonSetting, getAnotherWorkerList, hashPassword } from './utils';
|
import { getBooleanValue, getDomains, getStringValue, getIntValue, getUserRoles, getDefaultDomains, getJsonSetting, getAnotherWorkerList, hashPassword, getJsonObjectValue } from './utils';
|
||||||
import { unbindTelegramByAddress } from './telegram_api/common';
|
import { unbindTelegramByAddress } from './telegram_api/common';
|
||||||
import { CONSTANTS } from './constants';
|
import { CONSTANTS } from './constants';
|
||||||
import { AdminWebhookSettings, WebhookMail, WebhookSettings } from './models';
|
import { AdminWebhookSettings, WebhookMail, WebhookSettings } from './models';
|
||||||
@@ -9,6 +10,37 @@ import i18n from './i18n';
|
|||||||
|
|
||||||
const DEFAULT_NAME_REGEX = /[^a-z0-9]/g;
|
const DEFAULT_NAME_REGEX = /[^a-z0-9]/g;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if send mail is enabled for a specific domain
|
||||||
|
*/
|
||||||
|
export const isSendMailEnabled = (
|
||||||
|
c: Context<HonoCustomType>,
|
||||||
|
mailDomain: string
|
||||||
|
): boolean => {
|
||||||
|
// Check resend token for domain or global
|
||||||
|
const resendEnabled = c.env.RESEND_TOKEN || c.env[
|
||||||
|
`RESEND_TOKEN_${mailDomain.replace(/\./g, "_").toUpperCase()}`
|
||||||
|
];
|
||||||
|
if (resendEnabled) return true;
|
||||||
|
|
||||||
|
// Check SMTP config for domain
|
||||||
|
const smtpConfigMap = getJsonObjectValue<Record<string, WorkerMailerOptions>>(c.env.SMTP_CONFIG);
|
||||||
|
if (smtpConfigMap && smtpConfigMap[mailDomain]) return true;
|
||||||
|
|
||||||
|
// Check SEND_MAIL binding
|
||||||
|
if (c.env.SEND_MAIL) return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if send mail is enabled for any configured domain
|
||||||
|
*/
|
||||||
|
export const isAnySendMailEnabled = (c: Context<HonoCustomType>): boolean => {
|
||||||
|
const domains = getDomains(c);
|
||||||
|
return domains.some(domain => isSendMailEnabled(c, domain));
|
||||||
|
}
|
||||||
|
|
||||||
export const generateRandomName = (c: Context<HonoCustomType>): string => {
|
export const generateRandomName = (c: Context<HonoCustomType>): string => {
|
||||||
// name min length min 1
|
// name min length min 1
|
||||||
const minLength = Math.max(
|
const minLength = Math.max(
|
||||||
|
|||||||
Reference in New Issue
Block a user