mirror of
https://github.com/dreamhunter2333/cloudflare_temp_email.git
synced 2026-09-05 23:47:50 +08:00
fix: limit SEND_MAIL domain checks to binding paths (#987)
* fix: scope SEND_MAIL domain gating to binding * test: cover SEND_MAIL domain gating in e2e
This commit is contained in:
+17
-2
@@ -2,7 +2,7 @@ import { Context } from 'hono';
|
||||
import { Jwt } from 'hono/utils/jwt'
|
||||
import { WorkerMailerOptions } from 'worker-mailer';
|
||||
|
||||
import { getBooleanValue, getDomains, getStringValue, getIntValue, getUserRoles, getDefaultDomains, getJsonSetting, getAnotherWorkerList, hashPassword, getJsonObjectValue, getRandomSubdomainDomains } from './utils';
|
||||
import { getBooleanValue, getDomains, getStringArray, getStringValue, getIntValue, getUserRoles, getDefaultDomains, getJsonSetting, getAnotherWorkerList, hashPassword, getJsonObjectValue, getRandomSubdomainDomains } from './utils';
|
||||
import { unbindTelegramByAddress } from './telegram_api/common';
|
||||
import { CONSTANTS } from './constants';
|
||||
import { AddressCreationSettings, AdminWebhookSettings, WebhookMail, WebhookSettings } from './models';
|
||||
@@ -44,11 +44,26 @@ export const isSendMailEnabled = (
|
||||
if (smtpConfigMap && smtpConfigMap[mailDomain]) return true;
|
||||
|
||||
// Check SEND_MAIL binding
|
||||
if (c.env.SEND_MAIL) return true;
|
||||
if (isSendMailBindingEnabled(c, mailDomain)) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export const isSendMailBindingEnabled = (
|
||||
c: Context<HonoCustomType>,
|
||||
mailDomain: string
|
||||
): boolean => {
|
||||
if (!c.env.SEND_MAIL) {
|
||||
return false;
|
||||
}
|
||||
const sendMailDomains = getStringArray(c.env.SEND_MAIL_DOMAINS)
|
||||
.map((domain) => normalizeDomainValue(domain));
|
||||
if (sendMailDomains.length === 0) {
|
||||
return true;
|
||||
}
|
||||
return sendMailDomains.includes(normalizeDomainValue(mailDomain));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if send mail is enabled for any configured domain
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user