(state, client, purchase, options = {})
| 2312 | } |
| 2313 | |
| 2314 | async function activateLuckmailPurchaseForFlow(state, client, purchase, options = {}) { |
| 2315 | const normalizedPurchase = normalizeLuckmailPurchase(purchase); |
| 2316 | if (!normalizedPurchase?.email_address || !normalizedPurchase?.token) { |
| 2317 | throw new Error('LuckMail 邮箱缺少 email/token,无法用于当前流程。'); |
| 2318 | } |
| 2319 | |
| 2320 | let baselineCursor = null; |
| 2321 | if (options.initializeCursor !== false) { |
| 2322 | const mailList = await client.user.getTokenMails(normalizedPurchase.token); |
| 2323 | baselineCursor = buildLuckmailBaselineCursor(mailList?.mails || []); |
| 2324 | } |
| 2325 | |
| 2326 | await setLuckmailPurchaseState(normalizedPurchase); |
| 2327 | await setLuckmailMailCursorState(baselineCursor); |
| 2328 | await setEmailState(normalizedPurchase.email_address); |
| 2329 | |
| 2330 | if (options.logMessage) { |
| 2331 | await addLog(options.logMessage, options.logLevel || 'ok'); |
| 2332 | } |
| 2333 | |
| 2334 | return normalizedPurchase; |
| 2335 | } |
| 2336 | |
| 2337 | async function findReusableLuckmailPurchaseForFlow(state, client) { |
| 2338 | const preserveTagInfo = getLuckmailPreserveTagInfo(state); |
no test coverage detected