feat(email): 使用英文名时间生成默认邮箱前缀
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
(function cloudMailProviderModule(root, factory) {
|
||||
root.MultiPageBackgroundCloudMailProvider = factory();
|
||||
})(typeof self !== 'undefined' ? self : globalThis, function createCloudMailProviderModule() {
|
||||
root.MultiPageBackgroundCloudMailProvider = factory(root);
|
||||
})(typeof self !== 'undefined' ? self : globalThis, function createCloudMailProviderModule(root = globalThis) {
|
||||
function createCloudMailProvider(deps = {}) {
|
||||
const {
|
||||
addLog = async () => {},
|
||||
@@ -18,6 +18,7 @@
|
||||
normalizeCloudMailDomains,
|
||||
normalizeCloudMailMailApiMessages,
|
||||
persistRegistrationEmailState = null,
|
||||
buildRandomNameDateTimeLocalPart = root.MultiPageEmailLocalPartHelpers?.buildRandomNameDateTimeLocalPart,
|
||||
pickVerificationMessageWithTimeFallback,
|
||||
setEmailState = async () => {},
|
||||
setPersistentSettings = async () => {},
|
||||
@@ -172,6 +173,12 @@
|
||||
return chars.join('');
|
||||
}
|
||||
|
||||
function buildCloudMailNameDateTimeLocalPart(date = new Date()) {
|
||||
return typeof buildRandomNameDateTimeLocalPart === 'function'
|
||||
? buildRandomNameDateTimeLocalPart(date)
|
||||
: '';
|
||||
}
|
||||
|
||||
async function fetchCloudMailAddress(state, options = {}) {
|
||||
throwIfStopped();
|
||||
const latestState = state || await getState();
|
||||
@@ -181,6 +188,7 @@
|
||||
requireDomain: true,
|
||||
});
|
||||
const requestedLocal = String(options.localPart || options.name || '').trim().toLowerCase()
|
||||
|| buildCloudMailNameDateTimeLocalPart(options.date)
|
||||
|| generateCloudMailAliasLocalPart();
|
||||
const address = `${requestedLocal}@${ensuredConfig.domain}`.toLowerCase();
|
||||
const payload = { list: [{ email: address }] };
|
||||
@@ -318,6 +326,7 @@
|
||||
}
|
||||
|
||||
return {
|
||||
buildCloudMailNameDateTimeLocalPart,
|
||||
ensureCloudMailConfig,
|
||||
ensureCloudMailToken,
|
||||
fetchCloudMailAddress,
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
(function attachEmailLocalPartHelpers(root, factory) {
|
||||
root.MultiPageEmailLocalPartHelpers = factory(root);
|
||||
})(typeof self !== 'undefined' ? self : globalThis, function createEmailLocalPartHelpersModule(root = globalThis) {
|
||||
const ENGLISH_NAME_PREFIXES = [
|
||||
'james', 'john', 'robert', 'michael', 'william', 'david', 'richard', 'joseph',
|
||||
'thomas', 'charles', 'mary', 'patricia', 'jennifer', 'linda', 'elizabeth',
|
||||
'barbara', 'susan', 'jessica', 'sarah', 'karen', 'daniel', 'matthew',
|
||||
'anthony', 'mark', 'donald', 'steven', 'paul', 'andrew', 'joshua', 'kevin',
|
||||
'brian', 'george', 'edward', 'ronald', 'timothy', 'jason', 'jeffrey', 'ryan',
|
||||
'jacob', 'gary', 'nicholas', 'eric', 'jonathan', 'stephen', 'larry', 'justin',
|
||||
'scott', 'brandon', 'benjamin', 'samuel', 'gregory', 'alexander', 'patrick',
|
||||
'frank', 'raymond', 'jack', 'dennis', 'jerry', 'tyler', 'aaron', 'henry',
|
||||
'douglas', 'peter', 'adam', 'zachary', 'nathan', 'walter', 'harold', 'kyle',
|
||||
'carl', 'arthur', 'gerald', 'roger', 'alice', 'emma', 'olivia', 'sophia',
|
||||
'isabella', 'mia', 'amelia', 'harper', 'evelyn', 'abigail', 'emily', 'ella',
|
||||
'scarlett', 'grace', 'chloe', 'victoria', 'riley', 'aria', 'lily', 'nora',
|
||||
];
|
||||
|
||||
const RANDOM_SUFFIX_CHARS = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
||||
|
||||
function getRandomInt(maxExclusive) {
|
||||
const max = Math.floor(Number(maxExclusive));
|
||||
if (!Number.isFinite(max) || max <= 0) return 0;
|
||||
const cryptoApi = root.crypto;
|
||||
if (cryptoApi && typeof cryptoApi.getRandomValues === 'function') {
|
||||
const buffer = new Uint32Array(1);
|
||||
cryptoApi.getRandomValues(buffer);
|
||||
return buffer[0] % max;
|
||||
}
|
||||
return Math.floor(Math.random() * max);
|
||||
}
|
||||
|
||||
function pickRandomEnglishNamePrefix() {
|
||||
return ENGLISH_NAME_PREFIXES[getRandomInt(ENGLISH_NAME_PREFIXES.length)] || 'james';
|
||||
}
|
||||
|
||||
function formatDateTimeDigits(date = new Date()) {
|
||||
const current = new Date(date);
|
||||
if (Number.isNaN(current.getTime())) {
|
||||
return '';
|
||||
}
|
||||
const year = String(current.getFullYear());
|
||||
const month = String(current.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(current.getDate()).padStart(2, '0');
|
||||
const hour = String(current.getHours()).padStart(2, '0');
|
||||
const minute = String(current.getMinutes()).padStart(2, '0');
|
||||
const second = String(current.getSeconds()).padStart(2, '0');
|
||||
const millisecond = String(current.getMilliseconds()).padStart(3, '0');
|
||||
return `${year}${month}${day}${hour}${minute}${second}${millisecond}`;
|
||||
}
|
||||
|
||||
function buildRandomAlphaNumericSuffix(length = 4) {
|
||||
const size = Math.max(0, Math.floor(Number(length) || 0));
|
||||
const chars = [];
|
||||
for (let index = 0; index < size; index += 1) {
|
||||
chars.push(RANDOM_SUFFIX_CHARS[getRandomInt(RANDOM_SUFFIX_CHARS.length)] || 'a');
|
||||
}
|
||||
return chars.join('');
|
||||
}
|
||||
|
||||
function buildRandomNameDateTimeLocalPart(date = new Date(), options = {}) {
|
||||
const dateTimeDigits = formatDateTimeDigits(date);
|
||||
if (!dateTimeDigits) {
|
||||
return '';
|
||||
}
|
||||
const suffixLength = Number.isFinite(Number(options.suffixLength))
|
||||
? Math.max(0, Math.floor(Number(options.suffixLength)))
|
||||
: 4;
|
||||
return `${pickRandomEnglishNamePrefix()}${dateTimeDigits}${buildRandomAlphaNumericSuffix(suffixLength)}`;
|
||||
}
|
||||
|
||||
return {
|
||||
buildRandomAlphaNumericSuffix,
|
||||
buildRandomNameDateTimeLocalPart,
|
||||
formatDateTimeDigits,
|
||||
pickRandomEnglishNamePrefix,
|
||||
};
|
||||
});
|
||||
@@ -1,6 +1,6 @@
|
||||
(function attachGeneratedEmailHelpers(root, factory) {
|
||||
root.MultiPageGeneratedEmailHelpers = factory();
|
||||
})(typeof self !== 'undefined' ? self : globalThis, function createGeneratedEmailHelpersModule() {
|
||||
root.MultiPageGeneratedEmailHelpers = factory(root);
|
||||
})(typeof self !== 'undefined' ? self : globalThis, function createGeneratedEmailHelpersModule(root = globalThis) {
|
||||
function createGeneratedEmailHelpers(deps = {}) {
|
||||
const {
|
||||
addLog,
|
||||
@@ -24,6 +24,7 @@
|
||||
normalizeEmailGenerator,
|
||||
isGeneratedAliasProvider,
|
||||
persistRegistrationEmailState = null,
|
||||
buildRandomNameDateTimeLocalPart = root.MultiPageEmailLocalPartHelpers?.buildRandomNameDateTimeLocalPart,
|
||||
reuseOrCreateTab,
|
||||
sendToContentScript,
|
||||
setEmailState,
|
||||
@@ -59,6 +60,12 @@
|
||||
return chars.join('');
|
||||
}
|
||||
|
||||
function buildDefaultGeneratedEmailLocalPart(date = new Date()) {
|
||||
return typeof buildRandomNameDateTimeLocalPart === 'function'
|
||||
? buildRandomNameDateTimeLocalPart(date)
|
||||
: '';
|
||||
}
|
||||
|
||||
async function fetchCloudflareEmail(state, options = {}) {
|
||||
throwIfStopped();
|
||||
const latestState = state || await getState();
|
||||
@@ -165,7 +172,9 @@
|
||||
requireAdminAuth: true,
|
||||
requireDomain: true,
|
||||
});
|
||||
const requestedName = String(options.localPart || options.name || '').trim().toLowerCase() || generateCloudflareAliasLocalPart();
|
||||
const requestedName = String(options.localPart || options.name || '').trim().toLowerCase()
|
||||
|| buildDefaultGeneratedEmailLocalPart(options.date)
|
||||
|| generateCloudflareAliasLocalPart();
|
||||
const effectiveDomain = config.effectiveDomain || (
|
||||
typeof buildCloudflareTempEmailEffectiveDomain === 'function'
|
||||
? buildCloudflareTempEmailEffectiveDomain(config)
|
||||
@@ -377,6 +386,8 @@
|
||||
fetchCloudflareTempEmailAddress,
|
||||
fetchDuckEmail,
|
||||
fetchGeneratedEmail,
|
||||
buildDefaultGeneratedEmailLocalPart,
|
||||
buildRandomNameDateTimeLocalPart,
|
||||
generateCloudflareAliasLocalPart,
|
||||
requestCloudflareTempEmailJson,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user