feat: support icloud forward mailbox provider config
This commit is contained in:
@@ -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,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user