MCPcopy Index your code
hub / github.com/QLHazyCoder/FlowPilot / fetchIcloudHideMyEmail

Function fetchIcloudHideMyEmail

background.js:3093–3141  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3091}
3092
3093async function fetchIcloudHideMyEmail() {
3094 return withIcloudLoginHelp('获取 iCloud 隐私邮箱', async () => {
3095 throwIfStopped();
3096 await addLog('iCloud:正在校验当前浏览器登录状态...', 'info');
3097
3098 const { serviceUrl, setupUrl } = await resolveIcloudPremiumMailService();
3099 await addLog(`iCloud:已通过 ${new URL(setupUrl).host} 验证会话`, 'ok');
3100
3101 const existingAliasesResponse = await icloudRequest('GET', `${serviceUrl}/v2/hme/list`);
3102 const state = await getState();
3103 const existingAliases = normalizeIcloudAliasList(existingAliasesResponse, {
3104 usedEmails: getEffectiveUsedEmails(state),
3105 preservedEmails: getPreservedAliasMap(state),
3106 });
3107
3108 const reusableAlias = pickReusableIcloudAlias(existingAliases);
3109 if (reusableAlias) {
3110 await setEmailState(reusableAlias.email);
3111 await addLog(`iCloud:复用未使用别名 ${reusableAlias.email}`, 'ok');
3112 broadcastIcloudAliasesChanged({ reason: 'selected', email: reusableAlias.email });
3113 return reusableAlias.email;
3114 }
3115
3116 await addLog('iCloud:没有可复用别名,开始生成新的 Hide My Email 地址...', 'warn');
3117
3118 const generated = await icloudRequest('POST', `${serviceUrl}/v1/hme/generate`);
3119 if (!generated?.success || !generated?.result?.hme) {
3120 throw new Error(generated?.error?.errorMessage || 'iCloud 隐私邮箱生成失败。');
3121 }
3122
3123 const reserved = await icloudRequest('POST', `${serviceUrl}/v1/hme/reserve`, {
3124 data: {
3125 hme: generated.result.hme,
3126 label: getIcloudAliasLabel(),
3127 note: 'Generated through Multi-Page Automation',
3128 },
3129 });
3130
3131 if (!reserved?.success || !reserved?.result?.hme?.hme) {
3132 throw new Error(reserved?.error?.errorMessage || 'iCloud 隐私邮箱保留失败。');
3133 }
3134
3135 const alias = String(reserved.result.hme.hme || '').trim().toLowerCase();
3136 await setEmailState(alias);
3137 await addLog(`iCloud:已创建并保留新别名 ${alias}`, 'ok');
3138 broadcastIcloudAliasesChanged({ reason: 'created', email: alias });
3139 return alias;
3140 });
3141}
3142
3143async function finalizeIcloudAliasAfterSuccessfulFlow(state) {
3144 const email = String(state?.email || '').trim().toLowerCase();

Callers 1

fetchGeneratedEmailFunction · 0.85

Calls 13

withIcloudLoginHelpFunction · 0.85
icloudRequestFunction · 0.85
getStateFunction · 0.85
normalizeIcloudAliasListFunction · 0.85
getEffectiveUsedEmailsFunction · 0.85
getPreservedAliasMapFunction · 0.85
pickReusableIcloudAliasFunction · 0.85
setEmailStateFunction · 0.85
getIcloudAliasLabelFunction · 0.85
throwIfStoppedFunction · 0.70

Tested by

no test coverage detected