feat: support icloud forward mailbox provider config

This commit is contained in:
que01
2026-04-26 10:24:53 +08:00
parent 89644a0b30
commit 46ceb482c4
5 changed files with 320 additions and 7 deletions
+53
View File
@@ -279,6 +279,8 @@ const PERSISTED_SETTING_DEFAULTS = {
customEmailPool: [],
autoDeleteUsedIcloudAlias: false,
icloudHostPreference: 'auto',
icloudTargetMailboxType: 'icloud-inbox',
icloudForwardMailProvider: 'qq',
icloudFetchMode: 'reuse_existing',
accountRunHistoryTextEnabled: true,
accountRunHistoryHelperBaseUrl: DEFAULT_ACCOUNT_RUN_HISTORY_HELPER_BASE_URL,
@@ -692,6 +694,19 @@ function normalizeIcloudFetchMode(value = '') {
return normalized === 'always_new' ? 'always_new' : 'reuse_existing';
}
function normalizeIcloudTargetMailboxType(value = '') {
return String(value || '').trim().toLowerCase() === 'forward-mailbox'
? 'forward-mailbox'
: 'icloud-inbox';
}
function normalizeIcloudForwardMailProvider(value = '') {
const normalized = String(value || '').trim().toLowerCase();
return ['qq', '163', '163-vip', '126', 'gmail'].includes(normalized)
? normalized
: 'qq';
}
function normalizeCustomEmailPool(value = []) {
const source = Array.isArray(value)
? value
@@ -1002,6 +1017,10 @@ function normalizePersistentSettingValue(key, value) {
return Boolean(value);
case 'icloudHostPreference':
return normalizeIcloudHost(value) || 'auto';
case 'icloudTargetMailboxType':
return normalizeIcloudTargetMailboxType(value);
case 'icloudForwardMailProvider':
return normalizeIcloudForwardMailProvider(value);
case 'icloudFetchMode':
return normalizeIcloudFetchMode(value);
case 'accountRunHistoryHelperBaseUrl':
@@ -6875,6 +6894,29 @@ async function executeStep3(state) {
// Step 4: Get Signup Verification Code (qq-mail.js polls, then fills in signup-page.js)
// ============================================================
function getIcloudForwardMailConfig(state = {}, provider = 'qq') {
const normalizedProvider = normalizeIcloudForwardMailProvider(provider);
if (normalizedProvider === GMAIL_PROVIDER) {
return {
source: 'gmail-mail',
url: 'https://mail.google.com/mail/u/0/#inbox',
label: 'Gmail 邮箱',
inject: ['content/activation-utils.js', 'content/utils.js', 'content/gmail-mail.js'],
injectSource: 'gmail-mail',
};
}
if (normalizedProvider === '163') {
return { source: 'mail-163', url: 'https://mail.163.com/js6/main.jsp?df=mail163_letter#module=mbox.ListModule%7C%7B%22fid%22%3A1%2C%22order%22%3A%22date%22%2C%22desc%22%3Atrue%7D', label: '163 邮箱' };
}
if (normalizedProvider === '163-vip') {
return { source: 'mail-163', url: 'https://webmail.vip.163.com/js6/main.jsp?df=mail163_letter#module=mbox.ListModule%7C%7B%22fid%22%3A1%2C%22order%22%3A%22date%22%2C%22desc%22%3Atrue%7D', label: '163 VIP 邮箱' };
}
if (normalizedProvider === '126') {
return { source: 'mail-163', url: 'https://mail.126.com/js6/main.jsp?df=mail163_letter#module=mbox.ListModule%7C%7B%22fid%22%3A1%2C%22order%22%3A%22date%22%2C%22desc%22%3Atrue%7D', label: '126 邮箱' };
}
return { source: 'qq-mail', url: 'https://wx.mail.qq.com/', label: 'QQ 邮箱' };
}
function getMailConfig(state) {
const provider = state.mailProvider || 'qq';
if (provider === 'custom') {
@@ -6887,6 +6929,17 @@ function getMailConfig(state) {
const configuredHost = getConfiguredIcloudHostPreference(state)
|| normalizeIcloudHost(state?.preferredIcloudHost)
|| 'icloud.com';
const targetMailboxType = normalizeIcloudTargetMailboxType(state?.icloudTargetMailboxType);
const useForwardMailbox = targetMailboxType === 'forward-mailbox';
if (useForwardMailbox) {
const forwardProvider = normalizeIcloudForwardMailProvider(state?.icloudForwardMailProvider);
const forwardConfig = getIcloudForwardMailConfig(state, forwardProvider);
return {
...forwardConfig,
label: `iCloud 转发(${forwardConfig.label}`,
icloudForwarding: true,
};
}
const loginUrl = getIcloudLoginUrlForHost(configuredHost) || 'https://www.icloud.com/';
const mailUrl = getIcloudMailUrlForHost(configuredHost) || loginUrl;
return {
+17
View File
@@ -663,6 +663,23 @@
<option value="icloud.com.cn">iCloud.com.cn</option>
</select>
</div>
<div class="data-row" id="row-icloud-target-mailbox-type">
<span class="data-label">目标邮箱类型</span>
<select id="select-icloud-target-mailbox-type" class="data-select">
<option value="icloud-inbox">iCloud 收件箱</option>
<option value="forward-mailbox">转发到其他邮箱</option>
</select>
</div>
<div class="data-row" id="row-icloud-forward-mail-provider" style="display:none;">
<span class="data-label">转发邮箱</span>
<select id="select-icloud-forward-mail-provider" class="data-select">
<option value="qq">QQ 邮箱</option>
<option value="163">163 邮箱</option>
<option value="163-vip">163 VIP 邮箱</option>
<option value="126">126 邮箱</option>
<option value="gmail">Gmail 邮箱</option>
</select>
</div>
<div class="data-row">
<span class="data-label">获取策略</span>
<select id="select-icloud-fetch-mode" class="data-select">
+120
View File
@@ -140,6 +140,10 @@ const btnIcloudLoginDone = document.getElementById('btn-icloud-login-done');
const btnIcloudRefresh = document.getElementById('btn-icloud-refresh');
const btnIcloudDeleteUsed = document.getElementById('btn-icloud-delete-used');
const selectIcloudHostPreference = document.getElementById('select-icloud-host-preference');
const rowIcloudTargetMailboxType = document.getElementById('row-icloud-target-mailbox-type');
const selectIcloudTargetMailboxType = document.getElementById('select-icloud-target-mailbox-type');
const rowIcloudForwardMailProvider = document.getElementById('row-icloud-forward-mail-provider');
const selectIcloudForwardMailProvider = document.getElementById('select-icloud-forward-mail-provider');
const selectIcloudFetchMode = document.getElementById('select-icloud-fetch-mode');
const checkboxAutoDeleteIcloud = document.getElementById('checkbox-auto-delete-icloud');
const inputIcloudSearch = document.getElementById('input-icloud-search');
@@ -578,6 +582,17 @@ const normalizeIcloudFetchMode = (value) => {
const normalized = String(value || '').trim().toLowerCase();
return normalized === 'always_new' ? 'always_new' : 'reuse_existing';
};
const normalizeIcloudTargetMailboxType = (value) => {
return String(value || '').trim().toLowerCase() === 'forward-mailbox'
? 'forward-mailbox'
: 'icloud-inbox';
};
const normalizeIcloudForwardMailProvider = (value) => {
const normalized = String(value || '').trim().toLowerCase();
return ['qq', '163', '163-vip', '126', 'gmail'].includes(normalized)
? normalized
: 'qq';
};
const getIcloudLoginUrlForHost = window.IcloudUtils?.getIcloudLoginUrlForHost
|| ((host) => host === 'icloud.com.cn' ? 'https://www.icloud.com.cn/' : (host === 'icloud.com' ? 'https://www.icloud.com/' : ''));
@@ -1666,6 +1681,22 @@ function collectSettingsPayload() {
const icloudFetchModeRawValue = typeof selectIcloudFetchMode !== 'undefined'
? String(selectIcloudFetchMode?.value || '')
: '';
const icloudTargetMailboxTypeValue = typeof selectIcloudTargetMailboxType !== 'undefined'
? selectIcloudTargetMailboxType?.value
: '';
const icloudForwardMailProviderValue = typeof selectIcloudForwardMailProvider !== 'undefined'
? selectIcloudForwardMailProvider?.value
: '';
const normalizedIcloudTargetMailboxType = typeof normalizeIcloudTargetMailboxType === 'function'
? normalizeIcloudTargetMailboxType(icloudTargetMailboxTypeValue)
: (String(icloudTargetMailboxTypeValue || '').trim().toLowerCase() === 'forward-mailbox'
? 'forward-mailbox'
: 'icloud-inbox');
const normalizedIcloudForwardMailProvider = typeof normalizeIcloudForwardMailProvider === 'function'
? normalizeIcloudForwardMailProvider(icloudForwardMailProviderValue)
: (['qq', '163', '163-vip', '126', 'gmail'].includes(String(icloudForwardMailProviderValue || '').trim().toLowerCase())
? String(icloudForwardMailProviderValue || '').trim().toLowerCase()
: 'qq');
const mail2925UseAccountPool = typeof inputMail2925UseAccountPool !== 'undefined'
? Boolean(inputMail2925UseAccountPool?.checked)
: Boolean(latestState?.mail2925UseAccountPool);
@@ -1706,6 +1737,8 @@ function collectSettingsPayload() {
: [],
autoDeleteUsedIcloudAlias: checkboxAutoDeleteIcloud?.checked,
icloudHostPreference: selectIcloudHostPreference?.value || 'auto',
icloudTargetMailboxType: normalizedIcloudTargetMailboxType,
icloudForwardMailProvider: normalizedIcloudForwardMailProvider,
icloudFetchMode: (icloudFetchModeRawValue.trim().toLowerCase() === 'always_new'
? 'always_new'
: 'reuse_existing'),
@@ -2205,6 +2238,12 @@ function applySettingsState(state) {
if (selectIcloudFetchMode) {
selectIcloudFetchMode.value = normalizeIcloudFetchMode(state?.icloudFetchMode);
}
if (selectIcloudTargetMailboxType) {
selectIcloudTargetMailboxType.value = normalizeIcloudTargetMailboxType(state?.icloudTargetMailboxType);
}
if (selectIcloudForwardMailProvider) {
selectIcloudForwardMailProvider.value = normalizeIcloudForwardMailProvider(state?.icloudForwardMailProvider);
}
if (checkboxAutoDeleteIcloud) {
checkboxAutoDeleteIcloud.checked = Boolean(state?.autoDeleteUsedIcloudAlias);
}
@@ -3109,6 +3148,21 @@ function updateMailLoginButtonState() {
}
function updateMailProviderUI() {
const normalizeIcloudHostValue = typeof normalizeIcloudHost === 'function'
? normalizeIcloudHost
: ((value) => {
const normalized = String(value || '').trim().toLowerCase();
return normalized === 'icloud.com' || normalized === 'icloud.com.cn' ? normalized : '';
});
const icloudTargetMailboxTypeValue = typeof selectIcloudTargetMailboxType !== 'undefined'
? selectIcloudTargetMailboxType?.value
: latestState?.icloudTargetMailboxType;
const icloudForwardMailProviderValue = typeof selectIcloudForwardMailProvider !== 'undefined'
? selectIcloudForwardMailProvider?.value
: latestState?.icloudForwardMailProvider;
const icloudHostPreferenceValue = typeof selectIcloudHostPreference !== 'undefined'
? selectIcloudHostPreference?.value
: latestState?.icloudHostPreference;
const use2925 = selectMailProvider.value === '2925';
const useGmail = selectMailProvider.value === GMAIL_PROVIDER;
const useMail2925 = selectMailProvider.value === '2925';
@@ -3170,6 +3224,19 @@ function updateMailProviderUI() {
const showCloudflareDomain = useEmailGenerator && useCloudflare;
const showCloudflareTempEmailSettings = useCloudflareTempEmailProvider || (useEmailGenerator && useCloudflareTempEmailGenerator);
const showCloudflareTempEmailReceiveMailbox = useCloudflareTempEmailProvider && !useCloudflareTempEmailGenerator;
const selectedIcloudHost = typeof getSelectedIcloudHostPreference === 'function'
? getSelectedIcloudHostPreference()
: (normalizeIcloudHostValue(icloudHostPreferenceValue || latestState?.icloudHostPreference || '')
|| normalizeIcloudHostValue(latestState?.preferredIcloudHost)
|| 'icloud.com');
const icloudTargetMailboxType = typeof normalizeIcloudTargetMailboxType === 'function'
? normalizeIcloudTargetMailboxType(icloudTargetMailboxTypeValue)
: (String(icloudTargetMailboxTypeValue || '').trim().toLowerCase() === 'forward-mailbox'
? 'forward-mailbox'
: 'icloud-inbox');
const isIcloudComCnHost = selectedIcloudHost === 'icloud.com.cn';
const showIcloudTargetMailboxType = useIcloudProvider;
const showIcloudForwardMailProvider = useIcloudProvider && icloudTargetMailboxType === 'forward-mailbox';
const showCloudflareTempEmailRandomSubdomainToggle = useEmailGenerator && useCloudflareTempEmailGenerator;
const showCloudflareTempEmailDomain = useEmailGenerator && useCloudflareTempEmailGenerator;
if (rowEmailGenerator) {
@@ -3191,6 +3258,12 @@ function updateMailProviderUI() {
hideIcloudLoginHelp();
}
}
if (typeof rowIcloudTargetMailboxType !== 'undefined' && rowIcloudTargetMailboxType) {
rowIcloudTargetMailboxType.style.display = showIcloudTargetMailboxType ? '' : 'none';
}
if (typeof rowIcloudForwardMailProvider !== 'undefined' && rowIcloudForwardMailProvider) {
rowIcloudForwardMailProvider.style.display = showIcloudForwardMailProvider ? '' : 'none';
}
rowCfDomain.style.display = showCloudflareDomain ? '' : 'none';
const { domains } = getCloudflareDomainsFromState();
if (showCloudflareDomain) {
@@ -3306,6 +3379,15 @@ function updateMailProviderUI() {
if (autoHintText && showCloudflareTempEmailRandomSubdomainToggle && inputTempEmailUseRandomSubdomain?.checked) {
autoHintText.textContent = '已启用随机子域名:扩展会按当前选中的 Temp 域名提交,并额外携带 enableRandomSubdomain;是否生效取决于后端 RANDOM_SUBDOMAIN_DOMAINS 配置。';
}
if (autoHintText && useIcloudProvider && showIcloudForwardMailProvider) {
const forwardProvider = typeof normalizeIcloudForwardMailProvider === 'function'
? normalizeIcloudForwardMailProvider(icloudForwardMailProviderValue)
: (['qq', '163', '163-vip', '126', 'gmail'].includes(String(icloudForwardMailProviderValue || '').trim().toLowerCase())
? String(icloudForwardMailProviderValue || '').trim().toLowerCase()
: 'qq');
const forwardProviderLabel = MAIL_PROVIDER_LOGIN_CONFIGS[forwardProvider]?.label || '目标邮箱';
autoHintText.textContent = `iCloud ${isIcloudComCnHost ? 'com.cn' : ''} 当前使用转发收码:第 4/8 步会从 ${forwardProviderLabel} 轮询验证码。`;
}
if (useHotmail) {
inputEmail.value = getCurrentHotmailEmail();
} else if (useLuckmail) {
@@ -3451,6 +3533,9 @@ function updateButtonStates() {
const anyRunning = Object.values(statuses).some(s => s === 'running');
const autoLocked = isAutoRunLockedPhase();
const autoScheduled = isAutoRunScheduledPhase();
const icloudTargetMailboxTypeValue = typeof selectIcloudTargetMailboxType !== 'undefined'
? selectIcloudTargetMailboxType?.value
: latestState?.icloudTargetMailboxType;
for (const step of STEP_IDS) {
const btn = document.querySelector(`.step-btn[data-step="${step}"]`);
@@ -3500,6 +3585,19 @@ function updateButtonStates() {
if (btnIcloudRefresh) btnIcloudRefresh.disabled = disableIcloudControls;
if (btnIcloudDeleteUsed) btnIcloudDeleteUsed.disabled = disableIcloudControls || !hasDeletableUsedIcloudAliases();
if (selectIcloudHostPreference) selectIcloudHostPreference.disabled = disableIcloudControls;
if (typeof selectIcloudTargetMailboxType !== 'undefined' && selectIcloudTargetMailboxType) {
selectIcloudTargetMailboxType.disabled = disableIcloudControls;
}
if (typeof selectIcloudForwardMailProvider !== 'undefined' && selectIcloudForwardMailProvider) {
const normalizedIcloudTargetMailboxType = typeof normalizeIcloudTargetMailboxType === 'function'
? normalizeIcloudTargetMailboxType(icloudTargetMailboxTypeValue)
: (String(icloudTargetMailboxTypeValue || '').trim().toLowerCase() === 'forward-mailbox'
? 'forward-mailbox'
: 'icloud-inbox');
const allowIcloudForwardMailProvider = isIcloudMailProvider()
&& normalizedIcloudTargetMailboxType === 'forward-mailbox';
selectIcloudForwardMailProvider.disabled = disableIcloudControls || !allowIcloudForwardMailProvider;
}
if (selectIcloudFetchMode) {
const allowIcloudFetchMode = getSelectedEmailGenerator() === ICLOUD_PROVIDER
&& !isCustomMailProvider()
@@ -4718,6 +4816,7 @@ selectEmailGenerator.addEventListener('change', () => {
});
selectIcloudHostPreference?.addEventListener('change', () => {
updateMailProviderUI();
markSettingsDirty(true);
saveSettings({ silent: true }).catch(() => { });
if (getSelectedEmailGenerator() === 'icloud') {
@@ -4725,6 +4824,18 @@ selectIcloudHostPreference?.addEventListener('change', () => {
}
});
selectIcloudTargetMailboxType?.addEventListener('change', () => {
updateMailProviderUI();
markSettingsDirty(true);
saveSettings({ silent: true }).catch(() => { });
});
selectIcloudForwardMailProvider?.addEventListener('change', () => {
updateMailProviderUI();
markSettingsDirty(true);
saveSettings({ silent: true }).catch(() => { });
});
selectIcloudFetchMode?.addEventListener('change', () => {
markSettingsDirty(true);
saveSettings({ silent: true }).catch(() => { });
@@ -5309,6 +5420,15 @@ chrome.runtime.onMessage.addListener((message, _sender, sendResponse) => {
selectIcloudHostPreference.value = hostPreference === 'icloud.com'
? 'icloud.com'
: (hostPreference === 'icloud.com.cn' ? 'icloud.com.cn' : 'auto');
updateMailProviderUI();
}
if (message.payload.icloudTargetMailboxType !== undefined && selectIcloudTargetMailboxType) {
selectIcloudTargetMailboxType.value = normalizeIcloudTargetMailboxType(message.payload.icloudTargetMailboxType);
updateMailProviderUI();
}
if (message.payload.icloudForwardMailProvider !== undefined && selectIcloudForwardMailProvider) {
selectIcloudForwardMailProvider.value = normalizeIcloudForwardMailProvider(message.payload.icloudForwardMailProvider);
updateMailProviderUI();
}
if (message.payload.icloudFetchMode !== undefined && selectIcloudFetchMode) {
selectIcloudFetchMode.value = normalizeIcloudFetchMode(message.payload.icloudFetchMode);
+124 -7
View File
@@ -69,7 +69,7 @@ return { normalizeMailProvider };
});
test('getMailConfig returns icloud mail tab config with host preference', () => {
const bundle = extractFunction('getMailConfig');
const bundle = `${extractFunction('getIcloudForwardMailConfig')}\n${extractFunction('getMailConfig')}`;
const api = new Function(`
const ICLOUD_PROVIDER = 'icloud';
const GMAIL_PROVIDER = 'gmail';
@@ -91,23 +91,30 @@ function getIcloudLoginUrlForHost(host) {
function getIcloudMailUrlForHost(host) {
return host === 'icloud.com.cn' ? 'https://www.icloud.com.cn/mail/' : 'https://www.icloud.com/mail/';
}
function normalizeIcloudTargetMailboxType(value = '') {
return String(value || '').trim().toLowerCase() === 'forward-mailbox' ? 'forward-mailbox' : 'icloud-inbox';
}
function normalizeIcloudForwardMailProvider(value = '') {
const normalized = String(value || '').trim().toLowerCase();
return ['qq', '163', '163-vip', '126', 'gmail'].includes(normalized) ? normalized : 'qq';
}
${bundle}
return { getMailConfig };
`)();
assert.deepEqual(api.getMailConfig({
mailProvider: 'icloud',
icloudHostPreference: 'icloud.com.cn',
icloudHostPreference: 'icloud.com',
}), {
source: 'icloud-mail',
url: 'https://www.icloud.com.cn/mail/',
url: 'https://www.icloud.com/mail/',
label: 'iCloud 邮箱',
navigateOnReuse: true,
});
});
test('getMailConfig reuses preferred icloud host when preference is auto', () => {
const bundle = extractFunction('getMailConfig');
const bundle = `${extractFunction('getIcloudForwardMailConfig')}\n${extractFunction('getMailConfig')}`;
const api = new Function(`
const ICLOUD_PROVIDER = 'icloud';
const GMAIL_PROVIDER = 'gmail';
@@ -128,6 +135,13 @@ function getIcloudLoginUrlForHost(host) {
function getIcloudMailUrlForHost(host) {
return host === 'icloud.com.cn' ? 'https://www.icloud.com.cn/mail/' : 'https://www.icloud.com/mail/';
}
function normalizeIcloudTargetMailboxType(value = '') {
return String(value || '').trim().toLowerCase() === 'forward-mailbox' ? 'forward-mailbox' : 'icloud-inbox';
}
function normalizeIcloudForwardMailProvider(value = '') {
const normalized = String(value || '').trim().toLowerCase();
return ['qq', '163', '163-vip', '126', 'gmail'].includes(normalized) ? normalized : 'qq';
}
${bundle}
return { getMailConfig };
`)();
@@ -135,17 +149,17 @@ return { getMailConfig };
assert.deepEqual(api.getMailConfig({
mailProvider: 'icloud',
icloudHostPreference: 'auto',
preferredIcloudHost: 'icloud.com.cn',
preferredIcloudHost: 'icloud.com',
}), {
source: 'icloud-mail',
url: 'https://www.icloud.com.cn/mail/',
url: 'https://www.icloud.com/mail/',
label: 'iCloud 邮箱',
navigateOnReuse: true,
});
});
test('getMailConfig keeps provider metadata for 2925 mailboxes', () => {
const bundle = extractFunction('getMailConfig');
const bundle = `${extractFunction('getIcloudForwardMailConfig')}\n${extractFunction('getMailConfig')}`;
const api = new Function(`
const ICLOUD_PROVIDER = 'icloud';
const GMAIL_PROVIDER = 'gmail';
@@ -157,6 +171,13 @@ function normalizeInbucketOrigin(value) { return String(value || '').trim(); }
function getConfiguredIcloudHostPreference() { return ''; }
function getIcloudLoginUrlForHost(host) { return host; }
function getIcloudMailUrlForHost(host) { return host; }
function normalizeIcloudTargetMailboxType(value = '') {
return String(value || '').trim().toLowerCase() === 'forward-mailbox' ? 'forward-mailbox' : 'icloud-inbox';
}
function normalizeIcloudForwardMailProvider(value = '') {
const normalized = String(value || '').trim().toLowerCase();
return ['qq', '163', '163-vip', '126', 'gmail'].includes(normalized) ? normalized : 'qq';
}
${bundle}
return { getMailConfig };
`)();
@@ -172,3 +193,99 @@ return { getMailConfig };
injectSource: 'mail-2925',
});
});
test('getMailConfig uses icloud inbox config when host is com.cn and target mailbox is icloud inbox', () => {
const bundle = `${extractFunction('getIcloudForwardMailConfig')}\n${extractFunction('getMailConfig')}`;
const api = new Function(`
const ICLOUD_PROVIDER = 'icloud';
const GMAIL_PROVIDER = 'gmail';
const HOTMAIL_PROVIDER = 'hotmail-api';
const LUCKMAIL_PROVIDER = 'luckmail-api';
const CLOUDFLARE_TEMP_EMAIL_PROVIDER = 'cloudflare-temp-email';
function normalizeIcloudHost(value = '') {
const normalized = String(value || '').trim().toLowerCase();
return normalized === 'icloud.com' || normalized === 'icloud.com.cn' ? normalized : '';
}
function normalizeInbucketOrigin(value) { return String(value || '').trim(); }
function getConfiguredIcloudHostPreference(state) {
const normalized = String(state?.icloudHostPreference || '').trim().toLowerCase();
return normalized === 'icloud.com' || normalized === 'icloud.com.cn' ? normalized : '';
}
function getIcloudLoginUrlForHost(host) {
return host === 'icloud.com.cn' ? 'https://www.icloud.com.cn/' : 'https://www.icloud.com/';
}
function getIcloudMailUrlForHost(host) {
return host === 'icloud.com.cn' ? 'https://www.icloud.com.cn/mail/' : 'https://www.icloud.com/mail/';
}
function normalizeIcloudTargetMailboxType(value = '') {
return String(value || '').trim().toLowerCase() === 'forward-mailbox' ? 'forward-mailbox' : 'icloud-inbox';
}
function normalizeIcloudForwardMailProvider(value = '') {
const normalized = String(value || '').trim().toLowerCase();
return ['qq', '163', '163-vip', '126', 'gmail'].includes(normalized) ? normalized : 'qq';
}
${bundle}
return { getMailConfig };
`)();
assert.deepEqual(api.getMailConfig({
mailProvider: 'icloud',
icloudHostPreference: 'icloud.com.cn',
icloudTargetMailboxType: 'icloud-inbox',
icloudForwardMailProvider: 'gmail',
}), {
source: 'icloud-mail',
url: 'https://www.icloud.com.cn/mail/',
label: 'iCloud 邮箱',
navigateOnReuse: true,
});
});
test('getMailConfig uses forward mailbox config when target mailbox type is forward', () => {
const bundle = `${extractFunction('getIcloudForwardMailConfig')}\n${extractFunction('getMailConfig')}`;
const api = new Function(`
const ICLOUD_PROVIDER = 'icloud';
const GMAIL_PROVIDER = 'gmail';
const HOTMAIL_PROVIDER = 'hotmail-api';
const LUCKMAIL_PROVIDER = 'luckmail-api';
const CLOUDFLARE_TEMP_EMAIL_PROVIDER = 'cloudflare-temp-email';
function normalizeIcloudHost(value = '') {
const normalized = String(value || '').trim().toLowerCase();
return normalized === 'icloud.com' || normalized === 'icloud.com.cn' ? normalized : '';
}
function normalizeInbucketOrigin(value) { return String(value || '').trim(); }
function getConfiguredIcloudHostPreference(state) {
const normalized = String(state?.icloudHostPreference || '').trim().toLowerCase();
return normalized === 'icloud.com' || normalized === 'icloud.com.cn' ? normalized : '';
}
function getIcloudLoginUrlForHost(host) {
return host === 'icloud.com.cn' ? 'https://www.icloud.com.cn/' : 'https://www.icloud.com/';
}
function getIcloudMailUrlForHost(host) {
return host === 'icloud.com.cn' ? 'https://www.icloud.com.cn/mail/' : 'https://www.icloud.com/mail/';
}
function normalizeIcloudTargetMailboxType(value = '') {
return String(value || '').trim().toLowerCase() === 'forward-mailbox' ? 'forward-mailbox' : 'icloud-inbox';
}
function normalizeIcloudForwardMailProvider(value = '') {
const normalized = String(value || '').trim().toLowerCase();
return ['qq', '163', '163-vip', '126', 'gmail'].includes(normalized) ? normalized : 'qq';
}
${bundle}
return { getMailConfig };
`)();
assert.deepEqual(api.getMailConfig({
mailProvider: 'icloud',
icloudHostPreference: 'icloud.com.cn',
icloudTargetMailboxType: 'forward-mailbox',
icloudForwardMailProvider: 'gmail',
}), {
source: 'gmail-mail',
url: 'https://mail.google.com/mail/u/0/#inbox',
label: 'iCloud 转发(Gmail 邮箱)',
inject: ['content/activation-utils.js', 'content/utils.js', 'content/gmail-mail.js'],
injectSource: 'gmail-mail',
icloudForwarding: true,
});
});
+6
View File
@@ -55,6 +55,8 @@ const bundle = [
extractFunction('normalizeEmailGenerator'),
extractFunction('getEmailGeneratorLabel'),
extractFunction('normalizeVerificationResendCount'),
extractFunction('normalizeIcloudTargetMailboxType'),
extractFunction('normalizeIcloudForwardMailProvider'),
extractFunction('normalizePersistentSettingValue'),
extractFunction('finalizeIcloudAliasAfterSuccessfulFlow'),
].join('\n');
@@ -178,6 +180,10 @@ test('normalizePersistentSettingValue handles icloud settings', () => {
const api = createApi();
assert.equal(api.normalizePersistentSettingValue('icloudHostPreference', 'icloud.com'), 'icloud.com');
assert.equal(api.normalizePersistentSettingValue('icloudHostPreference', 'bad-host'), 'auto');
assert.equal(api.normalizePersistentSettingValue('icloudTargetMailboxType', 'forward-mailbox'), 'forward-mailbox');
assert.equal(api.normalizePersistentSettingValue('icloudTargetMailboxType', 'wrong'), 'icloud-inbox');
assert.equal(api.normalizePersistentSettingValue('icloudForwardMailProvider', 'GMAIL'), 'gmail');
assert.equal(api.normalizePersistentSettingValue('icloudForwardMailProvider', 'unknown'), 'qq');
assert.equal(api.normalizePersistentSettingValue('autoDeleteUsedIcloudAlias', 1), true);
assert.equal(api.normalizePersistentSettingValue('verificationResendCount', '6'), 6);
assert.equal(api.normalizePersistentSettingValue('verificationResendCount', 99), 20);