feat(email): 使用英文名时间生成默认邮箱前缀

This commit is contained in:
QLHazyCoder
2026-05-28 04:30:25 +08:00
parent 7790972af4
commit 001f133963
6 changed files with 262 additions and 7 deletions
+54
View File
@@ -1,6 +1,7 @@
const test = require('node:test');
const assert = require('node:assert/strict');
require('../background/email-local-part-helpers.js');
require('../background/cloudmail-provider.js');
function createProviderApi(options = {}) {
@@ -228,3 +229,56 @@ test('fetchCloudMailAddress preserves phone identity through the shared persiste
},
]);
});
test('fetchCloudMailAddress builds english name, date-time, and suffix local part by default', async () => {
const api = globalThis.MultiPageBackgroundCloudMailProvider.createCloudMailProvider({
addLog: async () => {},
buildCloudMailHeaders: () => ({}),
CLOUD_MAIL_DEFAULT_PAGE_SIZE: 20,
CLOUD_MAIL_GENERATOR: 'cloudmail',
CLOUD_MAIL_PROVIDER: 'cloudmail',
fetchImpl: async (url) => {
if (String(url).includes('/api/public/addUser')) {
return {
ok: true,
text: async () => JSON.stringify({ code: 200 }),
};
}
return {
ok: true,
text: async () => JSON.stringify({ code: 200, data: { token: 'token' } }),
};
},
getCloudMailTokenFromResponse: () => 'token',
getState: async () => ({}),
joinCloudMailUrl: (baseUrl, path) => `${baseUrl}${path}`,
normalizeCloudMailAddress: (value) => String(value || '').trim().toLowerCase(),
normalizeCloudMailBaseUrl: (value) => String(value || '').trim(),
normalizeCloudMailDomain: (value) => String(value || '').trim(),
normalizeCloudMailDomains: (values) => values || [],
normalizeCloudMailMailApiMessages: () => [],
persistRegistrationEmailState: async () => {},
pickVerificationMessageWithTimeFallback: () => ({
match: null,
usedRelaxedFilters: false,
usedTimeFallback: false,
}),
setEmailState: async () => {},
setPersistentSettings: async () => {},
sleepWithStop: async () => {},
throwIfStopped: () => {},
});
const state = {
cloudMailBaseUrl: 'https://mail.example.com',
cloudMailAdminEmail: 'admin@example.com',
cloudMailAdminPassword: 'secret',
cloudMailToken: 'token',
cloudMailDomain: 'example.com',
};
const email = await api.fetchCloudMailAddress(state, {
date: '2026-05-17T08:09:10.123',
});
assert.match(email, /^[a-z]+20260517080910123[a-z0-9]{4}@example\.com$/);
});